a
     ˜ëjó  ã                   @   sd   d dl mZ d dlmZmZmZ d dlmZmZ d dl	m
Z
mZ G dd„ deƒZG dd„ deƒZd	S )
é    )ÚCorpusReader)ÚStreamBackedCorpusViewÚconcatÚread_alignedsent_block)ÚRegexpTokenizerÚWhitespaceTokenizer)ÚAlignedSentÚ	Alignmentc                   @   sL   e Zd ZdZdeƒ eddd�edfdd„Zdd
d„Zddd„Z	ddd„Z
d	S )ÚAlignedCorpusReaderz’
    Reader for corpora of word-aligned sentences.  Tokens are assumed
    to be separated by whitespace.  Sentences begin on separate lines.
    ú/Ú
T)ZgapsÚlatin1c                 C   s,   t  | |||¡ || _|| _|| _|| _dS )a˜  
        Construct a new Aligned Corpus reader for a set of documents
        located at the given root directory.  Example usage:

            >>> root = '/...path to corpus.../'
            >>> reader = AlignedCorpusReader(root, '.*', '.txt') # doctest: +SKIP

        :param root: The root directory for this corpus.
        :param fileids: A list or regexp specifying the fileids in this corpus.
        N)r   Ú__init__Z_sepÚ_word_tokenizerÚ_sent_tokenizerÚ_alignedsent_block_reader)ÚselfÚrootÚfileidsÚsepÚword_tokenizerÚsent_tokenizerÚalignedsent_block_readerÚencoding© r   úY/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/nltk/corpus/reader/aligned.pyr      s
    zAlignedCorpusReader.__init__Nc                    s   t ‡ fdd„ˆ  |d¡D ƒƒS )z~
        :return: the given file(s) as a list of words
            and punctuation symbols.
        :rtype: list(str)
        c              
      s*   g | ]"\}}t ||d d ˆ jˆ jˆ jƒ‘qS )F©ÚAlignedSentCorpusViewr   r   r   ©Ú.0ZfileidÚenc©r   r   r   Ú
<listcomp>9   s   
÷ùz-AlignedCorpusReader.words.<locals>.<listcomp>T©r   Zabspaths©r   r   r   r!   r   Úwords2   s
    


öÿzAlignedCorpusReader.wordsc                    s   t ‡ fdd„ˆ  |d¡D ƒƒS )z²
        :return: the given file(s) as a list of
            sentences or utterances, each encoded as a list of word
            strings.
        :rtype: list(list(str))
        c              
      s*   g | ]"\}}t ||d dˆ jˆ jˆ jƒ‘qS )FTr   r   r!   r   r   r"   O   s   
÷ùz-AlignedCorpusReader.sents.<locals>.<listcomp>Tr#   r$   r   r!   r   ÚsentsG   s
    


öÿzAlignedCorpusReader.sentsc                    s   t ‡ fdd„ˆ  |d¡D ƒƒS )zp
        :return: the given file(s) as a list of AlignedSent objects.
        :rtype: list(AlignedSent)
        c              
      s*   g | ]"\}}t ||d d ˆ jˆ jˆ jƒ‘qS )Tr   r   r!   r   r   r"   c   s   
÷ùz5AlignedCorpusReader.aligned_sents.<locals>.<listcomp>Tr#   r$   r   r!   r   Úaligned_sents]   s
    


öÿz!AlignedCorpusReader.aligned_sents)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r%   r&   r'   r   r   r   r   r
      s   	
ø


r
   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   z³
    A specialized corpus view for aligned sentences.
    ``AlignedSentCorpusView`` objects are typically created by
    ``AlignedCorpusReader`` (not directly by nltk users).
    c                 C   s2   || _ || _|| _|| _|| _tj| ||d� d S )N)r   )Ú_alignedÚ_group_by_sentr   r   r   r   r   )r   Zcorpus_filer   ZalignedZgroup_by_sentr   r   r   r   r   r   r   y   s    
zAlignedSentCorpusView.__init__c                    s`   ‡ fdd„ˆ   |¡D ƒ}ˆ jrBt d |d ¡¡|d< t|Ž g}nˆ jrT|d g}n|d }|S )Nc                    s*   g | ]"}ˆ j  |¡D ]}ˆ j |¡‘qqS r   )r   Útokenizer   )r   Zalignedsent_strZsent_strr!   r   r   r"   ‹   s   þz4AlignedSentCorpusView.read_block.<locals>.<listcomp>ú é   r   )r   r,   r	   Ú
fromstringÚjoinr   r-   )r   ÚstreamÚblockr   r!   r   Ú
read_blockŠ   s    
þÿz AlignedSentCorpusView.read_blockN)r(   r)   r*   r+   r   r5   r   r   r   r   r   r   s   r   N)Znltk.corpus.reader.apir   Znltk.corpus.reader.utilr   r   r   Znltk.tokenizer   r   Znltk.translater   r	   r
   r   r   r   r   r   Ú<module>   s
   `