
    /h                          S SK r  " S S5      rg)    Nc                   *    \ rS rSrSrS rS rS rSrg)DependencyEvaluator   ae  
Class for measuring labelled and unlabelled attachment score for
dependency parsing. Note that the evaluation ignores punctuation.

>>> from nltk.parse import DependencyGraph, DependencyEvaluator

>>> gold_sent = DependencyGraph("""
... Pierre  NNP     2       NMOD
... Vinken  NNP     8       SUB
... ,       ,       2       P
... 61      CD      5       NMOD
... years   NNS     6       AMOD
... old     JJ      2       NMOD
... ,       ,       2       P
... will    MD      0       ROOT
... join    VB      8       VC
... the     DT      11      NMOD
... board   NN      9       OBJ
... as      IN      9       VMOD
... a       DT      15      NMOD
... nonexecutive    JJ      15      NMOD
... director        NN      12      PMOD
... Nov.    NNP     9       VMOD
... 29      CD      16      NMOD
... .       .       9       VMOD
... """)

>>> parsed_sent = DependencyGraph("""
... Pierre  NNP     8       NMOD
... Vinken  NNP     1       SUB
... ,       ,       3       P
... 61      CD      6       NMOD
... years   NNS     6       AMOD
... old     JJ      2       NMOD
... ,       ,       3       AMOD
... will    MD      0       ROOT
... join    VB      8       VC
... the     DT      11      AMOD
... board   NN      9       OBJECT
... as      IN      9       NMOD
... a       DT      15      NMOD
... nonexecutive    JJ      15      NMOD
... director        NN      12      PMOD
... Nov.    NNP     9       VMOD
... 29      CD      16      NMOD
... .       .       9       VMOD
... """)

>>> de = DependencyEvaluator([parsed_sent],[gold_sent])
>>> las, uas = de.eval()
>>> las
0.6
>>> uas
0.8
>>> abs(uas - 0.8) < 0.00001
True
c                     Xl         X l        g)zq
:param parsed_sents: the list of parsed_sents as the output of parser
:type parsed_sents: list(DependencyGraph)
N)_parsed_sents_gold_sents)selfparsed_sents
gold_sentss      K/var/www/auris/envauris/lib/python3.13/site-packages/nltk/parse/evaluate.py__init__DependencyEvaluator.__init__G   s    
 *%    c                 B   ^ 1 SkmSR                  U4S jU 5       5      $ )z
Function to remove punctuation from Unicode string.
:param input: the input string
:return: Unicode string after remove all punctuation
>   PcPdPePfPiPoPs c              3   `   >#    U  H#  n[         R                  " U5      T;  d  M  Uv   M%     g 7f)N)unicodedatacategory).0xpunc_cats     r   	<genexpr>4DependencyEvaluator._remove_punct.<locals>.<genexpr>V   s%     S%Q;+?+?+B(+Rqq%s   .	.)join)r	   inStrr   s     @r   _remove_punct!DependencyEvaluator._remove_punctO   s     >wwS%SSSr   c                    [        U R                  5      [        U R                  5      :w  a  [        S5      eSnSnSn[	        [        U R                  5      5       H  nU R                  U   R
                  nU R                  U   R
                  n[        U5      [        U5      :w  a  [        S5      eUR                  5        Hm  u  pxXg   n	US   c  M  US   U	S   :w  a  [        S5      eU R                  US   5      S:X  a  MB  US-  nUS   U	S   :X  d  MU  US-  nUS	   U	S	   :X  d  Mh  US-  nMo     M     X#-  X-  4$ )
zn
Return the Labeled Attachment Score (LAS) and Unlabeled Attachment Score (UAS)

:return : tuple(float,float)
zE Number of parsed sentence is different with number of gold sentence.r   z!Sentences must have equal length.wordz!Sentence sequence is not matched.r      headrel)lenr   r   
ValueErrorrangenodesitemsr#   )
r	   corrcorrLtotaliparsed_sent_nodesgold_sent_nodesparsed_node_addressparsed_node	gold_nodes
             r   evalDependencyEvaluator.evalX   sb    t!!"c$*:*:&;;W  s4--./A $ 2 21 5 ; ;"..q177O$%_)== !DEE4E4K4K4M0#+@	v&.v&)F*;;$%HII %%k&&9:b@
v&)F*;;AID"5)Yu-==
# 5N 04 }dl**r   )r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r#   r8   __static_attributes__ r   r   r   r      s    8t&T)+r   r   )r   r   r@   r   r   <module>rA      s    u+ u+r   