Models¶
Pydantic models for reading order prediction.
Takes layout detection and OCR results, produces ordered element sequence with caption and footnote associations.
Example
# Get layout and OCR
layout = layout_extractor.extract(image)
ocr = ocr_extractor.extract(image)
# Predict reading order
reading_order = predictor.predict(layout, ocr)
# Iterate in reading order
for element in reading_order.ordered_elements:
print(f"{element.index}: [{element.element_type}] {element.text[:50]}...")
# Get caption associations
for fig_id, caption_ids in reading_order.caption_map.items():
print(f"Figure {fig_id} has captions: {caption_ids}")
ElementType
¶
Bases: str, Enum
Type of document element for reading order.
BoundingBox
¶
Bases: BaseModel
Bounding box in pixel coordinates.
to_list
¶
from_list
classmethod
¶
Create from [x1, y1, x2, y2] list.
Source code in omnidocs/tasks/reading_order/models.py
to_normalized
¶
Convert to normalized coordinates (0-1024 range).
| PARAMETER | DESCRIPTION |
|---|---|
image_width
|
Original image width in pixels
TYPE:
|
image_height
|
Original image height in pixels
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BoundingBox
|
New BoundingBox with coordinates in 0-1024 range |
Source code in omnidocs/tasks/reading_order/models.py
OrderedElement
¶
Bases: BaseModel
A document element with its reading order position.
Combines layout detection results with OCR text and assigns a reading order index.
to_dict
¶
Convert to dictionary representation.
Source code in omnidocs/tasks/reading_order/models.py
ReadingOrderOutput
¶
Bases: BaseModel
Complete reading order prediction result.
Provides: - Ordered list of document elements - Caption-to-element associations - Footnote-to-element associations - Merge suggestions for split elements
Example
get_full_text
¶
Get concatenated text in reading order.
Excludes page headers, footers, captions, and footnotes from main text flow.
Source code in omnidocs/tasks/reading_order/models.py
get_elements_by_type
¶
get_captions_for
¶
Get caption elements for a given element ID.
Source code in omnidocs/tasks/reading_order/models.py
get_footnotes_for
¶
Get footnote elements for a given element ID.
Source code in omnidocs/tasks/reading_order/models.py
to_dict
¶
Convert to dictionary representation.
Source code in omnidocs/tasks/reading_order/models.py
save_json
¶
Save to JSON file.