| Server IP : 54.37.205.81 / Your IP : 216.73.216.76 Web Server : nginx/1.22.1 System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64 User : debian ( 1000) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/nltk/chunk/__pycache__/ |
Upload File : |
�
T�c�P � �8 � d dl Z d dlmZ d dlmZ d dlmZ d dlm Z d� Z G d� d� � Z
d � Z dd
�Z e j
d� � Zdd�Zd� Z dd�Zd� Z e j
de j � � Z e j
d� � Zd� Zg d�dfd�Zd� Zedk r e� � dS dS )� 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 �1/usr/lib/python3/dist-packages/nltk/chunk/util.pyr r sr � � �I��I�� /� /� ��M�M�)�"3�"3�"5�"5�6�6� ��^�I�.�.�.� ��^�I�.�.�.� � � �Y� �*�*�*� c �h � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z dd �Z
d
� Zd� Zd� Z
d
� Zd� Zd� Zd� ZdS )�
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 � � | _ |� dd� � | _ |� dd� � | _ |� dd� � | _ |� dd� � | _
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__zChunkScore.__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'