
    i                        d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlZd dlZd dl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mZmZmZ  ej6                  d
       ej6                  d
d       edd       edddd       edddd      fdej8                  dedee   defd              Zd#dedee   deddfdZ dede	e   ddfdZ!d e
eef   d!edee   fd"Z"y)$    N)Path)IteratorOptionalSequenceUnion)Printermsg   )Language)
load_model   )NAMEArgOptapp	debug_cliprofileT)hidden.zTrained pipeline to load)helpz&Location of input file. '-' for stdin.)r   exists
allow_dash'  z	--n-textsz-nz+Maximum number of texts to use if availablectxmodelinputsn_textsc                     | j                   j                  j                  t        k(  rt	        j
                  d       t        |||       y)a\  
    Profile which functions take the most time in a spaCy pipeline.
    Input should be formatted as one JSON object per line with a key "text".
    It can either be provided as a JSONL file, or be read from sys.sytdin.
    If no input file is specified, the IMDB dataset is loaded via Thinc.

    DOCS: https://spacy.io/api/cli#debug-profile
    zThe profile command is now available via the 'debug profile' subcommand. You can run python -m spacy debug --help for an overview of the other available debugging commands.)r   r   N)parentcommandnamer   r	   warnr   )r   r   r   r   s       b/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/spacy/cli/profile.pyprofile_clir#      s<    2 zz$&B	

 E&'2    returnc                 .   |/t        |t              }t        t        j                  ||            }|]	 dd l}t        j                  d      5  j                  |d      \  }}t        | \  }}d d d        t        j                  d| d       t        j                  d	|  d
      5  t        |       }d d d        t        j                  d|  d       t        j                  dt!               t#               d       t%        j&                  d      }t        j(                  d       |j+                         j-                  d      j/                          y # t        $ r t        j                  dd       Y Aw xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nr   zwThis command, when run without an input file, requires the ml_datasets library to be installed: pip install ml_datasetsr   exitsz'Loading IMDB dataset via ml_datasets...)train_limit	dev_limitzLoaded IMDB dataset and using z	 exampleszLoading pipeline 'z'...zLoaded pipeline ''zparse_texts(nlp, texts)zProfile.profzProfile statstime)_read_inputsr	   list	itertoolsisliceml_datasetsImportErrorfailloadingimdbzipinfor   goodcProfilerunctxglobalslocalspstatsStatsdivider
strip_dirs
sort_statsprint_stats)	r   r   r   textsr1   
imdb_train_nlpss	            r"   r   r   4   s`   VS)Y%%eW56~	 [[BC 	(',,A,NMJJ'HE1	( 	1')DE	)%5	6   HH q)*OO-wy&(NS^$AKK LLNf%113%  	HH* 	 		( 	(   s)   E "E>*F E;:E;>FFrF   rC   c                 ^    | j                  t        j                  |d       d      D ]  } y )N)disable   )
batch_size)pipetqdm)rF   rC   docs      r"   parse_textsrO   P   s,    xx		%62xF r$   locr	   c              #     K   | dk(  r, |j                   d       t        j                  }d |D        }nrt        |       }|j	                         r|j                         s |j                  d| d        |j                   d|j                  d           |j                         }|D ]   }t        j                  |      }|d	   }| " y w)
N-zReading input from sys.stdinc              3   >   K   | ]  }|j                  d         yw)utf8N)encode).0lines     r"   	<genexpr>z_read_inputs.<locals>.<genexpr>Y   s     7V$7s   zNot a valid input data filer   r'   zUsing data from text)r7   sysstdinr   r   is_filer3   partsopensrsly
json_loads)rP   r	   file_
input_pathrW   datarZ   s          r"   r-   r-   U   s     
cz/0		77#Y
  "**<*<*>CHH2CqA#J$4$4R$8#9:;! %F|
s   C
C)Nr   )#r9   r/   r=   r[   pathlibr   typingr   r   r   r   r`   rM   typerwasabir   r	   languager   utilr   _utilr   r   r   r   r   r   Contextstrintr#   r   rO   r-    r$   r"   <module>rp      s7      
  6 6       1 1 9Yt$ S9: 5	 {D'T3	3 3 TN	3 3 % 3@43 4 4 4PT 48X hsm  
eD#I& W # r$   