Loading Other/Metrics/LinesOfCode.csv +1 −1 Original line number Diff line number Diff line v1.3.1;3180 No newline at end of file v1.3.1;3156 No newline at end of file SimpleOCRCLI/SimpleOCRCLI/Runner/RunWithArgumentsFromCLI.cs +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ namespace SimpleOCR.CLI.Core.Runner protected override string RunImplementation() { SimpleOCR.Library.Core.IOCRService ocrService = new SimpleOCR.Library.Core.OCRService(this._Options.OCRDataFolder, GeneralLogger.CreateUsingConsole()); SimpleOCR.Library.Core.IOCRService ocrService = new SimpleOCR.Library.Core.OCRService(new SimpleOCR.Library.Core.OCRServiceConfiguration() { DataFolder = this._Options.OCRDataFolder }, GeneralLogger.CreateUsingConsole()); ocrService.Initialize(); (FileType fileType, byte[] content,string mimeType) = SimpleOCR.Library.Core.Misc.Utilities.LoadFile(_Options.File); content = fileType.Accept(new ToPictureVisitor(content,mimeType)); Loading SimpleOCRLibrary/SimpleOCRLibrary/IOCRServiceConfiguration.cs 0 → 100644 +7 −0 Original line number Diff line number Diff line namespace SimpleOCR.Library.Core { public interface IOCRServiceConfiguration { public string DataFolder { get; } } } SimpleOCRLibrary/SimpleOCRLibrary/OCRService.cs +9 −10 Original line number Diff line number Diff line using GRYLibrary.Core.Exceptions; using GRYLibrary.Core.ExecutePrograms; using GRYLibrary.Core.Logging.GRYLogger; using GRYLibrary.Core.Misc; using SimpleOCR.Library.Core.VIsitors; Loading @@ -16,14 +15,14 @@ namespace SimpleOCR.Library.Core { public bool IsInitialized { get; private set; } private readonly string _DataFolder; private readonly IOCRServiceConfiguration _Configuration; private readonly IGRYLog _Log; /// <param name="dataFolder">Location where OCRService is allowed to store downloaded OCR-data.</param> /// <remarks><see cref="OCRService"/> takes care of the download itself. The only requirement is that git is available as command.</remarks> public OCRService(string dataFolder, IGRYLog log) public OCRService(IOCRServiceConfiguration oCRServiceConfiguration, IGRYLog log) { this._DataFolder = dataFolder.Replace('\\', '/'); this._Configuration = oCRServiceConfiguration; this._Log = log; } public string GetOCRContent(byte[] fileContent, ISet<string> languages) Loading @@ -36,7 +35,7 @@ namespace SimpleOCR.Library.Core var supportedLanguages = this.GetSupportedLanguages(); foreach (string language in languages) { if (language.Count() != 3) if (language.Length != 3) { throw new BadRequestException($"Language '{language}' is not a valid ISO639-3 identifier because its length is not equal to 3."); } Loading @@ -45,7 +44,7 @@ namespace SimpleOCR.Library.Core throw new BadRequestException($"Language '{language}' is not supported."); } } string dataPath = _DataFolder; string dataPath = _Configuration.DataFolder; using TesseractEngine engine = new TesseractEngine(dataPath, languagesConcatenated, EngineMode.Default); using MemoryStream ms = new MemoryStream(fileContent); using Pix img = Pix.LoadFromMemory(ms.ToArray()); Loading @@ -64,7 +63,7 @@ namespace SimpleOCR.Library.Core { var result = new HashSet<string>(); string pattern = @"([a-z][a-z][a-z])\.traineddata"; string tessdataFolder = _DataFolder; string tessdataFolder = _Configuration.DataFolder; var files = Directory.GetFiles(tessdataFolder); foreach (var file in files) { Loading @@ -82,12 +81,12 @@ namespace SimpleOCR.Library.Core { try { string tessdataFolder = _DataFolder; string tessdataFolder = _Configuration.DataFolder; GRYLibrary.Core.Misc.Utilities.AssertCondition(!string.IsNullOrEmpty(tessdataFolder), "No OCR-data-folder set."); this._Log.Log($"OCRFolder: {tessdataFolder}"); if (!this.IsInitialized) { var traineddataFiles = Directory.GetFiles(_DataFolder).Where(file => file.EndsWith(".traineddata")); var traineddataFiles = Directory.GetFiles(_Configuration.DataFolder).Where(file => file.EndsWith(".traineddata")); GRYLibrary.Core.Misc.Utilities.AssertCondition(1 < traineddataFiles.Count(), "Expected multiple *.traineddata-files."); this.IsInitialized = true; } Loading @@ -101,7 +100,7 @@ namespace SimpleOCR.Library.Core public void ReInitialize() { GRYLibrary.Core.Misc.Utilities.EnsureDirectoryDoesNotExist(_DataFolder); GRYLibrary.Core.Misc.Utilities.EnsureDirectoryDoesNotExist(_Configuration.DataFolder); this.IsInitialized = false; this.Initialize(); } Loading SimpleOCRLibrary/SimpleOCRLibrary/OCRServiceConfiguration.cs 0 → 100644 +7 −0 Original line number Diff line number Diff line namespace SimpleOCR.Library.Core { public class OCRServiceConfiguration : IOCRServiceConfiguration { public string DataFolder { get; set; } } } Loading
Other/Metrics/LinesOfCode.csv +1 −1 Original line number Diff line number Diff line v1.3.1;3180 No newline at end of file v1.3.1;3156 No newline at end of file
SimpleOCRCLI/SimpleOCRCLI/Runner/RunWithArgumentsFromCLI.cs +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ namespace SimpleOCR.CLI.Core.Runner protected override string RunImplementation() { SimpleOCR.Library.Core.IOCRService ocrService = new SimpleOCR.Library.Core.OCRService(this._Options.OCRDataFolder, GeneralLogger.CreateUsingConsole()); SimpleOCR.Library.Core.IOCRService ocrService = new SimpleOCR.Library.Core.OCRService(new SimpleOCR.Library.Core.OCRServiceConfiguration() { DataFolder = this._Options.OCRDataFolder }, GeneralLogger.CreateUsingConsole()); ocrService.Initialize(); (FileType fileType, byte[] content,string mimeType) = SimpleOCR.Library.Core.Misc.Utilities.LoadFile(_Options.File); content = fileType.Accept(new ToPictureVisitor(content,mimeType)); Loading
SimpleOCRLibrary/SimpleOCRLibrary/IOCRServiceConfiguration.cs 0 → 100644 +7 −0 Original line number Diff line number Diff line namespace SimpleOCR.Library.Core { public interface IOCRServiceConfiguration { public string DataFolder { get; } } }
SimpleOCRLibrary/SimpleOCRLibrary/OCRService.cs +9 −10 Original line number Diff line number Diff line using GRYLibrary.Core.Exceptions; using GRYLibrary.Core.ExecutePrograms; using GRYLibrary.Core.Logging.GRYLogger; using GRYLibrary.Core.Misc; using SimpleOCR.Library.Core.VIsitors; Loading @@ -16,14 +15,14 @@ namespace SimpleOCR.Library.Core { public bool IsInitialized { get; private set; } private readonly string _DataFolder; private readonly IOCRServiceConfiguration _Configuration; private readonly IGRYLog _Log; /// <param name="dataFolder">Location where OCRService is allowed to store downloaded OCR-data.</param> /// <remarks><see cref="OCRService"/> takes care of the download itself. The only requirement is that git is available as command.</remarks> public OCRService(string dataFolder, IGRYLog log) public OCRService(IOCRServiceConfiguration oCRServiceConfiguration, IGRYLog log) { this._DataFolder = dataFolder.Replace('\\', '/'); this._Configuration = oCRServiceConfiguration; this._Log = log; } public string GetOCRContent(byte[] fileContent, ISet<string> languages) Loading @@ -36,7 +35,7 @@ namespace SimpleOCR.Library.Core var supportedLanguages = this.GetSupportedLanguages(); foreach (string language in languages) { if (language.Count() != 3) if (language.Length != 3) { throw new BadRequestException($"Language '{language}' is not a valid ISO639-3 identifier because its length is not equal to 3."); } Loading @@ -45,7 +44,7 @@ namespace SimpleOCR.Library.Core throw new BadRequestException($"Language '{language}' is not supported."); } } string dataPath = _DataFolder; string dataPath = _Configuration.DataFolder; using TesseractEngine engine = new TesseractEngine(dataPath, languagesConcatenated, EngineMode.Default); using MemoryStream ms = new MemoryStream(fileContent); using Pix img = Pix.LoadFromMemory(ms.ToArray()); Loading @@ -64,7 +63,7 @@ namespace SimpleOCR.Library.Core { var result = new HashSet<string>(); string pattern = @"([a-z][a-z][a-z])\.traineddata"; string tessdataFolder = _DataFolder; string tessdataFolder = _Configuration.DataFolder; var files = Directory.GetFiles(tessdataFolder); foreach (var file in files) { Loading @@ -82,12 +81,12 @@ namespace SimpleOCR.Library.Core { try { string tessdataFolder = _DataFolder; string tessdataFolder = _Configuration.DataFolder; GRYLibrary.Core.Misc.Utilities.AssertCondition(!string.IsNullOrEmpty(tessdataFolder), "No OCR-data-folder set."); this._Log.Log($"OCRFolder: {tessdataFolder}"); if (!this.IsInitialized) { var traineddataFiles = Directory.GetFiles(_DataFolder).Where(file => file.EndsWith(".traineddata")); var traineddataFiles = Directory.GetFiles(_Configuration.DataFolder).Where(file => file.EndsWith(".traineddata")); GRYLibrary.Core.Misc.Utilities.AssertCondition(1 < traineddataFiles.Count(), "Expected multiple *.traineddata-files."); this.IsInitialized = true; } Loading @@ -101,7 +100,7 @@ namespace SimpleOCR.Library.Core public void ReInitialize() { GRYLibrary.Core.Misc.Utilities.EnsureDirectoryDoesNotExist(_DataFolder); GRYLibrary.Core.Misc.Utilities.EnsureDirectoryDoesNotExist(_Configuration.DataFolder); this.IsInitialized = false; this.Initialize(); } Loading
SimpleOCRLibrary/SimpleOCRLibrary/OCRServiceConfiguration.cs 0 → 100644 +7 −0 Original line number Diff line number Diff line namespace SimpleOCR.Library.Core { public class OCRServiceConfiguration : IOCRServiceConfiguration { public string DataFolder { get; set; } } }