§
    �Øj  ã                   ó^   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 d„ Z	 	 dd„Zd„ Zd
S )z·
PDF feature extraction utilities - Orchestrator
Purpose: Coordinate feature extractors (RF, IMF, YF, JF)
         Each extractor lives in its own module for independent maintenance.
é   )Úmake_custom_feature)Úextract_rf_features)Úimage_feature_extraction_task)Úextract_yf_features)Úextract_jf_featuresc                 ó4   — t          d„ | D ¦   «         ¦  «        S )a¸  
    Round bbox coords to integer (pixel-level) granularity for cheap,
    tolerance-aware dedup. Detected bboxes (e.g. from IMF, which rescales
    from model resolution back to page pixel space) rarely match an
    existing bbox to the exact float, so exact-equality dedup effectively
    never fires; integer rounding treats near-identical boxes as the same
    box, which is what "already detected this region" is meant to capture.
    c              3   óN   K  — | ] }t          t          |¦  «        ¦  «        V — Œ!d S )N)ÚintÚround)Ú.0Úcs     ú”/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/pymupdf/layout/pymupdf_util_ext.pyú	<genexpr>z"_bbox_dedup_key.<locals>.<genexpr>   s.   è è € Ð-Ð- 1••U˜1‘X”X‘”Ð-Ð-Ð-Ð-Ð-Ð-ó    )Útuple)Úbboxs    r   Ú_bbox_dedup_keyr      s!   € õ Ð-Ð-¨Ð-Ñ-Ô-Ñ-Ô-Ð-r   ú	rf+imf+yfÚtextNc                 ó”  — d|v rd|v rt          d|›d�¦  «        ‚d| vrt          | ¦  «         d|v rú|�ø| d         }t          |||¦  «        \  }}}	}
|| d<   || d	<   d
„ | d         D ¦   «         }t          |	|
¦  «        D ]­\  }}t	          |¦  «        }||vr•|                     |¦  «         | d                              |¦  «         | d                              d¦  «         d| v r| d                              |¦  «         t          |d¦  «        }| d                              |¦  «         Œ®d|v r'|                      d¦  «        }|�t          | |¦  «         d|v r|�|�t          | ||¦  «         nCd|v r?|�=t          | ||d¬¦  «        }| d         }t          ||d|¬¦  «        \  }}}	}
|| d<   || d	<   d|v rt          | ¦  «         | S )a  
    Apply experimental feature extractors to base data.

    Args:
        data_dict: Base data dictionary from extract_base_elements
        feature_set_name: String indicating which features to extract (e.g., 'rf+imf+yf')
        feature_extractor: ONNX model for image feature extraction
        page: PyMuPDF page object (required for YF features)
        page_dict: Page dictionary (required for YF features)

    Returns:
        data_dict: Enhanced with custom_features

    Raises:
        ValueError: if feature_set_name requests both 'imf' and 'ymf'. These
            are mutually exclusive image-input strategies -- 'imf' runs the
            model on the plain page image, 'ymf' runs it on the page image
            with an extra YF-derived channel appended (aug_fetmap) -- not
            features meant to be combined. Declaring both would leave
            data_dict['feature_map']/['class_logits'] ambiguous (silently
            overwritten by whichever block runs second) and would run
            inference twice for no benefit.
    ÚimfÚymfzfeature_set_name=z� requests both 'imf' and 'ymf', which are mutually exclusive image-input strategies (plain image vs. YF-augmented image channel). Choose one.Úcustom_featuresNÚimageÚfeature_mapÚclass_logitsc                 ó,   — h | ]}t          |¦  «        ’ŒS © )r   )r   Úbs     r   ú	<setcomp>z+apply_feature_extractors.<locals>.<setcomp>U   s    € ÐNÐNÐN°Q�o¨aÑ0Ô0ÐNÐNÐNr   Úbboxesr   Ú Úbox_typeÚrfÚ
stext_pageÚyfT)Úreturn_fet_map)r"   )Ú
aug_fetmapÚjf)Ú
ValueErrorÚ_init_custom_featuresr   Úzipr   ÚaddÚappendr   Úgetr   r   r   )Ú	data_dictÚfeature_set_nameÚ
input_typeÚfeature_extractorÚpageÚ	page_dictÚpage_imgr   r   Úbboxes_to_addÚbox_types_to_addÚexisting_bbox_keysr   Útype_valÚkeyÚcustom_featurer%   Úyfms                     r   Úapply_feature_extractorsr>      s›  € ð2 Ð Ð Ð  UÐ.>Ð%>Ð%>ÝðHÐ 0ð Hð Hð Hñ
ô 
ð 	
ð  	Ð)Ð)Ý˜iÑ(Ô(Ð(ð Ð Ð Ð Ð%6Ð%BØ˜WÔ%ˆÝEbØÐ'¨ñF
ô F
ÑBˆ�\ =Ð2Bð $/ˆ	�-Ñ Ø$0ˆ	�.Ñ!ð OÐN¸)ÀHÔ:MÐNÑNÔNÐÝ! -Ð1AÑBÔBð 
	Dð 
	D‰NˆD�(Ý! $Ñ'Ô'ˆCØÐ,Ð,Ð,Ø"×&Ò& sÑ+Ô+Ð+Ø˜(Ô#×*Ò*¨4Ñ0Ô0Ð0Ø˜&Ô!×(Ò(¨Ñ,Ô,Ð,Ø Ð*Ð*Ø˜jÔ)×0Ò0°Ñ:Ô:Ð:å!4°X¸rÑ!BÔ!B�ØÐ+Ô,×3Ò3°NÑCÔCÐCøð ÐÐÐØ—]’] <Ñ0Ô0ˆ
ØÐ!Ý 	¨:Ñ6Ô6Ð6ð ÐÐÐØÐ 	Ð 5Ý 	¨4°Ñ;Ô;Ð;øØ	Ð"Ð	"Ð	"Ð'8Ð'Dõ " )¨T°9ÈTÐRÑRÔRˆØ˜WÔ%ˆÝEbØÐ'¨¸3ðF
ñ F
ô F
ÑBˆ�\ =Ð2Bð $/ˆ	�-Ñ Ø$0ˆ	�.Ñ!ð ÐÐÐÝ˜IÑ&Ô&Ð&àÐr   c                 ó.  — g | d<   |                       dg ¦  «        }t          t          | d         ¦  «        ¦  «        D ]V}|t          |¦  «        k     r||         nd}| d         |         }| d                              t	          ||¦  «        ¦  «         ŒWdS )z.Initialize custom_features from box_type list.r   r#   r!   Úunknownr   N)r/   ÚrangeÚlenr.   r   )r0   r#   Úrow_idxÚbtr   s        r   r+   r+   ~   s¨   € à#%€IÐÑ Ø�}Š}˜Z¨Ñ,Ô,€Hå�˜Y xÔ0Ñ1Ô1Ñ2Ô2ð Kð KˆØ")­C°©M¬MÒ"9Ð"9ˆX�gÔÐ¸yˆØ˜Ô  Ô)ˆØÐ#Ô$×+Ò+Õ,?ÀÀDÑ,IÔ,IÑJÔJÐJÐJðKð Kr   )r   r   NNN)Ú__doc__Úpymupdf_util_baser   Úpymupdf_util_rfr   Úpymupdf_util_imfr   Úpymupdf_util_yfr   Úpymupdf_util_jfr   r   r>   r+   r   r   r   ú<module>rK      sº   ððð ð 3Ð 2Ð 2Ð 2Ð 2Ð 2Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0ð	.ð 	.ð 	.ð :EØ_cðað að að aðHKð Kð Kð Kð Kr   