OCR model update#4309
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughRelocates ActOcr into the GingerCore.Actions namespace, updates references, refactors OCR model retrieval to use a downloadable online model, overhauls PDF table extraction to use Tabula/PdfPig, and updates project package references and build entries. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant OcrOps as GingerOcrOperations
participant ModelSvc as Online OCR Model (Sdcb.PaddleOCR.Models.Online)
participant PdfPig as PdfPig (render)
participant Tabula as Tabula Detectors/Extractors
User->>OcrOps: Request PDF/text/table extraction
OcrOps->>ModelSvc: Call GetOCRModel() (download & prepare)
ModelSvc-->>OcrOps: Return prepared model
OcrOps->>PdfPig: Render page -> images
loop For each page
OcrOps->>Tabula: Detect table areas
Tabula-->>OcrOps: Table area(s)
loop For each area
OcrOps->>Tabula: Extract table data
Tabula-->>OcrOps: Return table rows/cols
end
OcrOps->>ModelSvc: OCR image bytes
ModelSvc-->>OcrOps: Return extracted text
end
OcrOps-->>User: Return aggregated text/table results (with logs/errors)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 13
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (6)
Ginger/GingerCore/Actions/ActOcr.cs (4)
249-250: Remove unused backing property.
mGetFromRowNumberis never used; keep onlyGetFromRowNumber.- private string mGetFromRowNumber { get; set; } = "0";
293-294: Remove unused local.
dctOutputis declared but never used.- Dictionary<string, object> dctOutput = [];
348-349: Remove unused local.Duplicate unused
dctOutputhere as well.- Dictionary<string, object> dctOutput = [];
387-394: Harden parsing of UseRowNumber and GetFromRowNumber to avoid runtime exceptions.
bool.Parse/int.Parsewill throw on invalid/empty input (common when actions run headless). Default safely.case eActOcrPdfOperations.ReadTextFromTableInPdf: if (string.IsNullOrEmpty(GetFromRowNumber)) { GetFromRowNumber = "0"; } - resultText = GingerOcrOperations.ReadTextFromPdfTable(ValueExpression.Calculate(OcrFilePath), ValueExpression.Calculate(FirstString), ValueExpression.Calculate(PageNumber), bool.Parse(UseRowNumber), - int.Parse(ValueExpression.Calculate(GetFromRowNumber)), ElementLocateBy, ValueExpression.Calculate(ConditionColumnName), - ValueExpression.Calculate(ConditionColumnValue), decryptedPassword); + // Safe parsing with defaults + bool useRow = false; + bool.TryParse(UseRowNumber, out useRow); + int fromRow = 0; + int.TryParse(ValueExpression.Calculate(GetFromRowNumber), out fromRow); + if (fromRow < 0) fromRow = 0; + + resultText = GingerOcrOperations.ReadTextFromPdfTable( + ValueExpression.Calculate(OcrFilePath), + ValueExpression.Calculate(FirstString), + ValueExpression.Calculate(PageNumber), + useRow, + fromRow, + ElementLocateBy, + ValueExpression.Calculate(ConditionColumnName), + ValueExpression.Calculate(ConditionColumnValue), + decryptedPassword); if (!string.IsNullOrEmpty(resultText)) { ProcessOutput(resultText); } else { Error = "Unable to read text from PDF"; } break;Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs (2)
228-233: Bug: toggles reversed when “Select Column Value” radio is checked.Currently sets
UseRowNumber = trueand enables Row Number fields instead of Column filters. Fix below.- mAct.UseRowNumber = rb.IsChecked.Value.ToString(); - xRowNumber.IsEnabled = rb.IsChecked.Value; - xColumnWhere.IsEnabled = !rb.IsChecked.Value; - xColumnWhereValue.IsEnabled = !rb.IsChecked.Value; - xOperationCombo.IsEnabled = !rb.IsChecked.Value; + var isColumnValue = rb.IsChecked == true; + mAct.UseRowNumber = (!isColumnValue).ToString(); + xRowNumber.IsEnabled = !isColumnValue; + xColumnWhere.IsEnabled = isColumnValue; + xColumnWhereValue.IsEnabled = isColumnValue; + xOperationCombo.IsEnabled = isColumnValue;
83-92: Store solution-relative path in the action — don’t convert back to full when savingSolutionRepository.ConvertFullPathToBeRelative produces a solution-root relative path (prefixes with the solution-root sign) and GetFolderFullPath converts such relative paths back to absolute (SolutionRepository.cs — GetFolderFullPath ~line 392; ConvertFullPathToBeRelative ~line 421). In ActOcrEditPage.xaml.cs the browse handler currently does ConvertFullPathToBeRelative(fileName) then immediately calls GetFolderFullPath(fileName) and assigns that absolute path to mAct.OcrFilePath while displaying the relative path (browse handler, ActOcrEditPage.xaml.cs, ~lines 80–110). That stores an absolute path in the action and risks portability; ActSikuliEditPage stores the relative path instead (ActSikuliEditPage.xaml.cs ~line 151). Change the browse handler to store the relative path (assign fileName after ConvertFullPathToBeRelative) and resolve to full path only at execution time, or make this behavior consistent across actions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs(1 hunks)Ginger/GingerCore/Actions/ActOcr.cs(1 hunks)Ginger/GingerCore/GingerCore.csproj(2 hunks)Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs(6 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-04-25T13:29:45.059Z
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4188
File: Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs:22-23
Timestamp: 2025-04-25T13:29:45.059Z
Learning: The `using Amdocs.Ginger.Repository;` statement in Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs is necessary as it provides access to the `ObservableList<>` class which is used throughout the file for collections of RunSetConfig, AnalyzerItemBase, and ApplicationPOMModel objects.
Applied to files:
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.csGinger/GingerCore/Actions/ActOcr.cs
📚 Learning: 2025-06-16T10:37:13.073Z
Learnt from: prashelke
PR: Ginger-Automation/Ginger#4232
File: Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/VRTAnalyzer.cs:19-22
Timestamp: 2025-06-16T10:37:13.073Z
Learning: In Ginger codebase, both `using amdocs.ginger.GingerCoreNET;` and `using Amdocs.Ginger.CoreNET;` are valid and serve different purposes. The first (lowercase) contains the WorkSpace class and related workspace functionality, while the second (proper case) contains drivers like GenericAppiumDriver and other core functionality. Both may be required in files that use types from both namespaces.
Applied to files:
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.csGinger/GingerCore/Actions/ActOcr.cs
📚 Learning: 2025-04-25T13:29:45.059Z
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4188
File: Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs:22-23
Timestamp: 2025-04-25T13:29:45.059Z
Learning: The `using Amdocs.Ginger.Repository;` statement in Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs is necessary as it imports the ObservableList<> class which is used throughout the file.
Applied to files:
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs
📚 Learning: 2025-03-20T11:10:30.816Z
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4137
File: Ginger/Ginger/SourceControl/SourceControlProjectsPage.xaml.cs:21-21
Timestamp: 2025-03-20T11:10:30.816Z
Learning: The `Amdocs.Ginger.Common.SourceControlLib` namespace is required in files that reference the `GingerSolution` class for source control operations in the Ginger automation framework.
Applied to files:
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs
🧬 Code graph analysis (3)
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs (1)
Ginger/GingerCore/Actions/ActOcr.cs (1)
ActOcr(28-424)
Ginger/GingerCore/Actions/ActOcr.cs (1)
Ginger/GingerCore/Drivers/MainFrame/MainFrameDriver.cs (1)
Actions(508-512)
Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs (2)
Ginger/GingerCore/Actions/ActOcr.cs (1)
ActOcr(28-424)Ginger/GingerCoreCommon/ReporterLib/Reporter.cs (1)
Reporter(28-357)
🔇 Additional comments (6)
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs (3)
22-22: Correct import for relocated ActOcr.Importing
GingerCore.Actionsaligns the editor with the new namespace.
28-28: Static using updated to new ActOcr location.Good alignment with the refactor.
19-21: Both CoreNET namespaces are acceptable per repo conventions.Keeping
using amdocs.ginger.GingerCoreNET;is valid for WorkSpace usage (per retrieved learnings).Ginger/GingerCore/GingerCore.csproj (2)
201-201: Include of moved file is correct.
Actions\ActOcr.csis compiled under GingerCore; matches the relocation.
544-548: No lockstep required — versions are compatible. Sdcb.PaddleInference 3.0.0 (runtime 3.0.0.36), Sdcb.PaddleOCR 3.0.0 and Sdcb.PaddleOCR.Models.Online 3.0.1 have no documented requirement to be exact-equal; no changes required.Ginger/GingerCore/Actions/ActOcr.cs (1)
26-26: Approve — namespace relocation complete; no remainingGingerCore.ActOcrreferences.Search for
GingerCore.ActOcrreturned no matches; ActOcr is defined at Ginger/GingerCore/Actions/ActOcr.cs (namespace GingerCore.Actions) and usages reference GingerCore.Actions or unqualified ActOcr (e.g., Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs).
Thank you for your contribution.
Before submitting this PR, please make sure:
Summary by CodeRabbit
New Features
Refactor
Chores
Tests