§
    'ê[f–$  ã                   ó–   — d Z ddlZddlZddlZddlmZ ddlT ddlm	Z	 ddl
T ddlT ddlmZ  G d„ de¦  «        Z G d	„ d
e¦  «        ZdS )zN
A reader for corpora that contain chunked (and optionally tagged)
documents.
é    N©Útagstr2tree)Ú*)ÚBracketParseCorpusReader)ÚTreec                   óŠ   — e Zd ZdZde edd¬¦  «        eddfd„Zdd	„Zdd
„Z	dd„Z
dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd„ ZdS )ÚChunkedCorpusReadera&  
    Reader for chunked (and optionally tagged) corpora.  Paragraphs
    are split using a block reader.  They are then tokenized into
    sentences using a sentence tokenizer.  Finally, these sentences
    are parsed into chunk trees using a string-to-chunktree conversion
    function.  Each of these steps can be performed using a default
    function or a custom function.  By default, paragraphs are split
    on blank lines; sentences are listed one per line; and sentences
    are parsed into chunk trees using ``nltk.chunk.tagstr2tree``.
    Ú Ú
T)ÚgapsÚutf8Nc	                 óV   — t                                | |||¦  «         ||||f| _        dS )z’
        :param root: The root directory for this corpus.
        :param fileids: A list or regexp specifying the fileids in this corpus.
        N)ÚCorpusReaderÚ__init__Ú_cv_args)	ÚselfÚrootÚfileidsÚ	extensionÚstr2chunktreeÚsent_tokenizerÚpara_block_readerÚencodingÚtagsets	            úN/var/www/piapp/venv/lib/python3.11/site-packages/nltk/corpus/reader/chunked.pyr   zChunkedCorpusReader.__init__&   s;   € õ 	×Ò˜d D¨'°8Ñ<Ô<Ð<Ø&¨Ð8IÈ6ÐRˆŒð	Að 	Aó    c                 ób   ‡ — t          ˆ fd„‰                      |d¦  «        D ¦   «         ¦  «        S )z~
        :return: the given file(s) as a list of words
            and punctuation symbols.
        :rtype: list(str)
        c           
      óD   •— g | ]\  }}t          ||d d d d g‰j        ¢R Ž ‘ŒS )r   ©ÚChunkedCorpusViewr   ©Ú.0ÚfÚencr   s      €r   ú
<listcomp>z-ChunkedCorpusReader.words.<locals>.<listcomp>A   óI   ø€ ð ð ð á�Q˜õ " ! S¨!¨Q°°1ÐE°t´}ÐEÐEÐEðð ð r   T©ÚconcatÚabspaths©r   r   s   ` r   ÚwordszChunkedCorpusReader.words:   sK   ø€ õ ðð ð ð à $§¢¨g°tÑ <Ô <ðñ ô ñ
ô 
ð 	
r   c                 ób   ‡ — t          ˆ f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           
      óD   •— g | ]\  }}t          ||d dd d g‰j        ¢R Ž ‘ŒS ©r   é   r   r!   s      €r   r%   z-ChunkedCorpusReader.sents.<locals>.<listcomp>O   r&   r   Tr'   r*   s   ` r   ÚsentszChunkedCorpusReader.sentsG   óK   ø€ õ ðð ð ð à $§¢¨g°tÑ <Ô <ðñ ô ñ
ô 
ð 	
r   c                 ób   ‡ — t          ˆ fd„‰                      |d¦  «        D ¦   «         ¦  «        S )zÜ
        :return: the given file(s) as a list of
            paragraphs, each encoded as a list of sentences, which are
            in turn encoded as lists of word strings.
        :rtype: list(list(list(str)))
        c           
      óD   •— g | ]\  }}t          ||d ddd g‰j        ¢R Ž ‘ŒS r.   r   r!   s      €r   r%   z-ChunkedCorpusReader.paras.<locals>.<listcomp>]   r&   r   Tr'   r*   s   ` r   ÚparaszChunkedCorpusReader.parasU   r1   r   c                 óf   ‡ ‡— t          ˆ ˆfd„‰                      |d¦  «        D ¦   «         ¦  «        S )z¾
        :return: the given file(s) as a list of tagged
            words and punctuation symbols, encoded as tuples
            ``(word,tag)``.
        :rtype: list(tuple(str,str))
        c           
      óJ   •— g | ]\  }}t          ||d dddg‰j        ¢R d‰iŽ‘Œ S ©r/   r   Útarget_tagsetr   ©r"   r#   r$   r   r   s      €€r   r%   z4ChunkedCorpusReader.tagged_words.<locals>.<listcomp>k   ób   ø€ ð ð ð ñ �Q˜õ "Ø�s˜A˜q ! QðØ)-¬ðð ð ØFLðð ðð ð r   Tr'   ©r   r   r   s   ` `r   Útagged_wordsz ChunkedCorpusReader.tagged_wordsc   óS   øø€ õ ðð ð ð ð ð !%§¢¨g°tÑ <Ô <ð	ñ ô ñ
ô 
ð 	
r   c                 óf   ‡ ‡— t          ˆ ˆfd„‰                      |d¦  «        D ¦   «         ¦  «        S )z­
        :return: the given file(s) as a list of
            sentences, each encoded as a list of ``(word,tag)`` tuples.

        :rtype: list(list(tuple(str,str)))
        c           
      óJ   •— g | ]\  }}t          ||d d ddg‰j        ¢R d‰iŽ‘Œ S r7   r   r9   s      €€r   r%   z4ChunkedCorpusReader.tagged_sents.<locals>.<listcomp>{   r:   r   Tr'   r;   s   ` `r   Útagged_sentsz ChunkedCorpusReader.tagged_sentss   r=   r   c                 óf   ‡ ‡— t          ˆ ˆfd„‰                      |d¦  «        D ¦   «         ¦  «        S )zð
        :return: the given file(s) as a list of
            paragraphs, each encoded as a list of sentences, which are
            in turn encoded as lists of ``(word,tag)`` tuples.
        :rtype: list(list(list(tuple(str,str))))
        c           
      óJ   •— g | ]\  }}t          ||d d d dg‰j        ¢R d‰iŽ‘Œ S r7   r   r9   s      €€r   r%   z4ChunkedCorpusReader.tagged_paras.<locals>.<listcomp>‹   r:   r   Tr'   r;   s   ` `r   Útagged_parasz ChunkedCorpusReader.tagged_parasƒ   r=   r   c                 óf   ‡ ‡— t          ˆ ˆfd„‰                      |d¦  «        D ¦   «         ¦  «        S )av  
        :return: the given file(s) as a list of tagged
            words and chunks.  Words are encoded as ``(word, tag)``
            tuples (if the corpus has tags) or word strings (if the
            corpus has no tags).  Chunks are encoded as depth-one
            trees over ``(word,tag)`` tuples or word strings.
        :rtype: list(tuple(str,str) and Tree)
        c           
      óJ   •— g | ]\  }}t          ||d ddd g‰j        ¢R d‰iŽ‘Œ S r7   r   r9   s      €€r   r%   z5ChunkedCorpusReader.chunked_words.<locals>.<listcomp>�   r:   r   Tr'   r;   s   ` `r   Úchunked_wordsz!ChunkedCorpusReader.chunked_words“   óS   øø€ õ ðð ð ð ð ð !%§¢¨g°tÑ <Ô <ð	ñ ô ñ
ô 
ð 	
r   c                 óf   ‡ ‡— t          ˆ ˆfd„‰                      |d¦  «        D ¦   «         ¦  «        S )a6  
        :return: the given file(s) as a list of
            sentences, each encoded as a shallow Tree.  The leaves
            of these trees are encoded as ``(word, tag)`` tuples (if
            the corpus has tags) or word strings (if the corpus has no
            tags).
        :rtype: list(Tree)
        c           
      óJ   •— g | ]\  }}t          ||d d dd g‰j        ¢R d‰iŽ‘Œ S r7   r   r9   s      €€r   r%   z5ChunkedCorpusReader.chunked_sents.<locals>.<listcomp>¯   r:   r   Tr'   r;   s   ` `r   Úchunked_sentsz!ChunkedCorpusReader.chunked_sents¥   rG   r   c                 óf   ‡ ‡— t          ˆ ˆfd„‰                      |d¦  «        D ¦   «         ¦  «        S )ao  
        :return: the given file(s) as a list of
            paragraphs, each encoded as a list of sentences, which are
            in turn encoded as a shallow Tree.  The leaves of these
            trees are encoded as ``(word, tag)`` tuples (if the corpus
            has tags) or word strings (if the corpus has no tags).
        :rtype: list(list(Tree))
        c           
      óJ   •— g | ]\  }}t          ||d d d d g‰j        ¢R d‰iŽ‘Œ S )r/   r8   r   r9   s      €€r   r%   z5ChunkedCorpusReader.chunked_paras.<locals>.<listcomp>Á   r:   r   Tr'   r;   s   ` `r   Úchunked_parasz!ChunkedCorpusReader.chunked_paras·   rG   r   c                 ó4   — d„ t          |¦  «        D ¦   «         S )Nc                 ó,   — g | ]}t          |¦  «        ‘ŒS © r   )r"   Úts     r   r%   z3ChunkedCorpusReader._read_block.<locals>.<listcomp>Ê   s   € ÐEÐEÐE 1•˜A‘”ÐEÐEÐEr   )Úread_blankline_block)r   Ústreams     r   Ú_read_blockzChunkedCorpusReader._read_blockÉ   s   € ØEÐEÕ(<¸VÑ(DÔ(DÐEÑEÔEÐEr   )N©NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚRegexpTokenizerrR   r   r+   r0   r4   r<   r@   rC   rF   rJ   rM   rT   rP   r   r   r	   r	      s!  € € € € € ð	ð 	ð Ø!Ø&� t°$Ð7Ñ7Ô7Ø.ØØðAð Að Að Að(
ð 
ð 
ð 
ð
ð 
ð 
ð 
ð
ð 
ð 
ð 
ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð$
ð 
ð 
ð 
ð$
ð 
ð 
ð 
ð$Fð Fð Fð Fð Fr   r	   c                   ó&   — e Zd Z	 	 dd„Zd„ Zd„ ZdS )r    Nc                 ó¾   — t                                | ||¬¦  «         || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        d S )N)r   )ÚStreamBackedCorpusViewr   Ú_taggedÚ_group_by_sentÚ_group_by_paraÚ_chunkedÚ_str2chunktreeÚ_sent_tokenizerÚ_para_block_readerÚ_source_tagsetÚ_target_tagset)r   Úfileidr   ÚtaggedÚgroup_by_sentÚgroup_by_paraÚchunkedr   r   r   Úsource_tagsetr8   s               r   r   zChunkedCorpusView.__init__Î   sk   € õ 	×'Ò'¨¨f¸xÐ'ÑHÔHÐHØˆŒØ+ˆÔØ+ˆÔØˆŒØ+ˆÔØ-ˆÔØ"3ˆÔØ+ˆÔØ+ˆÔÐÐr   c                 óò  — g }|                       |¦  «        D ]Þ}g }| j                             |¦  «        D ]�}|                      || j        | j        ¬¦  «        }| j        s|                      |¦  «        }| j        s| 	                    ¦   «         }| j
        r|                     |¦  «         Œx|                     |¦  «         ŒŽ| j        r|                     |¦  «         ŒÉ|                     |¦  «         Œß|S )N)rl   r8   )rd   rc   Útokenizerb   re   rf   r^   Ú_untagra   Úleavesr_   ÚappendÚextendr`   )r   rS   ÚblockÚpara_strÚparaÚsent_strÚsents          r   Ú
read_blockzChunkedCorpusView.read_blockç   s  € ØˆØ×/Ò/°Ñ7Ô7ð 	#ð 	#ˆHØˆDØ Ô0×9Ò9¸(ÑCÔCð &ð &�Ø×*Ò*ØØ"&Ô"5Ø"&Ô"5ð +ñ ô �ð ”|ð -ØŸ;š; tÑ,Ô,�Dð ”}ð )ØŸ;š;™=œ=�Dð Ô&ð &Ø—K’K Ñ%Ô%Ð%Ð%à—K’K Ñ%Ô%Ð%Ð%ð Ô"ð #Ø—’˜TÑ"Ô"Ð"Ð"à—’˜TÑ"Ô"Ð"Ð"ð ˆr   c                 óä   — t          |¦  «        D ]_\  }}t          |t          ¦  «        r|                      |¦  «         Œ0t          |t          ¦  «        r|d         ||<   ŒQt          d¦  «        ‚|S )Nr   z"expected child to be Tree or tuple)Ú	enumerateÚ
isinstancer   ro   ÚtupleÚ
ValueError)r   ÚtreeÚiÚchilds       r   ro   zChunkedCorpusView._untag	  s{   € Ý! $™œð 	Gð 	G‰HˆAˆuÝ˜%¥Ñ&Ô&ð GØ—’˜EÑ"Ô"Ð"Ð"Ý˜E¥5Ñ)Ô)ð GØ œ(��Q‘�å Ð!EÑFÔFÐFØˆr   rU   )rV   rW   rX   r   rx   ro   rP   r   r   r    r    Í   sO   € € € € € ð Øð,ð ,ð ,ð ,ð2 ð  ð  ðDð ð ð ð r   r    )rY   ÚcodecsÚos.pathÚosÚnltkÚ
nltk.chunkr   Únltk.corpus.reader.apiÚ nltk.corpus.reader.bracket_parser   Únltk.corpus.reader.utilÚnltk.tokenizeÚ	nltk.treer   r   r	   r]   r    rP   r   r   ú<module>r‹      s   ððð ð
 €€€Ø €€€à €€€Ø "Ð "Ð "Ð "Ð "Ð "Ø $Ð $Ð $Ð $Ø EÐ EÐ EÐ EÐ EÐ EØ %Ð %Ð %Ð %Ø Ð Ð Ð Ø Ð Ð Ð Ð Ð ðpFð pFð pFð pFð pF˜,ñ pFô pFð pFðfDð Dð Dð Dð DÐ.ñ Dô Dð Dð Dð Dr   