Predictor¶
Rule-based reading order predictor.
Uses spatial analysis and R-tree indexing to determine the logical reading sequence of document elements. Self-contained implementation without external dependencies on docling-ibm-models.
Based on the algorithm from docling-ibm-models, adapted for omnidocs.
RuleBasedReadingOrderPredictor
¶
Bases: BaseReadingOrderPredictor
Rule-based reading order predictor using spatial analysis.
Uses R-tree spatial indexing and rule-based algorithms to determine the logical reading sequence of document elements. This is a CPU-only implementation that doesn't require GPU resources.
Features: - Multi-column layout detection - Header/footer separation - Caption-to-figure/table association - Footnote linking - Element merge suggestions
Example
from omnidocs.tasks.reading_order import RuleBasedReadingOrderPredictor
from omnidocs.tasks.layout_extraction import DocLayoutYOLO, DocLayoutYOLOConfig
from omnidocs.tasks.ocr_extraction import EasyOCR, EasyOCRConfig
# Initialize components
layout_extractor = DocLayoutYOLO(config=DocLayoutYOLOConfig())
ocr = EasyOCR(config=EasyOCRConfig())
predictor = RuleBasedReadingOrderPredictor()
# Process document
layout = layout_extractor.extract(image)
ocr_result = ocr.extract(image)
reading_order = predictor.predict(layout, ocr_result)
# Get text in reading order
text = reading_order.get_full_text()
Initialize the reading order predictor.
Source code in omnidocs/tasks/reading_order/rule_based/predictor.py
predict
¶
predict(
layout: LayoutOutput,
ocr: Optional[OCROutput] = None,
page_no: int = 0,
) -> ReadingOrderOutput
Predict reading order for a single page.
| PARAMETER | DESCRIPTION |
|---|---|
layout
|
Layout detection results with bounding boxes
TYPE:
|
ocr
|
Optional OCR results for text content
TYPE:
|
page_no
|
Page number (for multi-page documents)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ReadingOrderOutput
|
ReadingOrderOutput with ordered elements and associations |
Source code in omnidocs/tasks/reading_order/rule_based/predictor.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |