o
    
i
                     @   s^  d Z ddl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 eee
e
geee	eeef  gdf eg df f f Zg fdeeef dee deeee ef  fd	d
Zdeeef deeef fddZdeeef deeef fddZ	dde	ee  deegef fddZejejfddde
de
deeef fddZdS )z1
Configuration utilities copied from spacy.util.
    N)DictAnyTupleCallableIteratorListOptionalIO)Language)registrynodeparentreturnc                 c   sJ    |   D ]\}}g ||}t|trt||E dH  q||fV  qdS )z8Walk a dict and yield the path and values of the leaves.N)items
isinstancedict	walk_dict)r   r   keyvalue
key_parent r   F/home/ubuntu/.local/lib/python3.10/site-packages/spacy_loggers/util.pyr      s   
r   valuesc           	      C   sb   i }|   D ](\}}|}| d}t|D ]\}}|t|d k}|||r*|ni }qq|S )a  Convert dot notation to a dict. For example: {"token.pos": True,
    "token._.xyz": True} becomes {"token": {"pos": True, "_": {"xyz": True }}}.

    values (Dict[str, Any]): The key/value pairs to convert.
    RETURNS (Dict[str, dict]): The converted values.
    .   )r   lowersplit	enumeratelen
setdefault)	r   resultr   r   pathpartsiitemis_lastr   r   r   dot_to_dict   s   r&   objc                 C   s   dd t | D S )zConvert dot notation to a dict. For example: {"token": {"pos": True,
    "_": {"xyz": True }}} becomes {"token.pos": True, "token._.xyz": True}.

    values (Dict[str, dict]): The dict to convert.
    RETURNS (Dict[str, Any]): The key/value pairs.
    c                 S   s   i | ]
\}}d  ||qS )r   )join).0r   r   r   r   r   
<dictcomp>6   s    zdict_to_dot.<locals>.<dictcomp>)r   )r'   r   r   r   dict_to_dot/   s   r+   regexpsc              
      sx   zg  | d ur| D ]}  tj|tjd q	W n tjy. } z	td| d|d }~ww dtdtf fdd}|S )N)flagszRegular expression `z/` couldn't be compiled for logger stats matcherstringr   c                    s    D ]
}| | r dS qdS )NTF)search)r.   regexcompiledr   r   is_matchF   s
   
z,matcher_for_regex_patterns.<locals>.is_match)appendrecompile	MULTILINEerror
ValueErrorstrbool)r,   r0   errr3   r   r1   r   matcher_for_regex_patterns9   s    
r=   nlpr
   stdoutstderrc                 C   s.   t dd}|dd}|| ||\}}||fS )Nloggerszspacy.ConsoleLogger.v1F)progress_bar)r   get)r>   r?   r@   console_loggerconsoleconsole_log_stepconsole_finalizer   r   r   setup_default_console_loggerO   s   
rH   )N)__doc__systypingr   r   r   r   r   r   r   r	   r5   spacyr
   
spacy.utilr   r:   LoggerTr   r   r&   r+   r;   r=   r?   r@   rH   r   r   r   r   <module>   sJ    ((

""


