Skip to content

API Reference parrot_loaders.ocr.layout

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_loaders.ocr.layout

View source

Heuristic layout analyzer for parrot_loaders.

Converts a flat list of :class:OCRBlock objects into a structured :class:LayoutResult using pure geometry-based heuristics.

Stages

  1. Line grouping — cluster blocks whose y-centres are within line_threshold pixels of each other.
  2. Header detection — mark a line as a header when its text is significantly larger than average, or it is written in ALL CAPS.
  3. Table detection — identify 3+ consecutive lines whose column x-positions are vertically aligned.
  4. Column detection — count how many visual columns are present.

The :func:render_markdown function converts a :class:LayoutResult into a clean Markdown string.

Class HeuristicLayoutAnalyzer

Geometry-based layout analyzer that requires no ML model.

Parameter Type Default Description
line_threshold float 10.0 Maximum vertical pixel distance between the y-centres of two blocks for them to be placed on the same line.
table_min_rows int 3 Minimum number of consecutive lines needed to call a region a table.
column_align_tolerance float 20.0 Maximum horizontal pixel difference between the x1 positions of two blocks on different lines for them to be considered column-aligned.
header_font_ratio float 1.5 Ratio above the median font size that causes a block to be classified as a header (default 1.5×).

Method HeuristicLayoutAnalyzer.analyze

Analyse blocks and return a structured :class:LayoutResult.

analyze(blocks: List[OCRBlock]) -> LayoutResult

Parameter Type Default Description
blocks List[OCRBlock] Raw OCR blocks to analyse.

Returns: LayoutResult — class:LayoutResult containing grouped lines, detected tables, column count, and average confidence.

Alias LayoutLine

Re-exported from parrot_loaders.ocr.models.LayoutLine.

Alias LayoutResult

Re-exported from parrot_loaders.ocr.models.LayoutResult.

Alias OCRBlock

Re-exported from parrot_loaders.ocr.models.OCRBlock.

Function render_markdown

Convert a :class:LayoutResult into a Markdown string.

Rendering rules:

  • Headers → ## <text>
  • Table lines → rendered as a Markdown table with a separator row after the first row.
  • Regular lines → plain text; consecutive non-table, non-header lines are joined within a paragraph (separated by spaces), and paragraphs are separated by \n\n.

render_markdown(layout: LayoutResult) -> str

Parameter Type Default Description
layout LayoutResult The layout result to render.

Returns: str — A Markdown-formatted string.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally