Ë
    `›¾j85  ã            	       óÞ  — d dl Z d dlmZ d dlmZmZmZmZmZm	Z	m
Z
mZ d dl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d
lmZ ddlmZmZ ddlmZmZ ddlm Z  ddlm!Z! ddl"m#Z# ddl$m%Z% eeee&e'f   ef      Z(ee'eee(   e(ee&f   f   Z)ee'eee&e'f   ee&e'f   f   f   Z*ee'ee'eee&e'f   ee&e'f   f   f   f   Z+dee    dee'ef   fd„Z,d„ Z- G d„ de%«      Z.de/de
e/e/f   fd„Z0d„ Z1y)é    N)ÚPath)ÚAnyÚCallableÚDictÚIterableÚListÚOptionalÚTupleÚUnioné   )Úutil)ÚErrors)ÚLanguage)ÚMatcher)ÚScorer)ÚIDS)ÚDocÚSpan)Únormalize_token_attrsÚset_token_attrs)ÚExample)ÚSimpleFrozenList)ÚVocabé   )ÚPipeÚexamplesÚreturnc                 ó”  — d„ }i }|j                  t        j                  | dfi |¤Ž«       |j                  t        j                  | dfi |¤Ž«       |j                  t        j                  | dfd|i|¤Ž«       |j                  t        j                  | dfd|i|¤Ž«       |j                  t        j                  | dfi |¤Ž«       |S )Nc                 ó.   — t        | |«      j                  S ©N)ÚgetattrÚkey)ÚtokenÚattrs     úg/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/spacy/pipeline/attributeruler.pyÚmorph_key_getterz/attribute_ruler_score.<locals>.morph_key_getter   s   € Ü�u˜dÓ#×'Ñ'Ð'ó    ÚtagÚposÚmorphÚgetterÚlemma)Úupdater   Úscore_token_attrÚscore_token_attr_per_feat)r   Úkwargsr&   Úresultss       r%   Úattribute_ruler_scorer2      sÇ   € ò(ð €GØ‡N�N”6×*Ñ*¨8°UÑE¸fÑEÔFØ‡N�N”6×*Ñ*¨8°UÑE¸fÑEÔFØ‡N�NÜ×Ñ ¨'ÑUÐ:JÐUÈfÑUôð ‡N�NÜ×(Ñ(Ø�gñ	
Ø&6ð	
Ø:@ñ	
ôð
 ‡N�N”6×*Ñ*¨8°WÑGÀÑGÔHØ€Nr'   c                  ó   — t         S r    )r2   © r'   r%   Úmake_attribute_ruler_scorerr5   /   s   € Ü Ð r'   c                   óF  — e Zd ZdZ	 d%dedœdedededee	   dd	f
d
„Z
d&d„Zd	d	d	d	dœdee	g ee   f      dee   deee      dee   dee   dd	fd„Zdedefd„Zdefd„Zd„ Zdeeeeeef   eeef   f   f   dd	fd„Zdeeeeeeeef   eeef   f   f   f   dd	fd„Z	 d'dee   dededd	fd„Zdee   dd	fd„Zede e   fd„«       Z! e"«       fdee   de#fd„Z$ e"«       fd e#dee   dd fd!„Z% e"«       fd"ee&ef   dee   dd	fd#„Z' e"«       fd"ee&ef   dee   dd fd$„Z(y	)(ÚAttributeRulerzÂSet token-level attributes for tokens matched by Matcher patterns.
    Additionally supports importing patterns from tag maps and morph rules.

    DOCS: https://spacy.io/api/attributeruler
    F)ÚvalidateÚscorerÚvocabÚnamer8   r9   r   Nc                óž   — || _         || _        t        | j                  |¬«      | _        || _        g | _        g | _        g | _        || _        y)aç  Create the AttributeRuler. After creation, you can add patterns
        with the `.initialize()` or `.add_patterns()` methods, or load patterns
        with `.from_bytes()` or `.from_disk()`. Loading patterns will remove
        any patterns you've added previously.

        vocab (Vocab): The vocab.
        name (str): The pipe name. Defaults to "attribute_ruler".
        scorer (Optional[Callable]): The scoring method. Defaults to
            Scorer.score_token_attr for the attributes "tag", "pos", "morph" and
            "lemma" and Scorer.score_token_attr_per_feat for the attribute
            "morph".

        RETURNS (AttributeRuler): The AttributeRuler component.

        DOCS: https://spacy.io/api/attributeruler#init
        ©r8   N)	r;   r:   r   Úmatcherr8   ÚattrsÚ_attrs_unnormedÚindicesr9   )Úselfr:   r;   r8   r9   s        r%   Ú__init__zAttributeRuler.__init__:   sH   € ð0 ˆŒ	ØˆŒ
Ü˜tŸz™z°HÔ=ˆŒØ ˆŒØ!#ˆŒ
Ø+-ˆÔØ"$ˆŒØˆ�r'   c                 óz   — t        | j                  | j                  ¬«      | _        g | _        g | _        g | _        y)zReset all patterns.r=   N)r   r:   r8   r>   r?   r@   rA   ©rB   s    r%   ÚclearzAttributeRuler.clear[   s.   € ä˜tŸz™z°D·M±MÔBˆŒØˆŒ
Ø!ˆÔØˆ�r'   )ÚnlpÚpatternsÚtag_mapÚmorph_rulesÚget_examplesrG   rH   rI   rJ   c                ó˜   — | j                  «        |r| j                  |«       |r| j                  |«       |r| j                  |«       yy)a  Initialize the attribute ruler by adding zero or more patterns.

        Rules can be specified as a sequence of dicts using the `patterns`
        keyword argument. You can also provide rules using the "tag map" or
        "morph rules" formats supported by spaCy prior to v3.
        N)rF   Úadd_patternsÚload_from_tag_mapÚload_from_morph_rules)rB   rK   rG   rH   rI   rJ   s         r%   Ú
initializezAttributeRuler.initializeb   sE   € ð 	�
‰
ŒÙØ×Ñ˜hÔ'ÙØ×"Ñ" 7Ô+ÙØ×&Ñ& {Õ3ð r'   Údocc                 óÆ   — | j                  «       }	 | j                  |«      }| j                  ||«       |S # t        $ r } || j                  | |g|«      cY d}~S d}~ww xY w)zÛApply the AttributeRuler to a Doc and set all attribute exceptions.

        doc (Doc): The document to process.
        RETURNS (Doc): The processed Doc.

        DOCS: https://spacy.io/api/attributeruler#call
        N)Úget_error_handlerÚmatchÚset_annotationsÚ	Exceptionr;   )rB   rQ   Úerror_handlerÚmatchesÚes        r%   Ú__call__zAttributeRuler.__call__y   s`   € ð ×.Ñ.Ó0ˆð	<Ø—j‘j “oˆGØ× Ñ   gÔ.ØˆJøÜò 	<Ù  §¡¨D°3°%¸Ó;Õ;ûð	<ús   ’$7 ·	A Á AÁA ÁA c           	      óÒ   — | j                  |dd¬«      }|D ���cg c],  \  }}}t        | j                  j                  |   «      |||f‘Œ. }}}}|j	                  «        |S c c}}}w )NTF)Úallow_missingÚas_spans)r>   Úintr:   ÚstringsÚsort)rB   rQ   rX   Úm_idÚsrY   s         r%   rT   zAttributeRuler.match‰   sr   € Ø—,‘,˜s°$À�,ÓGˆð &÷
ð 
á��a˜ô �—‘×#Ñ# DÑ)Ó*¨D°!°QÒ7ð
ˆò 
ð 	�‰ŒØˆùô
s   ›1A"c                 ó”  — |D ]I  \  }}}}t        ||||¬«      }| j                  |   }| j                  |   }		 ||	   }
t        ||	   |«       ŒK y# t        $ rn t	        t
        j                  j                  | j                  j                  |j                  «      |D �cg c]  }|j                  ‘Œ nc c}w c}|	¬«      «      d‚w xY w)zModify the document in place)Úlabel)rH   ÚspanÚindexN)r   r?   rA   Ú
IndexErrorÚ
ValueErrorr   ÚE1001Úformatr>   Úgetrd   Útextr   )rB   rQ   rX   Úattr_idÚmatch_idÚstartÚendre   r?   rf   r#   Úts               r%   rU   zAttributeRuler.set_annotations“   sÐ   € à-4ò 	0Ñ)ˆG�X˜u cÜ˜˜U C¨xÔ8ˆDØ—J‘J˜wÑ'ˆEØ—L‘L Ñ)ˆEðð ˜U™�ô ˜D ™K¨Õ/ñ%	0øô ò 	ô !Ü—L‘L×'Ñ'Ø!%§¡×!1Ñ!1°$·*±*Ó!=Ø.2Ö3¨˜aŸf›fÑ3ùÔ3Ø#ð (ó óð ðð	ús   ¹AÁACÂB3Â2Cc                 ó”  — |j                  «       D ]µ  \  }}d|ig}t        |«      \  }}d|vrB| j                  j                  j	                  |«      }| j                  j
                  |   |d<   nD| j                  j                  j	                  |d   «      }| j                  j
                  |   |d<   | j	                  |g|«       Œ· y)zÿLoad attribute ruler patterns from a tag map.

        tag_map (dict): The tag map that maps fine-grained tags to
            coarse-grained tags and morphological features.

        DOCS: https://spacy.io/api/attributeruler#load_from_morph_rules
        ÚTAGÚMORPHN)ÚitemsÚ_split_morph_attrsr:   Ú
morphologyÚaddr_   )rB   rI   r(   r?   ÚpatternÚmorph_attrsr*   s          r%   rN   z AttributeRuler.load_from_tag_map©   s·   € ð "Ÿ-™-›/ò 		'‰JˆC�Ø˜s�|�nˆGÜ!3°EÓ!:ÑˆE�;Ø˜eÑ#ØŸ
™
×-Ñ-×1Ñ1°+Ó>�Ø!%§¡×!3Ñ!3°EÑ!:��g’àŸ
™
×-Ñ-×1Ñ1°%¸±.ÓA�Ø!%§¡×!3Ñ!3°EÑ!:��g‘Ø�H‰H�g�Y Õ&ñ		'r'   c                 óœ  — |D ]Ç  }||   D ]½  }||dœg}||   |   }t        |«      \  }}d|v rE| j                  j                  j                  |d   «      }| j                  j                  |   |d<   nC|rA| j                  j                  j                  |«      }| j                  j                  |   |d<   | j                  |g|«       Œ¿ ŒÉ y)a+  Load attribute ruler patterns from morph rules.

        morph_rules (dict): The morph rules that map token text and
            fine-grained tags to coarse-grained tags, lemmas and morphological
            features.

        DOCS: https://spacy.io/api/attributeruler#load_from_morph_rules
        )ÚORTHrs   rt   N)rv   r:   rw   rx   r_   )rB   rJ   r(   Úwordry   r?   rz   r*   s           r%   rO   z$AttributeRuler.load_from_morph_rules¾   sÕ   € ð ò 	+ˆCØ# CÑ(ò 
+�Ø$(°Ñ5Ð6�Ø# CÑ(¨Ñ.�Ü%7¸Ó%>Ñ"��{Ø˜eÑ#Ø ŸJ™J×1Ñ1×5Ñ5°e¸G±nÓE�EØ%)§Z¡Z×%7Ñ%7¸Ñ%>�E˜'’NÙ Ø ŸJ™J×1Ñ1×5Ñ5°kÓB�EØ%)§Z¡Z×%7Ñ%7¸Ñ%>�E˜'‘NØ—‘˜'˜ EÕ*ñ
+ñ	+r'   r?   rf   c                 óŒ  — t        t        | j                  «      «      }| j                  j	                  | j
                  j                  j	                  |«      |«       | j                  j                  |«       t        | j
                  |«      }| j                  j                  |«       | j                  j                  |«       y)aB  Add Matcher patterns for tokens that should be modified with the
        provided attributes. The token at the specified index within the
        matched span will be assigned the attributes.

        patterns (Iterable[List[Dict]]): A list of Matcher patterns.
        attrs (Dict): The attributes to assign to the target token in the
            matched span.
        index (int): The index of the token in the matched span to modify. May
            be negative to index from the end of the span. Defaults to 0.

        DOCS: https://spacy.io/api/attributeruler#add
        N)ÚstrÚlenr?   r>   rx   r:   r_   r@   Úappendr   rA   )rB   rH   r?   rf   r"   s        r%   rx   zAttributeRuler.addÖ   s‡   € ô" ”#�d—j‘j“/Ó"ˆØ�‰×Ñ˜Ÿ™×+Ñ+×/Ñ/°Ó4°hÔ?Ø×Ñ×#Ñ# EÔ*Ü% d§j¡j°%Ó8ˆØ�
‰
×Ñ˜%Ô Ø�‰×Ñ˜EÕ"r'   c                 ó6   — |D ]  } | j                   di |¤Ž Œ y)ac  Add patterns from a list of pattern dicts with the keys as the
        arguments to AttributeRuler.add.
        patterns (Iterable[dict]): A list of pattern dicts with the keys
            as the arguments to AttributeRuler.add (patterns/attrs/index) to
            add as patterns.

        DOCS: https://spacy.io/api/attributeruler#add_patterns
        Nr4   )rx   )rB   rH   Úps      r%   rM   zAttributeRuler.add_patternsî   s"   € ð ò 	ˆAØˆD�H‰H‰M�q‹Mñ	r'   c                 ó  — g }t        t        | j                  «      «      D ]c  }i }| j                  j	                  t        |«      «      d   |d<   | j                  |   |d<   | j                  |   |d<   |j                  |«       Œe |S )zAll the added patterns.r   rH   r?   rf   )	Úranger€   r?   r>   rk   r   r@   rA   r�   )rB   Úall_patternsÚirƒ   s       r%   rH   zAttributeRuler.patternsú   s†   € ð ˆÜ”s˜4Ÿ:™:“Ó'ò 	#ˆAØˆAØ ŸL™L×,Ñ,¬S°«VÓ4°QÑ7ˆAˆj‰MØ×-Ñ-¨aÑ0ˆAˆg‰JØŸ™ a™ˆAˆg‰JØ×Ñ Õ"ð	#ð Ðr'   Úexcludec                 óX   ‡ ‡— i }ˆˆ fd„|d<   ˆ fd„|d<   t        j                  |‰«      S )zõSerialize the AttributeRuler to a bytestring.

        exclude (Iterable[str]): String names of serialization fields to exclude.
        RETURNS (bytes): The serialized object.

        DOCS: https://spacy.io/api/attributeruler#to_bytes
        c                  ó<   •— ‰j                   j                  ‰ ¬«      S ©N)rˆ   )r:   Úto_bytes)rˆ   rB   s   €€r%   ú<lambda>z)AttributeRuler.to_bytes.<locals>.<lambda>  s   ø€  T§Z¡Z×%8Ñ%8ÀÐ%8Ó%I€ r'   r:   c                  óB   •— t        j                  ‰ j                  «      S r    )ÚsrslyÚmsgpack_dumpsrH   rE   s   €r%   r�   z)AttributeRuler.to_bytes.<locals>.<lambda>  s   ø€ ¬×(;Ñ(;¸D¿M¹MÓ(J€ r'   rH   )r   rŒ   )rB   rˆ   Ú	serializes   `` r%   rŒ   zAttributeRuler.to_bytes  s/   ù€ ð ˆ	ÜIˆ	�'ÑÛ Jˆ	�*ÑÜ�}‰}˜Y¨Ó0Ð0r'   Ú
bytes_datac                 óT   ‡ ‡— ˆ fd„}ˆˆ fd„|dœ}t        j                  ||‰«       ‰ S )a'  Load the AttributeRuler from a bytestring.

        bytes_data (bytes): The data to load.
        exclude (Iterable[str]): String names of serialization fields to exclude.
        returns (AttributeRuler): The loaded object.

        DOCS: https://spacy.io/api/attributeruler#from_bytes
        c                 óN   •— ‰j                  t        j                  | «      «       y r    )rM   r�   Úmsgpack_loads)ÚbrB   s    €r%   Úload_patternsz0AttributeRuler.from_bytes.<locals>.load_patterns  s   ø€ Ø×Ñœe×1Ñ1°!Ó4Õ5r'   c                 ó>   •— ‰j                   j                  | ‰¬«      S r‹   )r:   Ú
from_bytes)r–   rˆ   rB   s    €€r%   r�   z+AttributeRuler.from_bytes.<locals>.<lambda>#  s   ø€ ˜tŸz™z×4Ñ4°QÀÐ4ÓH€ r'   ©r:   rH   )r   r™   )rB   r’   rˆ   r—   Údeserializes   ` `  r%   r™   zAttributeRuler.from_bytes  s/   ù€ ô	6ô IØ%ñ
ˆô 	�‰˜
 K°Ô9Øˆr'   Úpathc                 óN   ‡ ‡— ˆˆ fd„ˆ fd„dœ}t        j                  ||‰«       y)zôSerialize the AttributeRuler to disk.

        path (Union[Path, str]): A path to a directory.
        exclude (Iterable[str]): String names of serialization fields to exclude.

        DOCS: https://spacy.io/api/attributeruler#to_disk
        c                 ó>   •— ‰j                   j                  | ‰¬«      S r‹   )r:   Úto_disk©rƒ   rˆ   rB   s    €€r%   r�   z(AttributeRuler.to_disk.<locals>.<lambda>4  s   ø€ ˜tŸz™z×1Ñ1°!¸WÐ1ÓE€ r'   c                 óD   •— t        j                  | ‰j                  «      S r    )r�   Úwrite_msgpackrH   ©rƒ   rB   s    €r%   r�   z(AttributeRuler.to_disk.<locals>.<lambda>5  s   ø€ ¤%×"5Ñ"5°a¸¿¹Ó"G€ r'   rš   N)r   rŸ   )rB   rœ   rˆ   r‘   s   ` ` r%   rŸ   zAttributeRuler.to_disk)  s%   ù€ ô FÛGñ
ˆ	ô 	�‰�T˜9 gÕ.r'   c                 óT   ‡ ‡— ˆ fd„}ˆˆ fd„|dœ}t        j                  ||‰«       ‰ S )a(  Load the AttributeRuler from disk.

        path (Union[Path, str]): A path to a directory.
        exclude (Iterable[str]): String names of serialization fields to exclude.
        RETURNS (AttributeRuler): The loaded object.

        DOCS: https://spacy.io/api/attributeruler#from_disk
        c                 óN   •— ‰j                  t        j                  | «      «       y r    )rM   r�   Úread_msgpackr£   s    €r%   r—   z/AttributeRuler.from_disk.<locals>.load_patternsE  s   ø€ Ø×Ñœe×0Ñ0°Ó3Õ4r'   c                 ó>   •— ‰j                   j                  | ‰¬«      S r‹   )r:   Ú	from_diskr    s    €€r%   r�   z*AttributeRuler.from_disk.<locals>.<lambda>I  s   ø€ ˜tŸz™z×3Ñ3°A¸wÐ3ÓG€ r'   rš   )r   r¨   )rB   rœ   rˆ   r—   r›   s   ` `  r%   r¨   zAttributeRuler.from_disk9  s/   ù€ ô	5ô HØ%ñ
ˆô 	�‰�t˜[¨'Ô2Øˆr'   )Úattribute_ruler)r   N)r   ))Ú__name__Ú
__module__Ú__qualname__Ú__doc__r2   r   r   Úboolr	   r   rC   rF   r   r   r   ÚAttributeRulerPatternTypeÚ
TagMapTypeÚMorphRulesTyperP   r   rZ   rT   rU   r   r   r^   rN   rO   ÚMatcherPatternTyperx   rM   Úpropertyr   rH   r   ÚbytesrŒ   r™   r   rŸ   r¨   r4   r'   r%   r7   r7   3   s“  „ ñð &ðð
 Ø%:òàðð ðð
 ðð ˜Ñ"ðð 
óóBð #'ØBFØ(,Ø04ò4à˜x¨¨H°WÑ,=Ð(=Ñ>Ñ?ð4ð �hÑð	4ð
 ˜8Ð$=Ñ>Ñ?ð4ð ˜*Ñ%ð4ð ˜nÑ-ð4ð 
ó4ð.<˜Cð < Có <ð ˜ó ò0ð,'Ø˜C  e¨C°¨H¡o°u¸SÀ#¸X±Ð&FÑ!GÐGÑHð'à	ó'ð*+Ø  T¨#¨t°E¸#¸s¸(±OÀUÈ3ÐPSÈ8Á_Ð4TÑ/UÐ*UÑ%VÐ VÑWð+à	ó+ð2 QRñ#Ø Ð!3Ñ4ð#Ø=Að#ØJMð#à	ó#ð0
 XÐ.GÑ%Hð 
ÈTó 
ð ð	˜$Ð8Ñ9ò 	ó ð	ñ 1AÓ0Bñ 1 ¨¡ð 1Àuó 1ñ ;KÓ:LñØðØ*2°3©-ðà	óñ. @PÓ?Qñ/Ø˜$ ˜)Ñ$ð/Ø/7¸©}ð/à	ó/ñ" @PÓ?QñØ˜$ ˜)Ñ$ðØ/7¸©}ðà	ôr'   r7   r?   c                 ó¸   — i }i }| j                  «       D ]@  \  }}|dv s,|t        j                  «       v s|t        j                  «       v r|||<   Œ<|||<   ŒB ||fS )zÓSplit entries from a tag map or morph rules dict into to two dicts, one
    with the token-level features (POS, LEMMA) and one with the remaining
    features, which are presumed to be individual MORPH features.Ú_)ru   r   ÚkeysÚvalues)r?   Úother_attrsrz   ÚkÚvs        r%   rv   rv   P  sf   € ð €KØ€KØ—‘“ò ‰ˆˆ1Ø�‰8�qœCŸH™H›J‘¨!¬s¯z©z«|Ñ*;ØˆK˜ŠNàˆK˜ŠNð	ð
 ˜Ð#Ð#r'   c                 óx   — | dk(  r!t        j                  d«      }|j                  S t        dt        › d| › �«      ‚)NÚmake_attribute_rulerzspacy.pipeline.factorieszmodule z has no attribute )Ú	importlibÚimport_moduler½   ÚAttributeErrorrª   )r;   Úmodules     r%   Ú__getattr__rÂ   _  sA   € ØÐ%Ò%Ü×(Ñ(Ð)CÓDˆØ×*Ñ*Ð*Ü
˜7¤8 *Ð,>¸t¸fÐEÓ
FÐFr'   )2r¾   Úpathlibr   Útypingr   r   r   r   r   r	   r
   r   r�   Ú r   Úerrorsr   Úlanguager   r>   r   r9   r   Úsymbolsr   Útokensr   r   Útokens._retokenizer   r   Útrainingr   r   r:   r   Úpiper   r^   r   r²   r¯   r°   r±   r2   r5   r7   Údictrv   rÂ   r4   r'   r%   ú<module>rÎ      s4  ðÛ Ý ß N× NÓ Nã å Ý Ý Ý Ý Ý ß ß GÝ Ý #Ý Ý à˜$˜u S¨# X™°Ð3Ñ4Ñ5Ð Ø ØˆˆtÐ&Ñ'Ð);¸TÀ3ÐFÑ	GÐGñÐ ð �#�t˜E # s (™O¨U°3¸°8©_Ð<Ñ=Ð=Ñ>€
Ø�c˜4  T¨%°°S°©/¸5ÀÀcÀ¹?Ð*JÑ%KÐ KÑLÐLÑM€ð H¨WÑ$5ð ÀDÈÈcÈÁNó ò&!ôZ�Tô Zðz$˜dð $ u¨T°4¨ZÑ'8ó $óGr'   