a
    ¡˜ëj¹  ã                2   @   sª  U d Z ddlmZmZ ddlmZmZ ddlmZ e	e
e	 dœdd„Zeeej ee f dœd	d
„ZeejƒZdd„ eD ƒZeeeef eej f ed< dd„ eD ƒZeeeej f ed< ejejejejejejejejejejejej ej!ej"ej#ej$ej%ej&ej'ej'ej'ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4ejej5ejej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@dœ1ZAeeeej f ed< eƒ ZBdS )zÈ
This module contains mapping between:
HTML Tags <-> Elements Ontology <-> Unstructured Element classes
They are used to simplify transformations between different representations
of parsed documents
é    )ÚDictÚType)ÚelementsÚontology)ÚElement)ÚclsÚreturnc                 C   s,   |   ¡ }| ¡ }|D ]}| t|ƒ¡ q|S )zÓ
    Recursively find all subclasses of a given class.

    Parameters:
    cls (type): The class for which to find all subclasses.

    Returns:
    list[type]: A list of all subclasses of the given class.
    )Ú__subclasses__ÚcopyÚextendÚget_all_subclasses)r   Z
subclassesZall_subclassesÚsubclass© r   ú^/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/unstructured/documents/mappings.pyr      s
    
r   )r   c               Ž   C   s@  t jtjt jtjt jtjt jtjt jtjt j	tj	t j
tj
t jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt jtjt j tj t j!tj t j"tjt j#tjt j$tj t j%tj t j&tj t j'tj(t j)tj(t j*tj*t j+tj*t j,tjt j-tjt j.tjt j/tjt j0tjt j1tjt j2tjt j3tjt j4tjt j5tjt j6tjt j7tjt j8tjt j9tjt j:tjt j;tjt j<tjt j=tjt j>tjt j?tjt j@tjt jAtjAt jBtjBt jCtjt jDtjt jEtjt jFtjt jGtjt jHtj	t jItjt jJtjt jKtjiG} | S )au  
    Get a mapping of ontology element to unstructured type.

    The dictionary here was created base on ontology mapping json
    Can be generated via the following code:
    ```
        ontology_elements_list = json.loads(
            Path("unstructured_element_ontology.json").read_text()
        )
        ontology_to_unstructured_class_mapping = {
            ontology_element["name"]: ontology_element["ontologyV1Mapping"]
            for ontology_element in ontology_elements_list
    }
    ```

    Returns:
    dict: A dictionary where keys are ontology element classes
          and values are unstructured types.
    )Lr   ÚDocumentr   ÚTextÚSectionZPageZColumnÚ	ParagraphZNarrativeTextÚHeaderÚFooterÚSidebarÚ	PageBreakÚTitleÚSubtitleÚHeadingÚQuoteZFootnoteÚCaptionZFigureCaptionZ
PageNumberÚUncategorizedTextÚOrderedListÚUnorderedListÚDefinitionListÚListItemÚTableÚTableRowÚ	TableCellÚTableCellHeaderÚ	TableBodyÚTableHeaderÚImageÚFigureÚVideoÚAudioZBarcodeZQRCodeZLogoÚ	CodeBlockZCodeSnippetZ
InlineCodeZFormulaÚEquationÚFootnoteReferenceÚCitationZBibliographyZGlossaryZAuthorZMetaDateÚKeywordsZAbstractÚ	HyperlinkZTableOfContentsÚIndexÚFormÚ	FormFieldZFormFieldValueÚCheckboxZRadioButtonÚButtonÚCommentÚ	HighlightÚRevisionInsertionÚRevisionDeletionÚAddressZEmailAddressZPhoneNumberZCalendarDateÚTimeZCurrencyZMeasurementZ
LetterheadÚ	SignatureZ	WatermarkZStamp)Z&ontology_to_unstructured_class_mappingr   r   r   Ú)get_ontology_to_unstructured_type_mapping!   s’    ¹Jr>   c                 C   s(   i | ] }|ƒ j D ]}||ƒ jf|“qqS r   )Zallowed_tagsÚcss_class_name)Ú.0Úelement_typeÚtagr   r   r   Ú
<dictcomp>…   s   þrC   Ú)HTML_TAG_AND_CSS_NAME_TO_ELEMENT_TYPE_MAPc                 C   s   i | ]}|ƒ j |“qS r   )r?   )r@   rA   r   r   r   rC   Š   s   ÚCSS_CLASS_TO_ELEMENT_TYPE_MAP)1ÚaÚaddressÚasideÚaudioÚ
blockquoteÚbodyÚbuttonZciteÚcodeÚdelÚdivÚdlÚ
figcaptionÚfigureÚfooterÚformÚh1Úh2Úh3Úh4Úh5Úh6ÚheaderÚhrÚimgÚinputZinsÚlabelÚliÚmarkÚmathÚmetaÚnavÚolÚpÚpreÚsectionÚspanÚsubÚsvgÚtableÚtbodyÚtdÚthÚtheadÚtimeÚtrÚulÚvideoÚ$HTML_TAG_TO_DEFAULT_ELEMENT_TYPE_MAPN)CÚ__doc__Útypingr   r   Zunstructured.documentsr   r   Zunstructured.documents.elementsr   ÚtypeÚlistr   ÚdictZOntologyElementr>   ZALL_ONTOLOGY_ELEMENT_TYPESrD   ÚtupleÚstrÚ__annotations__rE   r1   r;   r   r+   r   r   r6   r/   r,   r:   r   r    r   r)   r   r3   r   r   r   r   r   r(   r5   r9   r4   r!   r8   r-   r0   r2   r   r   r   r.   r=   r"   r&   r$   r%   r'   r<   r#   r   r*   ru   Z+ONTOLOGY_CLASS_TO_UNSTRUCTURED_ELEMENT_TYPEr   r   r   r   Ú<module>   s€   ÿc
þ$ÿÏ5