ó
    À‘´j‹  ã                  ó¼   • S r SSKJr  SSKJrJr  SSKJrJrJ	r	  SSK
JrJr  \(       a  SSKJr  SSKJrJr  SSKJr  \	S	   r " S
 S\5      r\ " S S5      5       rg)u¯  What the overlap matcher decides about each table on a page.

Fusion matches the Set-of-Mark/Camelot tables against docling's tables and
pictures one page at a time, by bounding-box overlap. A `RegionMatch` records
one outcome: which SoM tables and which docling items overlapped, and what that
cardinality means. The graft and annotation passes act on these records; they
make no geometric decisions of their own.

The seven kinds correspond one-to-one to the fusion matrix:

- `replace` â€” one SoM table over one docling table, both agree. The Camelot body
  replaces the docling body; the SoM table is unchanged.
- `som_merged` â€” more docling tables than SoM tables in the region: SoM fused
  stacked tables. `split_table` splits the SoM table; the splits graft in.
- `docling_undercount` â€” more SoM tables than docling tables: docling dropped or
  merged a complex table. The docling table(s) in the region are deleted and the
  Camelot tables are inserted in their place, in vertical order.
- `image_table` â€” a docling table with no text layer under it (read by OCR,
  Camelot empty): a real table rendered as an image. Docling's OCR'd table is
  kept; the SoM table is annotated as an image table.
- `chart` â€” a SoM table over a docling picture and no docling table: SoM mistook
  an image for a table. Nothing grafts; the matched picture records that
  Set-of-Mark read it, and the SoM table is annotated as a chart.
- `docling_miss` â€” a SoM table over nothing in docling: docling missed it. The
  Camelot table is inserted into the document.
- `som_miss` â€” a docling table no SoM table matched: SoM missed a table docling
  found. Reported as an error; nothing is synthesized from docling.
é    )Úannotations)Ú	dataclassÚfield)ÚTYPE_CHECKINGÚListÚLiteral)Ú	BaseModelÚField)ÚDoclingDocument)ÚCellFlagÚExtractedTable)ÚParseResult)ÚreplaceÚ
som_mergedÚdocling_undercountÚimage_tableÚchartÚdocling_missÚsom_missc                  ó¸   • \ rS rSr% SrS\S'   S\S'   \" \S9rS\S	'   \" \S9r	S
\S'   \" \S9r
S
\S'   \" \SS9rS
\S'   \" SSS9rS\S'   \" SSS9rS\S'   Srg)ÚRegionMatché6   a§  One reconciliation outcome for a region on a page.

`som_indices` index into the Set-of-Mark `ExtractedTable` list handed to the
matcher. `docling_table_refs` / `docling_picture_refs` are docling
`self_ref` strings. The combination of which lists are populated and `kind`
drives the graft and annotation passes.

After grafting, `docling_table_refs` reference the *unified* document:
the graft deletes and inserts tables, which renumbers every later table's
`self_ref`, so it rewrites each match's refs to the grafted tables' final
positions. A consumer resolving these refs against the unified document
(the report always ships beside it) lands on the table the match is about.
ÚintÚpageÚ	MatchKindÚkind©Údefault_factoryz	List[int]Úsom_indicesú	List[str]Údocling_table_refsÚdocling_picture_refszBPredicted classes of the matched docling pictures (for chart kind))r   ÚdescriptionÚpicture_classesg        z9Representative box-overlap coverage for the region (0..1))Údefaultr#   ÚfloatÚoverlapÚ z Human-readable note on the matchÚstrÚdetail© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r
   Úlistr   r!   r"   r$   r'   r*   Ú__static_attributes__r+   ó    Ú6/home/mande/repo/quber/src/quber/core/fusion/models.pyr   r   6   s†   ‡ ñð ƒIØ
ƒOÙ"°4Ñ8€K�Ó8Ù$)¸$Ñ$?Ð˜	Ó?Ù&+¸DÑ&AÐ˜)ÓAÙ!&ØØXñ"€O�Yó ñ ØÐ!\ñ€GˆUó ñ  Ð0RÑS€FˆCÖSr4   r   c                  ó~   • \ rS rSr% SrS\S'   S\S'   \" \S9rS\S	'   \" \S9r	S
\S'   \" \S9r
S\S'   SrS\S'   Srg)ÚFusionResultéT   ab  The two corrected outputs of one fusion.

`document` is the unified `DoclingDocument`: docling's spine with the Camelot
table bodies grafted in. `tables` is the corrected Set-of-Mark/Camelot output:
merged regions split, charts and image tables annotated via `ExtractedTable.kind`.
`matches` is the final per-region classification (after any split), and
`errors` surfaces the regions that could not be fused: a table docling found
that SoM missed, a merge the split pass declined, or a SoM table in a
`docling_miss` or `docling_undercount` region left out of the unified
document because Camelot read no body.
z'DoclingDocument'ÚdocumentzList['ExtractedTable']Útablesr   zList[RegionMatch]Úmatchesr    ÚerrorszList['CellFlag']Úheading_flagsNz'ParseResult | None'Úparser+   )r,   r-   r.   r/   r0   r1   r   r2   r;   r<   r=   r>   r3   r+   r4   r5   r7   r7   T   sS   ‡ ñ
ð  ÓØ"Ó"Ù!&°tÑ!<€GÐÓ<Ù¨dÑ3€FˆIÓ3ñ ',¸DÑ&A€MÐ#ÓAð
 #'€EÐÖ&r4   r7   N)r0   Ú
__future__r   Údataclassesr   r   Útypingr   r   r   Úpydanticr	   r
   Údocling_core.types.doc.documentr   Úquber.core.extractors.baser   r   Úquber.core.parsersr   r   r   r7   r+   r4   r5   Ú<module>rF      s]   ðñõ: #ç (ß /Ñ /ç %æÝ?çCÝ.àðñ€	ôT�)ô Tð< ÷'ð 'ó ñ'r4   