§
    'ê[f?S  ã                   ó8  — d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d„ Z G d„ d¦  «        Z
d	„ Z	 dd„Z e j        d¦  «        Zdd„Zd„ Z	 dd„Zd„ Z e j        de j        ¦  «        Z e j        d¦  «        Zd„ Zg d¢dfd„Zd„ Zedk    r e¦   «          dS dS )é    N)Úaccuracy)Úmap_tag)Ú	str2tuple)ÚTreec                 óÊ   — g }g }|D ]M}|                       |                     ¦   «         ¦  «        }|t          |¦  «        z  }|t          |¦  «        z  }ŒNt          ||¦  «        S )a|  
    Score the accuracy of the chunker against the gold standard.
    Strip the chunk information from the gold standard and rechunk it using
    the chunker, then compute the accuracy score.

    :type chunker: ChunkParserI
    :param chunker: The chunker being evaluated.
    :type gold: tree
    :param gold: The chunk structures to score the chunker on.
    :rtype: float
    )ÚparseÚflattenÚtree2conlltagsÚ	_accuracy)ÚchunkerÚgoldÚ	gold_tagsÚ	test_tagsÚ	gold_treeÚ	test_trees         úC/var/www/piapp/venv/lib/python3.11/site-packages/nltk/chunk/util.pyr   r      sr   € ð €IØ€IØð /ð /ˆ	Ø—M’M )×"3Ò"3Ñ"5Ô"5Ñ6Ô6ˆ	Ø•^ IÑ.Ô.Ñ.ˆ	Ø•^ IÑ.Ô.Ñ.ˆ	ˆ	õ �Y 	Ñ*Ô*Ð*ó    c                   óh   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dd	„Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )Ú
ChunkScorea;  
    A utility class for scoring chunk parsers.  ``ChunkScore`` can
    evaluate a chunk parser's output, based on a number of statistics
    (precision, recall, f-measure, misssed chunks, incorrect chunks).
    It can also combine the scores from the parsing of multiple texts;
    this makes it significantly easier to evaluate a chunk parser that
    operates one sentence at a time.

    Texts are evaluated with the ``score`` method.  The results of
    evaluation can be accessed via a number of accessor methods, such
    as ``precision`` and ``f_measure``.  A typical use of the
    ``ChunkScore`` class is::

        >>> chunkscore = ChunkScore()           # doctest: +SKIP
        >>> for correct in correct_sentences:   # doctest: +SKIP
        ...     guess = chunkparser.parse(correct.leaves())   # doctest: +SKIP
        ...     chunkscore.score(correct, guess)              # doctest: +SKIP
        >>> print('F Measure:', chunkscore.f_measure())       # doctest: +SKIP
        F Measure: 0.823

    :ivar kwargs: Keyword arguments:

        - max_tp_examples: The maximum number actual examples of true
          positives to record.  This affects the ``correct`` member
          function: ``correct`` will not return more than this number
          of true positive examples.  This does *not* affect any of
          the numerical metrics (precision, recall, or f-measure)

        - max_fp_examples: The maximum number actual examples of false
          positives to record.  This affects the ``incorrect`` member
          function and the ``guessed`` member function: ``incorrect``
          will not return more than this number of examples, and
          ``guessed`` will not return more than this number of true
          positive examples.  This does *not* affect any of the
          numerical metrics (precision, recall, or f-measure)

        - max_fn_examples: The maximum number actual examples of false
          negatives to record.  This affects the ``missed`` member
          function and the ``correct`` member function: ``missed``
          will not return more than this number of examples, and
          ``correct`` will not return more than this number of true
          negative examples.  This does *not* affect any of the
          numerical metrics (precision, recall, or f-measure)

        - chunk_label: A regular expression indicating which chunks
          should be compared.  Defaults to ``'.*'`` (i.e., all chunks).

    :type _tp: list(Token)
    :ivar _tp: List of true positives
    :type _fp: list(Token)
    :ivar _fp: List of false positives
    :type _fn: list(Token)
    :ivar _fn: List of false negatives

    :type _tp_num: int
    :ivar _tp_num: Number of true positives
    :type _fp_num: int
    :ivar _fp_num: Number of false positives
    :type _fn_num: int
    :ivar _fn_num: Number of false negatives.
    c                 óþ  — t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        |                     dd¦  «        | _        |                     dd¦  «        | _        |                     dd¦  «        | _	        |                     dd¦  «        | _
        d| _        d| _        d| _        d| _        d| _        d| _        d	| _        d S )
NÚmax_tp_exampleséd   Úmax_fp_examplesÚmax_fn_examplesÚchunk_labelz.*r   g        F)ÚsetÚ_correctÚ_guessedÚ_tpÚ_fpÚ_fnÚgetÚ_max_tpÚ_max_fpÚ_max_fnÚ_chunk_labelÚ_tp_numÚ_fp_numÚ_fn_numÚ_countÚ_tags_correctÚ_tags_totalÚ_measuresNeedUpdate)ÚselfÚkwargss     r   Ú__init__zChunkScore.__init__r   sË   € Ý™œˆŒÝ™œˆŒÝ‘5”5ˆŒÝ‘5”5ˆŒÝ‘5”5ˆŒØ—z’zÐ"3°SÑ9Ô9ˆŒØ—z’zÐ"3°SÑ9Ô9ˆŒØ—z’zÐ"3°SÑ9Ô9ˆŒØ"ŸJšJ }°dÑ;Ô;ˆÔØˆŒØˆŒØˆŒØˆŒØ ˆÔØˆÔà#(ˆÔ Ð Ð r   c                 ó4  — | j         r�| j        | j        z  | _        | j        | j        z
  | _        | j        | j        z
  | _        t          | j        ¦  «        | _        t          | j        ¦  «        | _        t          | j        ¦  «        | _	        d| _         d S d S )NF)
r-   r   r   r   r!   r    Úlenr'   r(   r)   ©r.   s    r   Ú_updateMeasureszChunkScore._updateMeasures…   s‚   € ØÔ#ð 	-Ø”} t¤}Ñ4ˆDŒHØ”} t¤}Ñ4ˆDŒHØ”} t¤}Ñ4ˆDŒHÝ˜tœx™=œ=ˆDŒLÝ˜tœx™=œ=ˆDŒLÝ˜tœx™=œ=ˆDŒLØ',ˆDÔ$Ð$Ð$ð	-ð 	-r   c           	      óä  — | xj         t          || j        | j        ¦  «        z  c_         | xj        t          || j        | j        ¦  «        z  c_        | xj        dz  c_        d| _        	 t          |¦  «        }t          |¦  «        }n# t          $ r dx}}Y nw xY w| xj        t          |¦  «        z  c_        | xj
        t          d„ t          ||¦  «        D ¦   «         ¦  «        z  c_
        dS )aU  
        Given a correctly chunked sentence, score another chunked
        version of the same sentence.

        :type correct: chunk structure
        :param correct: The known-correct ("gold standard") chunked
            sentence.
        :type guessed: chunk structure
        :param guessed: The chunked sentence to be scored.
        é   T© c              3   ó,   K  — | ]\  }}||k    ¯d V — ŒdS )r6   Nr7   )Ú.0ÚtÚgs      r   ú	<genexpr>z#ChunkScore.score.<locals>.<genexpr>¨   s3   è è € ð "
ð "
Ù�1�a¸qÀAºv¸vˆA¸v¸v¸v¸vð"
ð "
r   N)r   Ú
_chunksetsr*   r&   r   r-   r
   Ú
ValueErrorr,   r2   r+   ÚsumÚzip)r.   ÚcorrectÚguessedÚcorrect_tagsÚguessed_tagss        r   ÚscorezChunkScore.score�   s  € ð 	ˆŒ� G¨T¬[¸$Ô:KÑLÔLÑLˆŒØˆŒ� G¨T¬[¸$Ô:KÑLÔLÑLˆŒØˆŒ�qÑˆŒØ#'ˆÔ ð	-Ý)¨'Ñ2Ô2ˆLÝ)¨'Ñ2Ô2ˆLˆLøÝð 	-ð 	-ð 	-ð +-Ð,ˆL˜<˜<˜<ð		-øøøð
 	ÐÔ�C Ñ-Ô-Ñ-ÐÔØÐÔ�cð "
ð "
Ý ¨lÑ;Ô;ð"
ñ "
ô "
ñ 
ô 
ñ 	
ÐÔÐÐs   Á+B
 Â
BÂBc                 ó:   — | j         dk    rdS | j        | j         z  S )zÁ
        Return the overall tag-based accuracy for all text that have
        been scored by this ``ChunkScore``, using the IOB (conll2000)
        tag encoding.

        :rtype: float
        r   r6   )r,   r+   r3   s    r   r   zChunkScore.accuracy¬   s(   € ð Ô˜qÒ Ð Ø�1ØÔ! DÔ$4Ñ4Ð4r   c                 ól   — |                       ¦   «          | j        | j        z   }|dk    rdS | j        |z  S )z‰
        Return the overall precision for all texts that have been
        scored by this ``ChunkScore``.

        :rtype: float
        r   )r4   r'   r(   ©r.   Údivs     r   Ú	precisionzChunkScore.precision¸   ó?   € ð 	×ÒÑÔÐØŒl˜Tœ\Ñ)ˆØ�!Š8ˆ8Ø�1à”< #Ñ%Ð%r   c                 ól   — |                       ¦   «          | j        | j        z   }|dk    rdS | j        |z  S )z†
        Return the overall recall for all texts that have been
        scored by this ``ChunkScore``.

        :rtype: float
        r   ©r4   r'   r)   rH   s     r   ÚrecallzChunkScore.recallÆ   rK   r   ç      à?c                 ó¸   — |                       ¦   «          |                      ¦   «         }|                      ¦   «         }|dk    s|dk    rdS d||z  d|z
  |z  z   z  S )a»  
        Return the overall F measure for all texts that have been
        scored by this ``ChunkScore``.

        :param alpha: the relative weighting of precision and recall.
            Larger alpha biases the score towards the precision value,
            while smaller alpha biases the score towards the recall
            value.  ``alpha`` should have a value in the range [0,1].
        :type alpha: float
        :rtype: float
        r   r6   )r4   rJ   rN   )r.   ÚalphaÚpÚrs       r   Ú	f_measurezChunkScore.f_measureÔ   sd   € ð 	×ÒÑÔÐØ�NŠNÑÔˆØ�KŠK‰MŒMˆØ�Š6ˆ6�Q˜!’V�VØ�1Ø�E˜A‘I  U¡¨a¡Ñ/Ñ0Ð0r   c                 ój   — |                       ¦   «          t          | j        ¦  «        }d„ |D ¦   «         S )zÈ
        Return the chunks which were included in the
        correct chunk structures, but not in the guessed chunk
        structures, listed in input order.

        :rtype: list of chunks
        c                 ó   — g | ]
}|d          ‘ŒS ©r6   r7   ©r9   Úcs     r   ú
<listcomp>z%ChunkScore.missed.<locals>.<listcomp>ñ   ó   € Ð%Ð%Ð%˜��!”Ð%Ð%Ð%r   )r4   Úlistr!   ©r.   Úchunkss     r   ÚmissedzChunkScore.missedç   s7   € ð 	×ÒÑÔÐÝ�d”h‘”ˆØ%Ð%˜fÐ%Ñ%Ô%Ð%r   c                 ój   — |                       ¦   «          t          | j        ¦  «        }d„ |D ¦   «         S )zÀ
        Return the chunks which were included in the guessed chunk structures,
        but not in the correct chunk structures, listed in input order.

        :rtype: list of chunks
        c                 ó   — g | ]
}|d          ‘ŒS rW   r7   rX   s     r   rZ   z(ChunkScore.incorrect.<locals>.<listcomp>ü   r[   r   )r4   r\   r    r]   s     r   Ú	incorrectzChunkScore.incorrectó   s7   € ð 	×ÒÑÔÐÝ�d”h‘”ˆØ%Ð%˜fÐ%Ñ%Ô%Ð%r   c                 óB   — t          | j        ¦  «        }d„ |D ¦   «         S )z—
        Return the chunks which were included in the correct
        chunk structures, listed in input order.

        :rtype: list of chunks
        c                 ó   — g | ]
}|d          ‘ŒS rW   r7   rX   s     r   rZ   z&ChunkScore.correct.<locals>.<listcomp>  r[   r   )r\   r   r]   s     r   rA   zChunkScore.correctþ   ó'   € õ �d”mÑ$Ô$ˆØ%Ð%˜fÐ%Ñ%Ô%Ð%r   c                 óB   — t          | j        ¦  «        }d„ |D ¦   «         S )z—
        Return the chunks which were included in the guessed
        chunk structures, listed in input order.

        :rtype: list of chunks
        c                 ó   — g | ]
}|d          ‘ŒS rW   r7   rX   s     r   rZ   z&ChunkScore.guessed.<locals>.<listcomp>  r[   r   )r\   r   r]   s     r   rB   zChunkScore.guessed  re   r   c                 óH   — |                       ¦   «          | j        | j        z   S )NrM   r3   s    r   Ú__len__zChunkScore.__len__  s#   € Ø×ÒÑÔÐØŒ|˜dœlÑ*Ð*r   c                 óF   — dt          t          | ¦  «        ¦  «        z   dz   S )z`
        Return a concise representation of this ``ChunkScoring``.

        :rtype: str
        z<ChunkScoring of z chunks>)Úreprr2   r3   s    r   Ú__repr__zChunkScore.__repr__  s    € ð #¥T­#¨d©)¬)¡_¤_Ñ4°zÑAÐAr   c                 óî   — dd|                       ¦   «         dz  d›d�z   d|                      ¦   «         dz  d›d�z   d|                      ¦   «         dz  d›d�z   d|                      ¦   «         dz  d›d	�z   S )
a-  
        Return a verbose representation of this ``ChunkScoring``.
        This representation includes the precision, recall, and
        f-measure scores.  For other information about the score,
        use the accessor methods (e.g., ``missed()`` and ``incorrect()``).

        :rtype: str
        zChunkParse score:
z    IOB Accuracy: r   z5.1fz%%
z    Precision:    z    Recall:       z    F-Measure:    z%%)r   rJ   rN   rT   r3   s    r   Ú__str__zChunkScore.__str__  s¦   € ð "ØD D§M¢M¡O¤O°cÑ$9ÐDÐDÐDÐDñFàE D§N¢NÑ$4Ô$4°sÑ$:ÐEÐEÐEÐEñGð C D§K¢K¡M¤M°CÑ$7ÐBÐBÐBÐBñDð D D§N¢NÑ$4Ô$4°sÑ$:ÐCÐCÐCÐCñ	Eð	
r   N)rO   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   r4   rE   r   rJ   rN   rT   r_   rb   rA   rB   ri   rl   rn   r7   r   r   r   r   3   sù   € € € € € ð<ð <ð|)ð )ð )ð&-ð -ð -ð
ð 
ð 
ð:
5ð 
5ð 
5ð&ð &ð &ð&ð &ð &ð1ð 1ð 1ð 1ð&
&ð 
&ð 
&ð	&ð 	&ð 	&ð&ð &ð &ð&ð &ð &ð+ð +ð +ðBð Bð Bð
ð 
ð 
ð 
ð 
r   r   c                 óT  — d}g }| D ]“}t          |t          ¦  «        rwt          j        ||                     ¦   «         ¦  «        r+|                     ||f|                     ¦   «         f¦  «         |t          |                     ¦   «         ¦  «        z  }ŒŽ|dz  }Œ”t          |¦  «        S )Nr   r6   )
Ú
isinstancer   ÚreÚmatchÚlabelÚappendÚfreezer2   Úleavesr   )r:   Úcountr   Úposr^   Úchilds         r   r=   r=   2  sŸ   € Ø
€CØ€FØð ð ˆÝ�e�TÑ"Ô"ð 	ÝŒx˜ U§[¢[¡]¤]Ñ3Ô3ð >Ø—’  s˜|¨U¯\ª\©^¬^Ð<Ñ=Ô=Ð=Ø•3�u—|’|‘~”~Ñ&Ô&Ñ&ˆCˆCà�1‰HˆCˆCÝˆv‰;Œ;Ðr   ÚNPÚSú/c                 ó¢  — t          j        d¦  «        }t          |g ¦  «        g}|                     | ¦  «        D �]Y}|                     ¦   «         }	|	d         dk    ryt          |¦  «        dk    r%t          d|                     ¦   «         d›�¦  «        ‚t          |g ¦  «        }
|d                              |
¦  «         |                     |
¦  «         Œœ|	d         dk    rMt          |¦  «        d	k    r%t          d
|                     ¦   «         d›�¦  «        ‚| 	                    ¦   «          Œõ|€|d                              |	¦  «         �Œt          |	|¦  «        \  }}|r|rt          |||¦  «        }|d                              ||f¦  «         �Œ[t          |¦  «        dk    r t          dt          | ¦  «        d›�¦  «        ‚|d         S )aB  
    Divide a string of bracketted tagged text into
    chunks and unchunked tokens, and produce a Tree.
    Chunks are marked by square brackets (``[...]``).  Words are
    delimited by whitespace, and each word should have the form
    ``text/tag``.  Words that do not contain a slash are
    assigned a ``tag`` of None.

    :param s: The string to be converted
    :type s: str
    :param chunk_label: The label to use for chunk nodes
    :type chunk_label: str
    :param root_label: The label to use for the root of the tree
    :type root_label: str
    :rtype: Tree
    z\[|\]|[^\[\]\s]+r   ú[r6   zUnexpected [ at char Údéÿÿÿÿú]é   zUnexpected ] at char NzExpected ] at char )ru   Úcompiler   ÚfinditerÚgroupr2   r>   Ústartrx   Úpopr   r   )Úsr   Ú
root_labelÚsepÚsource_tagsetÚtarget_tagsetÚWORD_OR_BRACKETÚstackrv   ÚtextÚchunkÚwordÚtags                r   Útagstr2treer—   ?  sÃ  € õ( ”jÐ!4Ñ5Ô5€Oå�*˜bÑ!Ô!Ð"€EØ ×)Ò)¨!Ñ,Ô,ð .ñ .ˆØ�{Š{‰}Œ}ˆØ�Œ7�cŠ>ˆ>Ý�5‰zŒz˜QŠˆÝ Ð!J¸¿º¹¼Ð!JÐ!JÐ!JÑKÔKÐKÝ˜ bÑ)Ô)ˆEØ�"ŒI×Ò˜UÑ#Ô#Ð#Ø�LŠL˜ÑÔÐÐØ�!ŒW˜Š^ˆ^Ý�5‰zŒz˜QŠˆÝ Ð!J¸¿º¹¼Ð!JÐ!JÐ!JÑKÔKÐKØ�IŠI‰KŒKˆKˆKàˆ{Ø�b”	× Ò  Ñ&Ô&Ð&Ñ&å% d¨CÑ0Ô0‘	��cØ ð E ]ð EÝ! -°ÀÑDÔD�CØ�b”	× Ò  $¨ Ñ-Ô-Ð-Ñ-å
ˆ5�z„z�Q‚€ÝÐ9­s°1©v¬vÐ9Ð9Ð9Ñ:Ô:Ð:Ø�Œ8€Or   z(\S+)\s+(\S+)\s+([IOB])-?(\S+)?©r~   ÚPPÚVPc                 ó¾  — t          |g ¦  «        g}t          |                      d¦  «        ¦  «        D �]!\  }}|                     ¦   «         sŒt                               |¦  «        }|€t          d|d›�¦  «        ‚|                     ¦   «         \  }}}	}
|�|
|vrd}	|	dk    o|
|d                              ¦   «         k    }|	dv s|r't          |¦  «        d	k    r| 
                    ¦   «          |	d
k    s|r@t          |
g ¦  «        }|d                              |¦  «         |                     |¦  «         |d                              ||f¦  «         �Œ#|d         S )a*  
    Return a chunk structure for a single sentence
    encoded in the given CONLL 2000 style string.
    This function converts a CoNLL IOB string into a tree.
    It uses the specified chunk types
    (defaults to NP, PP and VP), and creates a tree rooted at a node
    labeled S (by default).

    :param s: The CoNLL string to be converted.
    :type s: str
    :param chunk_types: The chunk types to be converted.
    :type chunk_types: tuple
    :param root_label: The node label to use for the root.
    :type root_label: str
    :rtype: Tree
    Ú
NzError on line rƒ   ÚOÚIr„   ÚBOr†   ÚBr   )r   Ú	enumerateÚsplitÚstripÚ_LINE_RErv   r>   Úgroupsrw   r2   r‹   rx   )rŒ   Úchunk_typesr�   r’   ÚlinenoÚlinerv   r•   r–   ÚstateÚ
chunk_typeÚ
mismatch_Ir”   s                r   Úconllstr2treer¬   u  sk  € õ$ �*˜bÑ!Ô!Ð"€Eå! !§'¢'¨$¡-¤-Ñ0Ô0ð &ñ &‰ˆ�Ø�zŠz‰|Œ|ð 	Øõ —’˜tÑ$Ô$ˆØˆ=ÝÐ8¨fÐ8Ð8Ð8Ñ9Ô9Ð9Ø).¯ª©¬Ñ&ˆˆs�E˜:ð Ð" z¸Ð'DÐ'DØˆEð ˜c’\ÐE j°E¸"´I·O²OÑ4EÔ4EÒ&Eˆ
Ø�Dˆ=ˆ=˜Jˆ=Ý�5‰zŒz˜QŠˆØ—	’	‘”�ð �CŠ<ˆ<˜:ˆ<Ý˜ RÑ(Ô(ˆEØ�"ŒI×Ò˜UÑ#Ô#Ð#Ø�LŠL˜ÑÔÐð 	ˆbŒ	×Ò˜$ ˜Ñ%Ô%Ð%Ñ%à�Œ8€Or   c                 óN  — g }| D ]Ÿ}	 |                      ¦   «         }d}|D ]O}t          |t          ¦  «        rt          d¦  «        ‚|                     |d         |d         ||z   f¦  «         d}ŒPŒl# t
          $ r' |                     |d         |d         df¦  «         Y Œœw xY w|S )zË
    Return a list of 3-tuples containing ``(word, tag, IOB-tag)``.
    Convert a tree to the CoNLL IOB tag format.

    :param t: The tree to be converted.
    :type t: Tree
    :rtype: list(tuple)
    úB-z7Tree is too deeply nested to be printed in CoNLL formatr   r6   úI-r�   )rw   rt   r   r>   rx   ÚAttributeError)r:   Útagsr}   ÚcategoryÚprefixÚcontentss         r   r
   r
   ª  sâ   € ð €DØð 3ð 3ˆð	3Ø—{’{‘}”}ˆHØˆFØ!ð ð �Ý˜h­Ñ-Ô-ð Ý$ØQñô ð ð —’˜X aœ[¨(°1¬+°vÀÑ7HÐIÑJÔJÐJØ��ðøõ ð 	3ð 	3ð 	3Ø�KŠK˜˜qœ 5¨¤8¨SÐ1Ñ2Ô2Ð2Ð2Ð2ð	3øøøà€Ks   ˆA(A1Á1.B"Â!B"Fc                 ó
  — t          |g ¦  «        }| D �]n\  }}}|€)|rt          d¦  «        ‚|                     ||f¦  «         Œ2|                     d¦  «        r/|                     t          |dd…         ||fg¦  «        ¦  «         Œv|                     d¦  «        r´t	          |¦  «        dk    sAt          |d         t           ¦  «        r&|d                              ¦   «         |dd…         k    rA|rt          d¦  «        ‚|                     t          |dd…         ||fg¦  «        ¦  «         �Œ |d                              ||f¦  «         �Œ?|dk    r|                     ||f¦  «         �Œ^t          d	|›�¦  «        ‚|S )
z1
    Convert the CoNLL IOB format to a tree.
    NzBad conll tag sequencer®   r†   r¯   r   r„   r�   zBad conll tag )r   r>   rx   Ú
startswithr2   rt   rw   )Úsentencer¦   r�   ÚstrictÚtreer•   ÚpostagÚchunktags           r   Úconlltags2treer¼   Å  s¤  € õ �
˜BÑÔ€DØ$,ð <ñ <Ñ ˆˆv�xØÐØð ,Ý Ð!9Ñ:Ô:Ð:ð —’˜T 6˜NÑ+Ô+Ð+Ð+Ø× Ò  Ñ&Ô&ð 	<Ø�KŠK�˜X a b bœ\¨T°6¨NÐ+;Ñ<Ô<Ñ=Ô=Ð=Ð=Ø× Ò  Ñ&Ô&ð 	<å�D‘	”	˜Q’�Ý! $ r¤(­DÑ1Ô1ð à˜”8—>’>Ñ#Ô# x°°°¤|Ò3Ð3àð FÝ$Ð%=Ñ>Ô>Ð>ð —K’K¥ X¨a¨b¨b¤\°T¸6°NÐ3CÑ DÔ DÑEÔEÐEÑEà�R”—’  v Ñ/Ô/Ð/Ñ/Ø˜Š_ˆ_Ø�KŠK˜˜v˜Ñ'Ô'Ð'Ñ'åÐ:¨hÐ:Ð:Ñ;Ô;Ð;Ø€Kr   c                 ó^   — d„ t          | ¦  «        D ¦   «         }d                     |¦  «        S )zÒ
    Return a multiline string where each line contains a word, tag and IOB tag.
    Convert a tree to the CoNLL IOB string format

    :param t: The tree to be converted.
    :type t: Tree
    :rtype: str
    c                 ó8   — g | ]}d                       |¦  «        ‘ŒS )Ú )Újoin)r9   Útokens     r   rZ   z!tree2conllstr.<locals>.<listcomp>ò  s"   € Ð<Ð<Ð< ˆS�XŠX�e‰_Œ_Ð<Ð<Ð<r   rœ   )r
   rÀ   )r:   Úliness     r   Útree2conllstrrÃ   é  s1   € ð =Ð<­.¸Ñ*;Ô*;Ð<Ñ<Ô<€EØ�9Š9�UÑÔÐr   a   <DOC>\s*(<DOCNO>\s*(?P<docno>.+?)\s*</DOCNO>\s*)?(<DOCTYPE>\s*(?P<doctype>.+?)\s*</DOCTYPE>\s*)?(<DATE_TIME>\s*(?P<date_time>.+?)\s*</DATE_TIME>\s*)?<BODY>\s*(<HEADLINE>\s*(?P<headline>.+?)\s*</HEADLINE>\s*)?<TEXT>(?P<text>.*?)</TEXT>\s*</BODY>\s*</DOC>\s*z#<b_\w+\s+[^>]*?type="(?P<type>\w+)"c                 ó  — t          |g ¦  «        g}| €g S t          j        d| ¦  «        D �]1}|                     ¦   «         }	 |                     d¦  «        r€t
                               |¦  «        }|€t          d|¦  «         t          |                     d¦  «        g ¦  «        }|d                              |¦  «         |                     |¦  «         nE|                     d¦  «        r| 	                    ¦   «          n|d                              |¦  «         Œó# t          t          f$ r,}t          d|                     ¦   «         d›d	�¦  «        |‚d }~ww xY wt          |¦  «        d
k    rt          d¦  «        ‚|d         S )Nz<[^>]+>|[^\s<]+z<b_ÚXXXXÚtyper„   z<e_z$Bad IEER string (error at character rƒ   ú)r6   zBad IEER stringr   )r   ru   rˆ   r‰   r¶   Ú_IEER_TYPE_RErv   Úprintrx   r‹   Ú
IndexErrorr>   rŠ   r2   )rŒ   r�   r’   Úpiece_mÚpieceÚmr”   Úes           r   Ú_ieer_read_textrÏ     s�  € Ý�*˜bÑ!Ô!Ð"€Eð 	€yØˆ	Ý”;Ð1°1Ñ5Ô5ð ñ ˆØ—’‘”ˆð	Ø×Ò Ñ&Ô&ð (Ý!×'Ò'¨Ñ.Ô.�Ø�9Ý˜& %Ñ(Ô(Ð(Ý˜QŸWšW V™_œ_¨bÑ1Ô1�Ø�b”	× Ò  Ñ'Ô'Ð'Ø—’˜UÑ#Ô#Ð#Ð#Ø×!Ò! %Ñ(Ô(ð (Ø—	’	‘”��ð
 �b”	× Ò  Ñ'Ô'Ð'øøÝ�JÐ'ð 	ð 	ð 	ÝØK°w·}²}±´ÐKÐKÐKÐKñô àðøøøøð	øøøõ ˆ5�z„z�Q‚€ÝÐ*Ñ+Ô+Ð+Ø�Œ8€Os   ÁCDÄEÄ/'EÅE)	ÚLOCATIONÚORGANIZATIONÚPERSONÚDURATIONÚDATEÚCARDINALÚPERCENTÚMONEYÚMEASUREc           	      ó`  — t                                | ¦  «        }|rƒt          |                     d¦  «        |¦  «        |                     d¦  «        |                     d¦  «        |                     d¦  «        t          |                     d¦  «        |¦  «        dœS t          | |¦  «        S )ap  
    Return a chunk structure containing the chunked tagged text that is
    encoded in the given IEER style string.
    Convert a string of chunked tagged text in the IEER named
    entity format into a chunk structure.  Chunks are of several
    types, LOCATION, ORGANIZATION, PERSON, DURATION, DATE, CARDINAL,
    PERCENT, MONEY, and MEASURE.

    :rtype: Tree
    r“   ÚdocnoÚdoctypeÚ	date_timeÚheadline)r“   rÚ   rÛ   rÜ   rÝ   )Ú_IEER_DOC_RErv   rÏ   r‰   )rŒ   r¦   r�   rÍ   s       r   Úieerstr2treerß   '  sŸ   € õ8 	×Ò˜1ÑÔ€AØð .å# A§G¢G¨F¡O¤O°ZÑ@Ô@Ø—W’W˜WÑ%Ô%Ø—w’w˜yÑ)Ô)ØŸš Ñ-Ô-õ (¨¯ª°
Ñ(;Ô(;¸ZÑHÔHð
ð 
ð 	
õ ˜q *Ñ-Ô-Ð-r   c                  ód  — d} dd l }|j                             | d¬¦  «        }|                     ¦   «          t	          ¦   «          d} t          | d¬¦  «        }|                     ¦   «          t	          d¦  «         t	          |j                             |¦  «        ¦  «         t	          ¦   «          d S )	Nzd[ Pierre/NNP Vinken/NNP ] ,/, [ 61/CD years/NNS ] old/JJ ,/, will/MD join/VB [ the/DT board/NN ] ./.r   r~   )r   av  
These DT B-NP
research NN I-NP
protocols NNS I-NP
offer VBP B-VP
to TO B-PP
the DT B-NP
patient NN I-NP
not RB O
only RB O
the DT B-NP
very RB I-NP
best JJS I-NP
therapy NN I-NP
which WDT B-NP
we PRP B-NP
have VBP B-VP
established VBN I-VP
today NN B-NP
but CC B-NP
also RB I-NP
the DT B-NP
hope NN I-NP
of IN B-PP
something NN B-NP
still RB B-ADJP
better JJR I-ADJP
. . O
)r~   r™   )r¦   zCoNLL output:)Únltkr”   r—   ÚpprintrÉ   r¬   rÃ   )rŒ   rá   r:   Ú
conll_trees       r   Údemorä   R  s¨   € àn€AØ€K€K€KàŒ
×Ò˜q¨dÐÑ3Ô3€AØ‡H‚H�J„J€JÝ	�G„G€Gð	€Aõ< ˜q¨lÐ;Ñ;Ô;€JØ×ÒÑÔÐõ 
ˆ/ÑÔÐÝ	ˆ$Œ*×
"Ò
" :Ñ
.Ô
.Ñ/Ô/Ð/Ý	�G„G€G€G€Gr   Ú__main__)r~   r   r€   NN)r˜   r   )r˜   r   F)ru   Únltk.metricsr   r   Únltk.tag.mappingr   Únltk.tag.utilr   Ú	nltk.treer   r   r=   r—   r‡   r¤   r¬   r
   r¼   rÃ   ÚDOTALLrÞ   rÈ   rÏ   rß   rä   ro   r7   r   r   ú<module>rë      sÈ  ðð 
€	€	€	à .Ð .Ð .Ð .Ð .Ð .Ø $Ð $Ð $Ð $Ð $Ð $Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð ð+ð +ð +ð<z
ð z
ð z
ð z
ð z
ñ z
ô z
ð z
ð~
ð 
ð 
ð UYð.ð .ð .ð .ðf ˆ2Œ:Ð8Ñ9Ô9€ð2ð 2ð 2ð 2ðjð ð ð8 FKð!ð !ð !ð !ðH
ð 
ð 
ð ˆrŒzðð „Iñ
ô 
€ð �”
ÐAÑBÔB€ðð ð ðD
ð 
ð 
ð ð(.ð (.ð (.ð (.ðV-ð -ð -ð` ˆzÒÐØ€D�F„F€F€F€Fð Ðr   