Ë
    `›¾jë.  ã                   ó  — d dl Z 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mZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZmZ ddlmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% dee   dee&ef   fd„Z'd„ Z( G d„ de%«      Z)d„ Z*y)é    N)ÚPath)ÚAnyÚCallableÚDictÚIterableÚListÚOptionalÚTupleÚUnion)ÚModelé   )Úutil)ÚErrorsÚWarnings)ÚLanguage)ÚLookupsÚload_lookups)ÚScorer)ÚDocÚToken)ÚExample)ÚSimpleFrozenListÚlogger)ÚVocabé   )ÚPipeÚexamplesÚreturnc                 ó0   — t        j                  | dfi |¤ŽS )NÚlemma)r   Úscore_token_attr)r   Úkwargss     úc/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/spacy/pipeline/lemmatizer.pyÚlemmatizer_scorer$      s   € Ü×"Ñ" 8¨WÑ?¸Ñ?Ð?ó    c                  ó   — t         S ©N)r$   © r%   r#   Úmake_lemmatizer_scorerr)      s   € ÜÐr%   c                   óø  — e Zd ZdZededeee   ee   f   fd„«       Z	 d%dde	dœde
d	ee   d
edededee   ddfd„Zed„ «       Zdedefd„Z	 d&dddœdeeg ee   f      dee   dee   fd„Zej4                  fdeddfd„Zdedee   fd„Zdedee   fd„Zdedefd„Z e «       dœde!ee"f   dee   fd „Z# e «       dœde!ee"f   dee   dd fd!„Z$ e «       dœdee   de%fd"„Z& e «       dœd#e%dee   dd fd$„Z'y)'Ú
Lemmatizerz�
    The Lemmatizer supports simple part-of-speech-sensitive suffix rules and
    lookup tables.

    DOCS: https://spacy.io/api/lemmatizer
    Úmoder   c                 ó6   — |dk(  rdgg fS |dk(  rdgddgfS g g fS )a  Returns the lookups configuration settings for a given mode for use
        in Lemmatizer.load_lookups.

        mode (str): The lemmatizer mode.
        RETURNS (Tuple[List[str], List[str]]): The required and optional
            lookup tables for this mode.
        ÚlookupÚlemma_lookupÚruleÚlemma_rulesÚ	lemma_excÚlemma_indexr(   )Úclsr,   s     r#   Úget_lookups_configzLemmatizer.get_lookups_config$   s<   € ð �8ÒØ#Ð$ bÐ)Ð)Ø�VŠ^Ø"�O k°=Ð%AÐBÐBØ�Bˆxˆr%   r.   F)r,   Ú	overwriteÚscorerÚvocabÚmodelÚnamer6   r7   Nc                óÀ  — || _         || _        || _        || _        t	        «       | _        || _        d| _        | j                  dk(  r| j                  | _
        nv| j                  dk(  r| j                  | _
        nU| j                  › d�}t        | |«      s)t        t        j                  j!                  |¬«      «      ‚t#        | |«      | _
        i | _        || _        y)a&  Initialize a Lemmatizer.

        vocab (Vocab): The vocab.
        model (Model): A model (not yet implemented).
        name (str): The component name. Defaults to "lemmatizer".
        mode (str): The lemmatizer mode: "lookup", "rule". Defaults to "lookup".
        overwrite (bool): Whether to overwrite existing lemmas. Defaults to
            `False`.
        scorer (Optional[Callable]): The scoring method. Defaults to
            Scorer.score_token_attr for the attribute "lemma".

        DOCS: https://spacy.io/api/lemmatizer#init
        Fr.   r0   Ú
_lemmatize)r,   N)r8   r9   r:   Ú_moder   Úlookupsr6   Ú
_validatedr,   Úlookup_lemmatizeÚ	lemmatizeÚrule_lemmatizeÚhasattrÚ
ValueErrorr   ÚE1003ÚformatÚgetattrÚcacher7   )Úselfr8   r9   r:   r,   r6   r7   Ú	mode_attrs           r#   Ú__init__zLemmatizer.__init__3   s¼   € ð. ˆŒ
ØˆŒ
ØˆŒ	ØˆŒ
Ü“yˆŒØ"ˆŒØˆŒØ�9‰9˜Ò Ø!×2Ñ2ˆD�NØ�Y‰Y˜&Ò Ø!×0Ñ0ˆD�NàŸ9™9˜+ ZÐ0ˆIÜ˜4 Ô+Ü ¤§¡×!4Ñ!4¸$Ð!4Ó!?Ó@Ð@Ü$ T¨9Ó5ˆDŒNØˆŒ
Øˆ�r%   c                 ó   — | j                   S r'   )r=   )rI   s    r#   r,   zLemmatizer.mode]   s   € à�z‰zÐr%   Údocc                 óN  — | j                   s| j                  t        j                  «       | j	                  «       }	 |D ]7  }| j
                  s|j                  dk(  sŒ| j                  |«      d   |_        Œ9 |S # t        $ r } || j                  | |g|«       Y d}~yd}~ww xY w)z´Apply the lemmatizer to one document.

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

        DOCS: https://spacy.io/api/lemmatizer#call
        r   N)r?   Ú_validate_tablesr   ÚE1004Úget_error_handlerr6   r    rA   Úlemma_Ú	Exceptionr:   )rI   rM   Úerror_handlerÚtokenÚes        r#   Ú__call__zLemmatizer.__call__a   s”   € ð �ŠØ×!Ñ!¤&§,¡,Ô/Ø×.Ñ.Ó0ˆð	5Øò <�Ø—>’> U§[¡[°AÓ%5Ø#'§>¡>°%Ó#8¸Ñ#;�E•Lð<ð ˆJøÜò 	5Ù˜$Ÿ)™) T¨C¨5°!×4Ñ4ûð	5ús   ½ A; ÁA; Á;	B$ÂBÂB$)Únlpr>   Úget_examplesrX   r>   c                ó¤  — | j                  | j                  «      \  }}|€Št        j                  d«       t	        | j
                  j                  |¬«      }t	        | j
                  j                  |d¬«      }|j                  D ]#  }|j                  ||j                  |«      «       Œ% || _
        | j                  t        j                  «       y)aÑ  Initialize the lemmatizer and load in data.

        get_examples (Callable[[], Iterable[Example]]): Function that
            returns a representative sample of gold-standard Example objects.
        nlp (Language): The current nlp object the component is part of.
        lookups (Lookups): The lookups object containing the (optional) tables
            such as "lemma_rules", "lemma_index", "lemma_exc" and
            "lemma_lookup". Defaults to None.
        Nz2Lemmatizer: loading tables from spacy-lookups-data)ÚlangÚtablesF)r[   r\   Ústrict)r5   r,   r   Údebugr   r8   r[   r\   Ú	set_tableÚ	get_tabler>   rO   r   rP   )rI   rY   rX   r>   Úrequired_tablesÚoptional_tablesÚoptional_lookupsÚtables           r#   Ú
initializezLemmatizer.initializet   s«   € ð  ,0×+BÑ+BÀ4Ç9Á9Ó+MÑ(ˆ˜Øˆ?Ü�L‰LÐMÔNÜ"¨¯
©
¯©ÀÔPˆGÜ+Ø—Z‘Z—_‘_¨_ÀUô Ðð *×0Ñ0ò L�Ø×!Ñ! %Ð)9×)CÑ)CÀEÓ)JÕKðLàˆŒØ×ÑœfŸl™lÕ+r%   Úerror_messagec                 óî   — | j                  | j                  «      \  }}|D ]K  }|| j                  vsŒt        |j	                  | j                  || j                  j
                  ¬«      «      ‚ d| _        y)z8Check that the lookups are correct for the current mode.)r,   r\   ÚfoundTN)r5   r,   r>   rD   rF   r\   r?   )rI   rf   ra   rb   rd   s        r#   rO   zLemmatizer._validate_tables�   sv   € à+/×+BÑ+BÀ4Ç9Á9Ó+MÑ(ˆ˜Ø$ò 	ˆEØ˜DŸL™LÒ(Ü Ø!×(Ñ(Ø!ŸY™YØ.Ø"Ÿl™l×1Ñ1ð )ó óð ð	ð ˆ�r%   rU   c                 ó°   — | j                   j                  di «      }|j                  |j                  |j                  «      }t	        |t
        «      r|g}|S )zÞLemmatize using a lookup-based approach.

        token (Token): The token to lemmatize.
        RETURNS (list): The available lemmas for the string.

        DOCS: https://spacy.io/api/lemmatizer#lookup_lemmatize
        r/   )r>   r`   ÚgetÚtextÚ
isinstanceÚstr)rI   rU   Úlookup_tableÚresults       r#   r@   zLemmatizer.lookup_lemmatizež   sJ   € ð —|‘|×-Ñ-¨n¸bÓAˆØ×!Ñ! %§*¡*¨e¯j©jÓ9ˆÜ�fœcÔ"Ø�XˆFØˆr%   c                 ó¢  — |j                   |j                  |j                  j                  f}|| j                  v r| j                  |   S |j
                  }|j                  j                  «       }|dv r9|dk(  r#t        j                  t        j                  «       |j                  «       gS | j                  |«      r|j                  «       gS | j                  j                  di «      }| j                  j                  di «      }| j                  j                  di «      }t        |j!                  |«      |j!                  |«      |j!                  |«      f«      s|dk(  r|gS |j                  «       gS |j!                  |i «      }|j!                  |i «      }	|j!                  |i «      }
|}|j                  «       }g }g }|
D ]…  \  }}|j#                  |«      sŒ|dt%        |«      t%        |«      z
   |z   }|sŒ8||v s|j'                  «       s)||v r|j)                  d|«       Œc|j+                  |«       Œu|j+                  |«       Œ‡ t-        t.        j1                  |«      «      }|	j!                  |g «      D ]  }||vsŒ|j)                  d|«       Œ |s|j3                  |«       |s|j+                  |«       || j                  |<   |S )	zÚLemmatize using a rule-based approach.

        token (Token): The token to lemmatize.
        RETURNS (list): The available lemmas for the string.

        DOCS: https://spacy.io/api/lemmatizer#rule_lemmatize
        )Ú ÚeolÚspacerq   r3   r2   r1   ÚpropnNr   )ÚorthÚposÚmorphÚkeyrH   rk   Úpos_ÚlowerÚwarningsÚwarnr   ÚW108Úis_base_formr>   r`   Úanyrj   ÚendswithÚlenÚisalphaÚinsertÚappendÚlistÚdictÚfromkeysÚextend)rI   rU   Ú	cache_keyÚstringÚuniv_posÚindex_tableÚ	exc_tableÚrules_tableÚindexÚ
exceptionsÚrulesÚorigÚformsÚ	oov_formsÚoldÚnewÚforms                    r#   rB   zLemmatizer.rule_lemmatize¬   s{  € ð —Z‘Z §¡¨E¯K©K¯O©OÐ<ˆ	Ø˜Ÿ
™
Ñ"Ø—:‘:˜iÑ(Ð(Ø—‘ˆØ—:‘:×#Ñ#Ó%ˆØÐ+Ñ+Ø˜2Š~Ü—‘œhŸm™mÔ,Ø—L‘L“NÐ#Ð#à×Ñ˜UÔ#Ø—L‘L“NÐ#Ð#Ø—l‘l×,Ñ,¨]¸BÓ?ˆØ—L‘L×*Ñ*¨;¸Ó;ˆ	Ø—l‘l×,Ñ,¨]¸BÓ?ˆÜà—‘ Ó)Ø—‘˜hÓ'Ø—‘ Ó)ðô
ð ˜7Ò"Ø�x�àŸ™›Ð'Ð'à—‘ ¨"Ó-ˆØ—]‘] 8¨RÓ0ˆ
Ø—‘ ¨"Ó-ˆØˆØ—‘“ˆØˆØˆ	Øò 	+‰HˆC�Ø�‰˜sÕ#ØÐ6¤ F£¬c°#«hÑ 6Ð7¸#Ñ=�ÙØØ˜U‘]¨$¯,©,¬.Ø˜u‘}ØŸ™ Q¨Õ-àŸ™ TÕ*à×$Ñ$ TÕ*ð	+ô ”T—]‘] 5Ó)Ó*ˆð
 —N‘N 6¨2Ó.ò 	&ˆDØ˜5Ò Ø—‘˜Q Õ%ð	&ñ Ø�L‰L˜Ô#ÙØ�L‰L˜ÔØ %ˆ�
‰
�9ÑØˆr%   c                  ó   — y)a  Check whether the token is a base form that does not need further
        analysis for lemmatization.

        token (Token): The token.
        RETURNS (bool): Whether the token is a base form.

        DOCS: https://spacy.io/api/lemmatizer#is_base_form
        Fr(   )rI   rU   s     r#   r~   zLemmatizer.is_base_formò   s   € ð r%   ©ÚexcludeÚpathrš   c                ó\   ‡ ‡— i }ˆˆ fd„|d<   ˆ fd„|d<   t        j                  ||‰«       y)zÞSerialize the pipe to disk.

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

        DOCS: https://spacy.io/api/lemmatizer#to_disk
        c                 ó>   •— ‰j                   j                  | ‰¬«      S ©Nr™   )r8   Úto_disk©Úprš   rI   s    €€r#   ú<lambda>z$Lemmatizer.to_disk.<locals>.<lambda>  s   ø€  t§z¡z×'9Ñ'9¸!ÀWÐ'9Ó'M€ r%   r8   c                 ó:   •— ‰j                   j                  | «      S r'   )r>   rŸ   ©r¡   rI   s    €r#   r¢   z$Lemmatizer.to_disk.<locals>.<lambda>	  s   ø€ ¨¯©×)=Ñ)=¸aÓ)@€ r%   r>   N)r   rŸ   )rI   r›   rš   Ú	serializes   ` ` r#   rŸ   zLemmatizer.to_diský   s.   ù€ ð ˆ	ÜMˆ	�'ÑÛ@ˆ	�)ÑÜ�‰�T˜9 gÕ.r%   c                ó~   ‡ ‡— i }ˆˆ fd„|d<   ˆ fd„|d<   t        j                  ||‰«       ‰ j                  «        ‰ S )aH  Load the pipe from disk. Modifies the object in place and returns it.

        path (str / Path): Path to a directory.
        exclude (Iterable[str]): String names of serialization fields to exclude.
        RETURNS (Lemmatizer): The modified Lemmatizer object.

        DOCS: https://spacy.io/api/lemmatizer#from_disk
        c                 ó>   •— ‰j                   j                  | ‰¬«      S rž   )r8   Ú	from_diskr    s    €€r#   r¢   z&Lemmatizer.from_disk.<locals>.<lambda>  s   ø€ ¨¯©×)=Ñ)=¸aÈÐ)=Ó)Q€ r%   r8   c                 ó:   •— ‰j                   j                  | «      S r'   )r>   r¨   r¤   s    €r#   r¢   z&Lemmatizer.from_disk.<locals>.<lambda>  s   ø€ ¨4¯<©<×+AÑ+AÀ!Ó+D€ r%   r>   )r   r¨   rO   )rI   r›   rš   Údeserializes   ` ` r#   r¨   zLemmatizer.from_disk  s?   ù€ ð 8:ˆÜQˆ�GÑÛ!Dˆ�IÑÜ�‰�t˜[¨'Ô2Ø×ÑÔØˆr%   c                óz   ‡ ‡— i }ˆˆ fd„|d<   ‰ j                   j                  |d<   t        j                  |‰«      S )zçSerialize the pipe to a bytestring.

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

        DOCS: https://spacy.io/api/lemmatizer#to_bytes
        c                  ó<   •— ‰j                   j                  ‰ ¬«      S rž   )r8   Úto_bytes)rš   rI   s   €€r#   r¢   z%Lemmatizer.to_bytes.<locals>.<lambda>'  s   ø€  T§Z¡Z×%8Ñ%8ÀÐ%8Ó%I€ r%   r8   r>   )r>   r­   r   )rI   rš   r¥   s   `` r#   r­   zLemmatizer.to_bytes  s9   ù€ ð ˆ	ÜIˆ	�'ÑØ#Ÿ|™|×4Ñ4ˆ	�)ÑÜ�}‰}˜Y¨Ó0Ð0r%   Ú
bytes_datac                ó~   ‡ ‡— i }ˆˆ fd„|d<   ˆ fd„|d<   t        j                  ||‰«       ‰ j                  «        ‰ S )a  Load the pipe from a bytestring.

        bytes_data (bytes): The serialized pipe.
        exclude (Iterable[str]): String names of serialization fields to exclude.
        RETURNS (Lemmatizer): The loaded Lemmatizer.

        DOCS: https://spacy.io/api/lemmatizer#from_bytes
        c                 ó>   •— ‰j                   j                  | ‰¬«      S rž   )r8   Ú
from_bytes)Úbrš   rI   s    €€r#   r¢   z'Lemmatizer.from_bytes.<locals>.<lambda>7  s   ø€ ¨¯©×)>Ñ)>¸qÈ'Ð)>Ó)R€ r%   r8   c                 ó:   •— ‰j                   j                  | «      S r'   )r>   r±   )r²   rI   s    €r#   r¢   z'Lemmatizer.from_bytes.<locals>.<lambda>8  s   ø€ ¨4¯<©<×+BÑ+BÀ1Ó+E€ r%   r>   )r   r±   rO   )rI   r®   rš   rª   s   ` ` r#   r±   zLemmatizer.from_bytes+  s?   ù€ ð 8:ˆÜRˆ�GÑÛ!Eˆ�IÑÜ�‰˜
 K°Ô9Ø×ÑÔØˆr%   )Ú
lemmatizerr'   )(Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodrm   r
   r   r5   r$   r   r	   r   Úboolr   rK   Úpropertyr,   r   rW   r   r   r   r   re   r   ÚE912rO   r   r@   rB   r~   r   r   r   rŸ   r¨   Úbytesr­   r±   r(   r%   r#   r+   r+      s(  „ ñð ð cð ¨e°D¸±I¸tÀC¹yÐ4HÑ.Iò ó ðð$ !ð	(ð ØØ%5ò(àð(ð ˜‰ð(ð ð	(ð ð(ð ð(ð ˜Ñ"ð(ð 
ó(ðT ñó ðð5˜Cð 5 Có 5ð* CGð,ð #'Ø%)ò,à˜x¨¨H°WÑ,=Ð(=Ñ>Ñ?ð,ð �hÑð	,ð
 ˜'Ñ"ó,ð8 5;·K±Kñ ¨cð ÀDó ð eð °°S±	ó ðD Eð D¨d°3©ió DðL	 %ð 	¨Dó 	ñ CSÓBTò/Ø˜#˜t˜)Ñ$ð/Ø2:¸3±-ó/ñ  CSÓBTòØ˜#˜t˜)Ñ$ðØ2:¸3±-ðà	óñ$ 4DÓ3Eò 1 8¨C¡=ð 1È%ó 1ñ >NÓ=OòØðØ-5°c©]ðà	ôr%   r+   c                 óx   — | dk(  r!t        j                  d«      }|j                  S t        dt        › d| › �«      ‚)NÚmake_lemmatizerz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%   )+rÀ   r{   Úpathlibr   Útypingr   r   r   r   r   r	   r
   r   Ú	thinc.apir   rq   r   Úerrorsr   r   Úlanguager   r>   r   r   r7   r   Útokensr   r   Útrainingr   r   r   r8   r   Úpiper   rm   r$   r)   r+   rÄ   r(   r%   r#   ú<module>rÍ      su   ðÛ Û Ý ß N× NÓ Nå å ß %Ý ß +Ý ß Ý ß +Ý Ý ð@˜x¨Ñ0ð @¸tÀCÈÀH¹~ó @òô_�ô _óF	Gr%   