o
    €¨Êhí
  ã                   @   sH   d dl Z d dlZd dlZd dlZdZG dd„ deƒZG dd„ deƒZdS )é    Ni�  c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚCorpusObjectz˜
    This is a proxy object that allow additional
    attributes to be added to the collections of
    data that get returned by the corpus reader.
    c                    s2   |rt t| ƒ |d ¡ nt t| ƒ ¡  g | _dS )zE
        Imitate a list by allowing a value to be passed in.
        r   N)Úsuperr   Ú__init__Ú
categories)ÚselfÚargsÚkwargs©Ú	__class__© úJ/var/www/html/env/lib/python3.10/site-packages/chatterbot_corpus/corpus.pyr      s   
zCorpusObject.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r	   r   r   
   s    r   c                   @   s6   e Zd Zdd„ Zddd„Zdd„ Zdd	„ Zd
d„ ZdS )ÚCorpusc                 C   s(   t j t j t¡¡}t j |d¡| _d S )NÚdata)ÚosÚpathÚdirnameÚabspathÚ__file__ÚjoinÚdata_directory)r   Úcurrent_directoryr   r   r   r      s   zCorpus.__init__Újsonc                 C   st   t j|v s	d|v r|S | d¡}|d dkr | d¡ | j|d< t jj|Ž }t j |d |¡ ¡r8|d |¡7 }|S )zE
        Reads a dotted file path and returns the file path.
        ú/Ú.r   Ú
chatterbotz.{})	r   ÚsepÚsplitÚpopr   r   r   ÚexistsÚformat)r   Údotted_pathÚ	extensionÚpartsÚcorpus_pathr   r   r   Úget_file_path#   s   


zCorpus.get_file_pathc                 C   s>   t j|dd��}t |¡}W d  ƒ |S 1 sw   Y  |S )zC
        Read and return the data from a corpus json file.
        zutf-8)ÚencodingN)ÚioÚopenÚyamlÚload)r   Ú	file_nameÚ	data_filer   r   r   r   Úread_corpus9   s   
ÿþzCorpus.read_corpusc                 C   sP   d}| j ||d�}g }tj |¡rtj|d | dd�}n| |¡ | ¡  |S )z`
        Return a list of file paths to each data file in
        the specified corpus.
        Úyml)r&   z/**/*.T)Ú	recursive)r)   r   r   ÚisdirÚglobÚappendÚsort)r   r%   ÚCORPUS_EXTENSIONr(   Úpathsr   r   r   Úlist_corpus_filesA   s   
zCorpus.list_corpus_filesc                 C   sZ   |   |¡}g }|D ]!}tƒ }|  |¡}| dg ¡}| dg ¡|_| |¡ | |¡ q	|S )zF
        Return the data contained within a specified corpus.
        Úconversationsr   )r:   r   r1   Úgetr   Úextendr6   )r   r%   Údata_file_pathsÚcorporaÚ	file_pathÚcorpusÚcorpus_datar;   r   r   r   Úload_corpusS   s   


zCorpus.load_corpusN)r   )r   r   r   r   r)   r1   r:   rC   r   r   r   r   r      s    
r   )	r   r+   r5   r-   ÚDIALOG_MAXIMUM_CHARACTER_LENGTHÚlistr   Úobjectr   r   r   r   r   Ú<module>   s    