Ë
    `›¾j  ã                   óZ  — d dl mZ d dlmZ d dlmZmZmZmZm	Z	 d dl
Z
d dl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mZmZmZmZmZ dZdZdZdZ dZ!eee"   ee   f   Z#dededee   fd„Z$dede"dee"   fd„Z%dee   dee"   fd„Z& ejN                  d«       edd¬«       eded¬«       eded¬ «       edd!d"e¬«       ed#d$d%d&¬«       edd'd(d)¬«       ed*d+d,d-¬«       ed
d.d/d0¬«       ed
d1d2d3¬«      f	d4e"d5ed6ed7ee   d8e"d9e(d:e)d;e)d<e)fd=„«       Z*d5ed6ed4e"d>e"d;e)d<e)fd?„Z+y)@é    )Úchain)ÚPath)ÚIterableÚListÚOptionalÚUnionÚcastN)Úmsgé   )ÚDocÚDocBin)Úensure_pathÚ
load_model)ÚVocabé   )ÚArgÚOptÚappÚimport_codeÚ	setup_gpuÚwalk_directorya•  Location of the documents to predict on.
Can be a single file in .spacy format or a .jsonl file.
Files with other extensions are treated as single plain text documents.
If a directory is provided it is traversed recursively to grab
all files to be processed.
The files can be a mixture of .spacy, .jsonl and text files.
If .jsonl is provided the specified field is going
to be grabbed ("text" by default).z&Path to save the resulting .spacy filezNPath to Python file with additional code (registered functions) to be importedz3Use gold preprocessing provided in the .spacy fileszjThe provided output file already exists. To force overwriting the output file, set the --force or -F flag.ÚpathÚvocabÚreturnc              #   ór   K  — t        «       j                  | «      }|j                  |«      D ]  }|–— Œ y­w)z)
    Stream Doc objects from DocBin.
    N)r   Ú	from_diskÚget_docs)r   r   ÚdocbinÚdocs       úY/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/spacy/cli/apply.pyÚ_stream_docbinr!   %   s7   è ø€ ô ‹X×Ñ Ó%€FØ�‰˜uÓ%ò ˆØ‹	ñùs   ‚57Úfieldc              #   ó’   K  — t        j                  | «      D ]+  }||vrt        j                  | › d|› d�d¬«       Œ%||   –— Œ- y­w)z_
    Stream "text" field from JSONL. If the field "text" is
    not found it raises error.
    z  does not contain the required 'z' field.r   ©ÚexitsN)ÚsrslyÚ
read_jsonlr
   Úfail)r   r"   Úentrys      r    Ú_stream_jsonlr*   .   sQ   è ø€ ô
 ×!Ñ! $Ó'ò ˆØ˜ÑÜ�H‰H˜�vÐ=¸e¸WÀHÐMÐUVÖWà˜‘,Óñ	ùs   ‚AAÚpathsc              #   ó„   K  — | D ]+  }t        |d«      5 }|j                  «       }|–— ddd«       Œ- y# 1 sw Y   Œ8xY w­w)z2
    Yields strings from text files in paths.
    ÚrN)ÚopenÚread)r+   r   ÚfinÚtexts       r    Ú_stream_textsr2   :   sK   è ø€ ð ò ˆÜ�$˜‹_ð 	 Ø—8‘8“:ˆDØŠJ÷	ð 	ñ÷	ð 	üs   ‚A ”4©A ´=	¹A Úapply.zModel name or path)ÚhelpT)r4   ÚexistsF)r4   Údir_okayz--codez-cr1   z
--text-keyz-tkz$Key containing text string for JSONLz--forcez-Fz!Force overwriting the output fileéÿÿÿÿz--gpu-idz-gzGPU ID or -1 for CPU.z--batch-sizez-bzBatch size.z--n-processz-nznumber of processors to use.ÚmodelÚ	data_pathÚoutput_fileÚ	code_pathÚtext_keyÚforce_overwriteÚuse_gpuÚ
batch_sizeÚ	n_processc	                 ó@  — t        |«      }t        |«      }t        |«      }|j                  «       r|st        j                  t        d¬«       |j                  «       st        j                  d|› �d¬«       t        |«       t        |«       t        ||| |||«       y)aÍ  
    Apply a trained pipeline to documents to get predictions.
    Expects a loadable spaCy pipeline and path to the data, which
    can be a directory or a file.
    The data files can be provided in multiple formats:
        1. .spacy files
        2. .jsonl files with a specified "field" to read the text from.
        3. Files with any other extension are assumed to be containing
           a single document.
    DOCS: https://spacy.io/api/cli#apply
    r   r$   zCouldn't find data path: N)r   r5   r
   r(   Ú	force_msgr   r   r3   )	r8   r9   r:   r;   r<   r=   r>   r?   r@   s	            r    Ú	apply_clirC   D   s‚   € ô8 ˜IÓ&€IÜ˜kÓ*€KÜ˜IÓ&€IØ×ÑÔ¡OÜ�‰” !Õ$Ø×ÑÔÜ�‰Ð,¨Y¨KÐ8ÀÕBÜ�	ÔÜˆgÔÜ	ˆ)�[ %¨°:¸yÕIó    Ú
json_fieldc                 óB  — t        d¬«      }t        | «      }t        |«      dk(  r+|j                  |«       t	        j
                  d| › d�«       y t        |«      }t	        j                  d|› �«       |j                  }	g }
g }|D ]i  }|j                  dk(  r|
j                  t        ||	«      «       Œ.|j                  dk(  r|
j                  t        ||«      «       ŒY|j                  |«       Œk t        |«      dkD  r|
j                  t        |«      «       t        t        t!        |
Ž «      }t#        j"                  |j%                  |||¬	«      d ¬
«      D ]  }|j'                  |«       Œ |j                  dk(  r|j)                  d«      }|j                  |«       y )NT)Ústore_user_datar   zDid not find data to process, z  seems to be an empty directory.zLoaded model z.spacyz.jsonl)r?   r@   )ÚdisableÚ )r   r   ÚlenÚto_diskr
   Úwarnr   Úgoodr   ÚsuffixÚappendr!   r*   r2   r	   ÚDocOrStrStreamr   ÚtqdmÚpipeÚaddÚwith_suffix)r9   r:   r8   rE   r?   r@   r   r+   Únlpr   ÚstreamsÚ
text_filesr   Údatagenr   s                  r    r3   r3   l   sl  € ô  DÔ)€FÜ˜9Ó%€EÜ
ˆ5ƒz�Q‚Ø�‰�{Ô#Ü�‰Ø,¨Y¨KÐ7WÐXô	
ð 	Ü
�UÓ
€CÜ‡H�Hˆ}˜U˜GÐ$Ô%Ø�I‰I€EØ$&€GØ€JØò $ˆØ�;‰;˜(Ò"Ø�N‰Nœ>¨$°Ó6Õ7Ø�[‰[˜HÒ$Ø�N‰Nœ=¨¨zÓ:Õ;à×Ñ˜dÕ#ð$ô ˆ:ƒ˜ÒØ�‰”} ZÓ0Ô1Ü”>¤5¨' ?Ó3€GÜ�y‰yØ�‰� Z¸9ˆÓEÈtôò ˆð 	�
‰
�3�ðð ×Ñ˜RÒØ!×-Ñ-¨hÓ7ˆØ
‡N�N�;ÕrD   ),Ú	itertoolsr   Úpathlibr   Útypingr   r   r   r   r	   r&   rQ   Úwasabir
   Útokensr   r   Úutilr   r   r   r   Ú_utilr   r   r   r   r   r   Ú	path_helpÚout_helpÚ	code_helpÚ	gold_helprB   ÚstrrP   r!   r*   r2   ÚcommandÚboolÚintrC   r3   © rD   r    ú<module>ri      s  ðÝ Ý ß 8Õ 8ã Û Ý ç  ß *Ý ß H× Hð&€	ð 4€àTð 
ð B€	ðHð 
ð �x ‘} h¨s¡mÐ3Ñ4€ð˜ð  eð °¸±ó ð	˜ð 	 Sð 	¨X°c©]ó 	ð˜ $™ð ¨H°S©Mó ð €‡�ˆWÓñ �SÐ3Ô4Ù˜# I°dÔ;Ù˜C h¸Ô?Ù # D¨(°D¸yÔ IÙØ�˜eÐ*Pôñ  Øˆy˜$Ð%Hôñ �r˜: tÐ2IÔJÙ˜!˜^¨T¸ÔFÙ˜˜M¨4Ð6TÔUñ$Jàð$Jð ð$Jð ð	$Jð
 ˜‰~ð$Jð ð$Jð ð$Jð ð$Jð ð$Jð ò$Jó ð$JðN% Øð% àð% ð ð% ð ð	% ð
 ð% ð ô% rD   