Ë
    `›¾jO  ã                   ó8  — d dl Z d dlZd dlm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mZ d dl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dlmZmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z& ddl'm(Z( dZ)e	e*ee*ee	e*ef      f   f   Z+d„ Z,d„ Z- G d„ de(«      Z.d„ Z/y)é    N)Údefaultdict)ÚPath)	ÚAnyÚCallableÚDictÚIterableÚListÚOptionalÚSequenceÚTupleÚUnioné   )ÚErrorsÚWarnings)ÚLanguage)ÚMatcherÚPhraseMatcher)Úlevenshtein_compare©Úget_ner_prf)ÚDocÚSpan)ÚExample)ÚSimpleFrozenListÚensure_pathÚ	from_diskÚto_diské   )ÚPipez||c                 ó   — t        | «      S ©Nr   )ÚexamplesÚkwargss     úd/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/spacy/pipeline/entityruler.pyÚentity_ruler_scorer%      s   € Ü�xÓ Ð ó    c                  ó   — t         S r!   )r%   © r&   r$   Úmake_entity_ruler_scorerr)      s   € ÜÐr&   c                   óx  — e Zd ZdZ	 d-deddededœdedede	e
eef      ded	ed
edede	ee      de	e   ddfd„Zdefd„Zdedefd„Zdedefd„Zdefd„Zd„ Zedeedf   fd„«       Zdddœdeg ee   f   de	e   de	ee      fd„Zedee	e   df   fd„«       Zedee   fd„«       Zdee   ddfd„Z d.d„Z!d eddfd!„Z"d.d"„Z#dedeee	e   f   fd#„Z$de%d e%defd$„Z& e'«       d%œd&e(d'ee   dd fd(„Z) e'«       d%œd'ee   de(fd)„Z* e'«       d%œd*e
ee+f   d'ee   dd fd+„Z, e'«       d%œd*e
ee+f   d'ee   ddfd,„Z-y)/ÚEntityRuleraâ  The EntityRuler lets you add spans to the `Doc.ents` using token-based
    rules or exact phrase matches. It can be combined with the statistical
    `EntityRecognizer` to boost accuracy, or used on its own to implement a
    purely rule-based entity recognition system. After initialization, the
    component is typically added to the pipeline using `nlp.add_pipe`.

    DOCS: https://spacy.io/api/entityruler
    USAGE: https://spacy.io/usage/rule-based-matching#entityruler
    NF)Úphrase_matcher_attrÚmatcher_fuzzy_compareÚvalidateÚoverwrite_entsÚ
ent_id_sepÚpatternsÚscorerÚnlpÚnamer,   r-   r.   r/   r0   r1   r2   Úreturnc                ó®  — || _         || _        || _        t        t        «      | _        t        t        «      | _        || _        || _        t        |j                  || j                  ¬«      | _        || _        t        |j                  | j                  |¬«      | _        || _        t        t         «      | _        |�| j%                  |«       |	| _        y)a#  Initialize the entity ruler. If patterns are supplied here, they
        need to be a list of dictionaries with a `"label"` and `"pattern"`
        key. A pattern can either be a token pattern (list) or a phrase pattern
        (string). For example: `{'label': 'ORG', 'pattern': 'Apple'}`.

        nlp (Language): The shared nlp object to pass the vocab to the matchers
            and process phrase patterns.
        name (str): Instance name of the current pipeline component. Typically
            passed in automatically from the factory when the component is
            added. Used to disable the current entity ruler while creating
            phrase patterns with the nlp object.
        phrase_matcher_attr (int / str): Token attribute to match on, passed
            to the internal PhraseMatcher as `attr`.
        matcher_fuzzy_compare (Callable): The fuzzy comparison method for the
            internal Matcher. Defaults to
            spacy.matcher.levenshtein.levenshtein_compare.
        validate (bool): Whether patterns should be validated, passed to
            Matcher and PhraseMatcher as `validate`
        patterns (iterable): Optional patterns to load in.
        overwrite_ents (bool): If existing entities are present, e.g. entities
            added by the model, overwrite them by matches if necessary.
        ent_id_sep (str): Separator used internally for entity IDs.
        scorer (Optional[Callable]): The scoring method. Defaults to
            spacy.scorer.get_ner_prf.

        DOCS: https://spacy.io/api/entityruler#init
        ©r.   Úfuzzy_compare©Úattrr.   N)r3   r4   Ú	overwriter   ÚlistÚtoken_patternsÚphrase_patternsÚ	_validater-   r   ÚvocabÚmatcherr,   r   Úphrase_matcherr0   ÚtupleÚ_ent_idsÚadd_patternsr2   )
Úselfr3   r4   r,   r-   r.   r/   r0   r1   r2   s
             r$   Ú__init__zEntityRuler.__init__*   s¸   € ðP ˆŒØˆŒ	Ø'ˆŒÜ)¬$Ó/ˆÔÜ*¬4Ó0ˆÔØ!ˆŒØ%:ˆÔ"ÜØ�I‰I ¸×8RÑ8Rô
ˆŒð $7ˆÔ Ü+Ø�I‰I˜D×4Ñ4¸xô
ˆÔð %ˆŒÜ#¤EÓ*ˆŒØÐØ×Ñ˜hÔ'Øˆ�r&   c                 ó´   — t        d„ | j                  j                  «       D «       «      }t        d„ | j                  j                  «       D «       «      }||z   S )z5The number of all patterns added to the entity ruler.c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr!   ©Úlen©Ú.0Úps     r$   ú	<genexpr>z&EntityRuler.__len__.<locals>.<genexpr>h   s   è ø€ ÒL¨!œs 1ŸvÑLùó   ‚c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr!   rJ   rL   s     r$   rO   z&EntityRuler.__len__.<locals>.<genexpr>i   s   è ø€ ÒN¨1¤ A§ÑNùrP   )Úsumr=   Úvaluesr>   )rF   Ún_token_patternsÚn_phrase_patternss      r$   Ú__len__zEntityRuler.__len__f   sN   € äÑL¨t×/BÑ/B×/IÑ/IÓ/KÔLÓLÐÜÑN°×0DÑ0D×0KÑ0KÓ0MÔNÓNÐØÐ"3Ñ3Ð3r&   Úlabelc                 ó>   — || j                   v xs || j                  v S )z+Whether a label is present in the patterns.)r=   r>   )rF   rW   s     r$   Ú__contains__zEntityRuler.__contains__l   s#   € à˜×+Ñ+Ð+ÒL¨u¸×8LÑ8LÐ/LÐLr&   Údocc                 óÆ   — | j                  «       }	 | j                  |«      }| j                  ||«       |S # t        $ r } || j                  | |g|«      cY d}~S d}~ww xY w)zæFind matches in document and add them as entities.

        doc (Doc): The Doc object in the pipeline.
        RETURNS (Doc): The Doc with added entities, if available.

        DOCS: https://spacy.io/api/entityruler#call
        N)Úget_error_handlerÚmatchÚset_annotationsÚ	Exceptionr4   )rF   rZ   Úerror_handlerÚmatchesÚes        r$   Ú__call__zEntityRuler.__call__p   s`   € ð ×.Ñ.Ó0ˆð	<Ø—j‘j “oˆGØ× Ñ   gÔ.ØˆJøÜò 	<Ù  §¡¨D°3°%¸Ó;Õ;ûð	<ús   ’$7 ·	A Á AÁA ÁA c           
      ó”  — | j                  «        t        j                  «       5  t        j                  dd¬«       t	        | j                  |«      «      t	        | j                  |«      «      z   }d d d «       t        D ���cg c]  \  }}}||k7  sŒ|||f‘Œ c}}}«      }d„ }t        ||d¬«      }|S # 1 sw Y   ŒFxY wc c}}}w )NÚignorez\[W036)Úmessagec                 ó$   — | d   | d   z
  | d    fS )Nr   r   r(   )Úms    r$   ú<lambda>z#EntityRuler.match.<locals>.<lambda>‰   s   €  ! A¡$¨¨1©¡+°°!±¨uÐ!5€ r&   T)ÚkeyÚreverse)	Ú_require_patternsÚwarningsÚcatch_warningsÚfilterwarningsr<   rA   rB   ÚsetÚsorted)rF   rZ   ra   Úm_idÚstartÚendÚfinal_matchesÚget_sort_keys           r$   r]   zEntityRuler.match€   s¼   € Ø×ÑÔ Ü×$Ñ$Ó&ñ 	OÜ×#Ñ# H°iÕ@Ü˜4Ÿ<™<¨Ó,Ó-´°T×5HÑ5HÈÓ5MÓ0NÑNˆG÷	Oô Ø8?×PÐPÑ$4 D¨%°À5ÈCÃ<ˆd�E˜3ÒÔPó
ˆñ 6ˆÜ˜}°,ÈÔMˆØÐ÷	Oð 	Oüô
 Qs   ¥AB7ÂCÂCÂ7C c                 ó  — t        |j                  «      }g }t        «       }|D ]Ï  \  }}}t        d„ ||| D «       «      r| j                  sŒ)||vsŒ.|dz
  |vsŒ6|| j
                  v r#| j
                  |   \  }	}
t        ||||	|
¬«      }nt        ||||¬«      }|j                  |«       |D �cg c]#  }|j                  |k  r|j                  |kD  rŒ"|‘Œ% }}|j                  t        ||«      «       ŒÑ ||z   |_        yc c}w )zModify the document in placec              3   ó4   K  — | ]  }|j                   –— Œ y ­wr!   )Úent_type)rM   Úts     r$   rO   z.EntityRuler.set_annotations.<locals>.<genexpr>“   s   è ø€ Ò6 !�1—:•:Ñ6ùs   ‚r   )rW   Úspan_id)rW   N)r<   Úentsrp   Úanyr;   rD   r   Úappendrs   rt   ÚupdateÚrange)rF   rZ   ra   ÚentitiesÚnew_entitiesÚseen_tokensÚmatch_idrs   rt   rW   Úent_idÚspanrb   s                r$   r^   zEntityRuler.set_annotations�   s  € ä˜Ÿ™“>ˆØˆÜ“eˆØ$+ò 	6Ñ ˆH�e˜SÜÑ6 s¨5° ~Ô6Ô6¸t¿~º~Øà˜KÒ'¨C°!©G¸;Ò,FØ˜tŸ}™}Ñ,Ø$(§M¡M°(Ñ$;‘M�E˜6Ü  U¨C°uÀfÔM‘Dä  U¨C°xÔ@�DØ×#Ñ# DÔ)à'öØ°·±¸#²À!Ç%Á%È%Ã-’Að�ð ð ×"Ñ"¤5¨°Ó#4Õ5ð	6ð ˜lÑ*ˆ�ùò	s   Â/#DÃD.c                 ón  — t        | j                  j                  «       «      }|j                  | j                  j                  «       «       t        «       }|D ]G  }| j
                  |v r&| j                  |«      \  }}|j                  |«       Œ7|j                  |«       ŒI t        t        |«      «      S )z”All labels present in the match patterns.

        RETURNS (set): The string labels.

        DOCS: https://spacy.io/api/entityruler#labels
        )
rp   r=   Úkeysr   r>   r0   Ú_split_labelÚaddrC   rq   )rF   rˆ   Ú
all_labelsÚlrW   Ú_s         r$   ÚlabelszEntityRuler.labels£   s˜   € ô �4×&Ñ&×+Ñ+Ó-Ó.ˆØ�‰�D×(Ñ(×-Ñ-Ó/Ô0Ü“Uˆ
àò 	"ˆAØ�‰ !Ñ#Ø×,Ñ,¨QÓ/‘��qØ—‘˜uÕ%à—‘˜qÕ!ð	"ô ”V˜JÓ'Ó(Ð(r&   )r3   r1   Úget_examplesc                óL   — | j                  «        |r| j                  |«       yy)a‹  Initialize the pipe for training.

        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.
        patterns Optional[Iterable[PatternType]]: The list of patterns.

        DOCS: https://spacy.io/api/entityruler#initialize
        N)ÚclearrE   )rF   r�   r3   r1   s       r$   Ú
initializezEntityRuler.initialize·   s#   € ð  	�
‰
ŒÙØ×Ñ˜hÕ'ð r&   c                 ó:  — t        | j                  j                  «       «      }|j                  | j                  j                  «       «       t        «       }|D ]6  }| j
                  |v sŒ| j                  |«      \  }}|j                  |«       Œ8 t        |«      S )z¬All entity ids present in the match patterns `id` properties

        RETURNS (set): The string entity ids.

        DOCS: https://spacy.io/api/entityruler#ent_ids
        )	rp   r=   rˆ   r   r>   r0   r‰   rŠ   rC   )rF   rˆ   Úall_ent_idsrŒ   r�   r…   s         r$   Úent_idszEntityRuler.ent_idsË   s‡   € ô �4×&Ñ&×+Ñ+Ó-Ó.ˆØ�‰�D×(Ñ(×-Ñ-Ó/Ô0Ü“eˆàò 	(ˆAØ�‰ !Ò#Ø ×-Ñ-¨aÓ0‘	��6Ø—‘ Õ'ð	(ô �[Ó!Ð!r&   c                 ó†  — g }| j                   j                  «       D ]=  \  }}|D ]3  }| j                  |«      \  }}||dœ}|r||d<   |j                  |«       Œ5 Œ? | j                  j                  «       D ]G  \  }}|D ]=  }| j                  |«      \  }}||j
                  dœ}|r||d<   |j                  |«       Œ? ŒI |S )zÃGet all patterns that were added to the entity ruler.

        RETURNS (list): The original patterns, one dictionary per pattern.

        DOCS: https://spacy.io/api/entityruler#patterns
        ©rW   ÚpatternÚid)r=   Úitemsr‰   r~   r>   Útext)rF   Úall_patternsrW   r1   r˜   Ú	ent_labelr…   rN   s           r$   r1   zEntityRuler.patternsÝ   së   € ð ˆØ#×2Ñ2×8Ñ8Ó:ò 	'‰OˆE�8Ø#ò '�Ø$(×$5Ñ$5°eÓ$<Ñ!�	˜6Ø'°GÑ<�ÙØ$�A�d‘GØ×#Ñ# AÕ&ñ'ð	'ð  $×3Ñ3×9Ñ9Ó;ò 	'‰OˆE�8Ø#ò '�Ø$(×$5Ñ$5°eÓ$<Ñ!�	˜6Ø'°G·L±LÑA�ÙØ$�A�d‘GØ×#Ñ# AÕ&ñ'ð	'ð Ðr&   c                 óH  — 	 d}t        | j                  j                  «      D ]  \  }\  }}| |k(  sŒ|} n | j                  j                  |d D �cg c]  }|‘Œ }}| j                  j                  |¬«      5  g }g }g }	g }
|D ]ƒ  }t        |d   t        «      rI|j                  |d   «       |	j                  |d   «       |
j                  |j                  d«      «       Œ_t        |d   t        «      sŒs|j                  |«       Œ… g }t        || j                  j                  |	«      |
«      D ]#  \  }}}||dœ}|r||d<   |j                  |«       Œ% ||z   D �]  }|d   }d|v rF|}| j                  ||d   «      }| j                  j                  |«      }||d   f| j                   |<   |d   }t        |t"        «      r<| j$                  |   j                  |«       | j&                  j)                  ||g«       Œ¤t        |t        «      r<| j*                  |   j                  |«       | j                  j)                  ||g«       Œðt	        t,        j.                  j1                  |¬«      «      ‚ 	 ddd«       yc c}w # t        $ r g }Y �Œ7w xY w# 1 sw Y   yxY w)	a~  Add patterns to the entity ruler. A pattern can either be a token
        pattern (list of dicts) or a phrase pattern (string). For example:
        {'label': 'ORG', 'pattern': 'Apple'}
        {'label': 'GPE', 'pattern': [{'lower': 'san'}, {'lower': 'francisco'}]}

        patterns (list): The patterns to add.

        DOCS: https://spacy.io/api/entityruler#add_patterns
        éÿÿÿÿN)Údisabler˜   rW   r™   r—   )r˜   )Ú	enumerater3   ÚpipelineÚ
pipe_namesÚ
ValueErrorÚselect_pipesÚ
isinstanceÚstrr~   Úgetr<   ÚzipÚpipeÚ_create_labelrA   Ú_normalize_keyrD   r   r>   rB   rŠ   r=   r   ÚE097Úformat)rF   r1   Úcurrent_indexÚir4   rª   Úsubsequent_pipesr=   Úphrase_pattern_labelsÚphrase_pattern_textsÚphrase_pattern_idsÚentryr>   rW   r˜   r…   Úphrase_patternr�   rj   s                      r$   rE   zEntityRuler.add_patternsö   s°  € ð	"ØˆMÜ#,¨T¯X©X×->Ñ->Ó#?ò ‘�‘<�D˜$Ø˜4“<Ø$%�MÙðð 26·±×1DÑ1DÀ]À^Ð1TÖU¨¢ÐUÐÐUð �X‰X×"Ñ"Ð+;Ð"Ó<ñ %	JØˆNØ$&Ð!Ø#%Ð Ø!#ÐØ!ò 1�Ü˜e IÑ.´Ô4Ø)×0Ñ0°°w±Ô@Ø(×/Ñ/°°iÑ0@ÔAØ&×-Ñ-¨e¯i©i¸«oÕ>Ü  iÑ 0´$Õ7Ø"×)Ñ)¨%Õ0ð1ð !ˆOÜ*-Ø%Ø—‘—‘Ð2Ó3Ø"ó+ò 7Ñ&��w ð
 ,1¸WÑ!E�ÙØ+1�N 4Ñ(Ø×&Ñ& ~Õ6ð7ð (¨/Ñ9ó J�Ø˜g™�Ø˜5‘=Ø %�IØ ×.Ñ.¨u°e¸D±kÓB�EØŸ,™,×5Ñ5°eÓ<�CØ*3°U¸4±[Ð)A�D—M‘M #Ñ&Ø 	Ñ*�Ü˜g¤sÔ+Ø×(Ñ(¨Ñ/×6Ñ6°wÔ?Ø×'Ñ'×+Ñ+¨E°G°9Õ=Ü ¬Ô.Ø×'Ñ'¨Ñ.×5Ñ5°gÔ>Ø—L‘L×$Ñ$ U¨W¨IÕ6ä$¤V§[¡[×%7Ñ%7ÀÐ%7Ó%HÓIÐIñJ÷-%	Jð %	Jùò  VøÜò 	"Ø!Óð	"ú÷%	Jð %	Jús<   ‚/J ² J Á	JÁJ Á9A=JÃ7F JÊJ ÊJÊJÊJ!c                 óh  — t        t        «      | _        t        t        «      | _        t        t        «      | _        t        | j                  j                  | j                  | j                  ¬«      | _        t        | j                  j                  | j                  | j                  ¬«      | _        y)zReset all patterns.r7   r9   N)r   r<   r=   r>   rC   rD   r   r3   r@   r?   r-   rA   r   r,   rB   ©rF   s    r$   r‘   zEntityRuler.clear2  sw   € ä)¬$Ó/ˆÔÜ*¬4Ó0ˆÔÜ#¤EÓ*ˆŒÜØ�H‰H�N‰NØ—^‘^Ø×4Ñ4ô
ˆŒô
 ,Ø�H‰H�N‰N ×!9Ñ!9ÀDÇNÁNô
ˆÕr&   r…   c           	      óþ  — | j                   j                  «       D ��cg c]  \  }}||k(  sŒ||f‘Œ }}}|s5t        t        j                  j                  d|| j                  ¬«      «      ‚|D ��cg c]  \  }}| j                  ||«      ‘Œ }}}t        t        | j                  j                  «       D ��ci c]  \  }}||vr||“Œ c}}«      | _
        t        t        | j                  j                  «       D ��ci c]  \  }}||vr||“Œ c}}«      | _        |D ]G  }|| j                  v r| j                  j                  |«       Œ-| j                  j                  |«       ŒI yc c}}w c c}}w c c}}w c c}}w )zÙRemove a pattern by its ent_id if a pattern with this ent_id was added before

        ent_id (str): id of the pattern to be removed
        RETURNS: None
        DOCS: https://spacy.io/api/entityruler#remove
        ÚID)Ú	attr_typerW   Ú	componentN)rD   rS   r¤   r   ÚE1024r®   r4   r«   r   r<   r>   rš   r=   rB   ÚremoverA   )rF   r…   rW   ÚeidÚlabel_id_pairsÚcreated_labelsÚvals          r$   r¾   zEntityRuler.remove@  s‚  € ð .2¯]©]×-AÑ-AÓ-C÷
Ù)˜e SÀsÈfÃ}ˆU�CŠLð
ˆñ 
ñ ÜÜ—‘×#Ñ#¨d¸&ÈDÏIÉIÐ#ÓVóð ð @N÷
Ù/;°°sˆD×Ñ˜u cÕ*ð
ˆñ 
ô  +Üð %)×$8Ñ$8×$>Ñ$>Ó$@÷á �U˜CØ Ñ.ð �s‘
óó 
ˆÔô *Üð %)×$7Ñ$7×$=Ñ$=Ó$?÷á �U˜CØ Ñ.ð �s‘
óó
ˆÔð $ò 	+ˆEØ˜×+Ñ+Ñ+Ø×#Ñ#×*Ñ*¨5Õ1à—‘×#Ñ# EÕ*ñ		+ùó;
ùó
ùóùós   žE'¬E'Á1E-Â7E3Ã<E9c                 óœ   — t        | «      dk(  r>t        j                  t        j                  j                  | j                  ¬«      «       yy)z:Raise a warning if this component has no patterns defined.r   )r4   N)rK   rm   Úwarnr   ÚW036r®   r4   r¸   s    r$   rl   zEntityRuler._require_patternsj  s4   € äˆt‹9˜Š>Ü�M‰Mœ(Ÿ-™-×.Ñ.°D·I±IÐ.Ó>Õ?ð r&   c                 ót   — | j                   |v r#|j                  | j                   d«      \  }}||fS |}d}||fS )z»Split Entity label into ent_label and ent_id if it contains self.ent_id_sep

        label (str): The value of label in a pattern entry
        RETURNS (tuple): ent_label, ent_id
        r   N)r0   Úrsplit)rF   rW   r�   r…   s       r$   r‰   zEntityRuler._split_labelo  sM   € ð �?‰?˜eÑ#Ø %§¡¨T¯_©_¸aÓ @ÑˆI�vð ˜&Ð Ð ð ˆIØˆFØ˜&Ð Ð r&   c                 óJ   — t        |t        «      r|› | j                  › |› �}|S )a*  Join Entity label with ent_id if the pattern has an `id` attribute
        If ent_id is not a string, the label is returned as is.

        label (str): The label to set for ent.label_
        ent_id (str): The label
        RETURNS (str): The ent_label joined with configured `ent_id_sep`
        )r¦   r§   r0   )rF   rW   r…   s      r$   r«   zEntityRuler._create_label|  s*   € ô �fœcÔ"Ø�g˜dŸo™oÐ.¨v¨hÐ7ˆEØˆr&   )ÚexcludeÚpatterns_bytesrÉ   c                óÊ  — t        j                  |«      }| j                  «        t        |t        «      rœ| j                  |j                  d|«      «       |j                  dd«      | _        |j                  dd«      | _        t        | j                  j                  | j                  ¬«      | _        |j                  dt        «      | _        | S | j                  |«       | S )zÝLoad the entity ruler from a bytestring.

        patterns_bytes (bytes): The bytestring to load.
        RETURNS (EntityRuler): The loaded entity ruler.

        DOCS: https://spacy.io/api/entityruler#from_bytes
        r1   r;   Fr,   N©r:   r0   )ÚsrslyÚmsgpack_loadsr‘   r¦   ÚdictrE   r¨   r;   r,   r   r3   r@   rB   ÚDEFAULT_ENT_ID_SEPr0   )rF   rÊ   rÉ   Úcfgs       r$   Ú
from_byteszEntityRuler.from_bytesˆ  s¸   € ô ×!Ñ! .Ó1ˆØ�
‰
ŒÜ�cœ4Ô Ø×Ñ˜cŸg™g j°#Ó6Ô7Ø ŸW™W [°%Ó8ˆDŒNØ'*§w¡wÐ/DÀdÓ'KˆDÔ$Ü"/Ø—‘—‘Ø×-Ñ-ô#ˆDÔð "Ÿg™g lÔ4FÓGˆDŒOð ˆð ×Ñ˜cÔ"Øˆr&   c                óŠ   — | j                   | j                  | j                  | j                  dœ}t	        j
                  |«      S )z©Serialize the entity ruler patterns to a bytestring.

        RETURNS (bytes): The serialized patterns.

        DOCS: https://spacy.io/api/entityruler#to_bytes
        )r;   r0   r,   r1   )r;   r0   r,   r1   rÍ   Úmsgpack_dumps)rF   rÉ   Úserials      r$   Úto_byteszEntityRuler.to_bytes¡  s<   € ð Ÿ™ØŸ/™/Ø#'×#;Ñ#;ØŸ™ñ	
ˆô ×"Ñ" 6Ó*Ð*r&   Úpathc                ó`  ‡ ‡— t        |«      }‰ j                  «        |j                  d«      }|j                  dk(  r]|j                  r(t        j                  |«      }‰ j                  |«       ‰ S t        t        j                  j                  |¬«      «      ‚|j	                  «       r(t        j                  |«      }‰ j                  |«       ‰ S |j                  «       r¤i Šdˆ fd„i}dˆfd„i}t        ||i «       ‰j                  dd«      ‰ _        ‰j                  d	«      ‰ _        ‰j                  d
t"        «      ‰ _        t'        ‰ j(                  j*                  ‰ j                   ¬«      ‰ _        t        ||i «       ‰ S t        t        j.                  j                  |¬«      «      ‚)a+  Load the entity ruler from a file. Expects a file containing
        newline-delimited JSON (JSONL) with one entry per line.

        path (str / Path): The JSONL file to load.
        RETURNS (EntityRuler): The loaded entity ruler.

        DOCS: https://spacy.io/api/entityruler#from_disk
        ú.jsonl)r×   r1   c                 ój   •— ‰j                  t        j                  | j                  d«      «      «      S ©NrÙ   )rE   rÍ   Ú
read_jsonlÚwith_suffix©rN   rF   s    €r$   ri   z'EntityRuler.from_disk.<locals>.<lambda>Ê  s)   ø€  d×&7Ñ&7Ü×$Ñ$ Q§]¡]°8Ó%<Ó=ó'€ r&   rÑ   c                 óL   •— ‰j                  t        j                  | «      «      S r!   )r   rÍ   Ú	read_json©rN   rÑ   s    €r$   ri   z'EntityRuler.from_disk.<locals>.<lambda>Î  s   ø€ °#·*±*¼U¿_¹_ÈQÓ=OÓ2P€ r&   r;   Fr,   r0   rÌ   )r   r‘   rÝ   ÚsuffixÚis_filerÍ   rÜ   rE   r¤   r   ÚE1023r®   Úis_dirr   r¨   r;   r,   rÐ   r0   r   r3   r@   rB   ÚE146)rF   r×   rÉ   Údepr_patterns_pathr1   Údeserializers_patternsÚdeserializers_cfgrÑ   s   `      @r$   r   zEntityRuler.from_disk°  sy  ù€ ô ˜4Ó ˆØ�
‰
ŒØ!×-Ñ-¨hÓ7ÐØ�;‰;˜(Ò"Ø�|Š|Ü ×+Ñ+¨DÓ1�Ø×!Ñ! (Ô+ð2 ˆô/ !¤§¡×!4Ñ!4¸$Ð!4Ó!?Ó@Ð@Ø×'Ñ'Ô)Ü×'Ñ'Ð(:Ó;ˆHØ×Ñ˜hÔ'ð( ˆð' �[‰[Œ]ØˆCàó ð&Ð"ð
 "'Ó(PÐ QÐÜ�dÐ-¨rÔ2Ø ŸW™W [°%Ó8ˆDŒNØ'*§w¡wÐ/DÓ'EˆDÔ$Ø!Ÿg™g lÔ4FÓGˆDŒOä"/Ø—‘—‘ T×%=Ñ%=ô#ˆDÔô �dÐ2°BÔ7ð ˆô œVŸ[™[×/Ñ/°TÐ/Ó:Ó;Ð;r&   c                óö   ‡ ‡— t        |«      }‰ j                  ‰ j                  ‰ j                  dœŠˆ fd„ˆfd„dœ}|j                  dk(  r!t        j                  |‰ j                  «       yt        ||i «       y)zéSave the entity ruler patterns to a directory. The patterns will be
        saved as newline-delimited JSON (JSONL).

        path (str / Path): The JSONL file to save.

        DOCS: https://spacy.io/api/entityruler#to_disk
        )r;   r,   r0   c                 ób   •— t        j                  | j                  d«      ‰j                  «      S rÛ   )rÍ   Úwrite_jsonlrÝ   r1   rÞ   s    €r$   ri   z%EntityRuler.to_disk.<locals>.<lambda>í  s$   ø€ ¤%×"3Ñ"3Ø—‘˜hÓ'¨¯©ó#€ r&   c                 ó0   •— t        j                  | ‰«      S r!   )rÍ   Ú
write_jsonrá   s    €r$   ri   z%EntityRuler.to_disk.<locals>.<lambda>ð  s   ø€ œU×-Ñ-¨a°Ó5€ r&   )r1   rÑ   rÙ   N)	r   r;   r,   r0   râ   rÍ   rì   r1   r   )rF   r×   rÉ   ÚserializersrÑ   s   `   @r$   r   zEntityRuler.to_diskÜ  sl   ù€ ô ˜4Ó ˆàŸ™Ø#'×#;Ñ#;ØŸ/™/ñ
ˆóó 6ñ	
ˆð �;‰;˜(Ò"Ü×Ñ˜d D§M¡MÕ2ä�D˜+ rÕ*r&   )Úentity_ruler)r5   N).Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rÐ   r%   r   r§   r
   r   Úintr   Úboolr	   ÚPatternTyperG   rV   rY   r   rc   r]   r^   Úpropertyr   rŽ   r   r   r   r’   r•   r1   rE   r‘   r¾   rl   r‰   r   r«   r   ÚbytesrÒ   rÖ   r   r   r   r(   r&   r$   r+   r+      sÏ  „ ñð #ð:ð
 :>Ø*=ØØ$Ø,Ø04Ø%7ò:àð:ð ð:ð
 & e¨C°¨H¡oÑ6ð:ð  (ð:ð ð:ð ð:ð ð:ð ˜4 Ñ,Ñ-ð:ð ˜Ñ"ð:ð 
ó:ðx4˜ó 4ðM #ð M¨$ó Mð<˜Cð < Có <ð ˜ó ò+ð, ð)˜˜c 3˜h™ò )ó ð)ð. #'Ø48ò(à˜r 8¨GÑ#4Ð4Ñ5ð(ð �hÑð	(ð
 ˜8 KÑ0Ñ1ó(ð( ð"˜˜x¨™}¨cÐ1Ñ2ò "ó ð"ð" ð˜$˜{Ñ+ò ó ðð0:J T¨+Ñ%6ð :J¸4ó :Jóx
ð(+˜Sð (+ Tó (+óT@ð
! #ð !¨%°°X¸c±]Ð0BÑ*Có !ð
 3ð 
°ð 
¸ó 
ñ BRÓASòØ#ðØ19¸#±ðà	óñ2 4DÓ3Eò + 8¨C¡=ð +È%ó +ñ  CSÓBTò*Ø˜#˜t˜)Ñ$ð*Ø2:¸3±-ð*à	ó*ñZ CSÓBTò+Ø˜#˜t˜)Ñ$ð+Ø2:¸3±-ð+à	ô+r&   r+   c                 óx   — | dk(  r!t        j                  d«      }|j                  S t        dt        › d| › �«      ‚)NÚmake_entity_rulerzspacy.pipeline.factorieszmodule z has no attribute )Ú	importlibÚimport_modulerû   ÚAttributeErrorrñ   )r4   Úmodules     r$   Ú__getattr__r   ù  sA   € ØÐ"Ò"Ü×(Ñ(Ð)CÓDˆØ×'Ñ'Ð'Ü
˜7¤8 *Ð,>¸t¸fÐEÓ
FÐFr&   )0rü   rm   Úcollectionsr   Úpathlibr   Útypingr   r   r   r   r	   r
   r   r   r   rÍ   Úerrorsr   r   Úlanguager   rA   r   r   Úmatcher.levenshteinr   r2   r   Útokensr   r   Útrainingr   Úutilr   r   r   r   rª   r   rÐ   r§   r÷   r%   r)   r+   r   r(   r&   r$   ú<module>r
     s†   ðÛ Û Ý #Ý ß X× XÕ Xã ç %Ý ß ,Ý 5Ý  ß Ý ß DÓ DÝ àÐ Ø�3˜˜c 4¨¨S°#¨X©Ñ#7Ð7Ñ8Ð8Ñ9€ò!òôV+�$ô V+ótGr&   