feat: table ocr confidence added #891
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds confidence scoring capabilities to the table processing pipeline, enabling both cell-level and table-level confidence metrics to be captured and exposed in the JSON output. This enhancement provides valuable metadata about the quality and reliability of table extraction results.
Added confidence: float | None = None field to TableCell class. Enables storage of individual cell confidence scores from OCR/text extraction
Added table_confidence: float = 0.0 field to BaseTable class. Enables storage of aggregated table-level confidence scores Affects all table types: Table, TableOfContents, Form
Added calculate_table_confidence() method. Calculates average confidence across all cells in a table
Added calculate_cell_confidence() method. Calculates average confidence for individual table cells
Updated assign_ocr_lines() method. Preserves confidence data from OCR results: {"text": t, "confidence": cell_text.confidence}
Added block-specific JSON output classes:
Updated extract_json() method. Implements block-specific confidence field inclusion
TableCell blocks → JSONTableCellOutput with confidence field
Table blocks → JSONTableOutput with table_confidence field
Other blocks → JSONBlockOutput with no confidence fields
This feature could be useful when someone is working with surya plus a fallback model, so based on confidence fallback to that model can be implemented.