ó <¿CVc@ s6ddlmZddlZdefd„ƒYZdS(iÿÿÿÿ(tdivisionNtDependencyEvaluatorcB s)eZdZd„Zd„Zd„ZRS(s$ 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.8... >>> abs(uas - 0.6) < 0.00001 True cC s||_||_dS(s‰ :param parsed_sents: the list of parsed_sents as the output of parser :type parsed_sents: list(DependencyGraph) N(t _parsed_sentst _gold_sents(tselft parsed_sentst gold_sents((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/evaluate.pyt__init__Gs c s>tdddddddgƒ‰dj‡fd †|DƒƒS( s© Function to remove punctuation from Unicode string. :param input: the input string :return: Unicode string after remove all punctuation tPctPdtPstPetPitPftPotc3 s*|] }tj|ƒˆkr|VqdS(N(t unicodedatatcategory(t.0tx(tpunc_cat(se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/evaluate.pys Vs(tsettjoin(RtinStr((Rse/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/evaluate.pyt _remove_punctOs!c C sƒt|jƒt|jƒkr-tdƒ‚nd}d}d}x/tt|jƒƒD]}|j|j}|j|j}t|ƒt|ƒkr¢tdƒ‚nxÈ|jƒD]º\}}||} |dd krÛq¯n|d| dkrştdƒ‚n|j|dƒdkrq¯n|d7}|d| dkr¯|d7}|d | d kri|d7}qiq¯q¯WqUW||||fS( s† Return the Labeled Attachment Score (LAS) and Unlabeled Attachment Score (UAS) :return : tuple(float,float) sE Number of parsed sentence is different with number of gold sentence.is!Sentences must have equal length.twords!Sentence sequence is not matched.RitheadtrelN( tlenRRt ValueErrortrangetnodestitemstNoneR( RtcorrtcorrLttotaltitparsed_sent_nodestgold_sent_nodestparsed_node_addresst parsed_nodet gold_node((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/evaluate.pytevalXs0   (t__name__t __module__t__doc__RRR+(((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/evaluate.pyRs7  (t __future__RRtobjectR(((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/parse/evaluate.pyt s