+
    ÖÇÜh  ã                   óL   € R t ^ RIt^ RIt^ RIHt ^ RIHt RR ltRR ltR t	R# )zNIST score implementation.N)ÚCounter)Úngramsc                ó    € \        V .V.V4      # )aW  
Calculate NIST score from
George Doddington. 2002. "Automatic evaluation of machine translation quality
using n-gram co-occurrence statistics." Proceedings of HLT.
Morgan Kaufmann Publishers Inc. https://dl.acm.org/citation.cfm?id=1289189.1289273

DARPA commissioned NIST to develop an MT evaluation facility based on the BLEU
score. The official script used by NIST to compute BLEU and NIST score is
mteval-14.pl. The main differences are:

 - BLEU uses geometric mean of the ngram overlaps, NIST uses arithmetic mean.
 - NIST has a different brevity penalty
 - NIST score from mteval-14.pl has a self-contained tokenizer

Note: The mteval-14.pl includes a smoothing function for BLEU score that is NOT
      used in the NIST score computation.

>>> hypothesis1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'which',
...               'ensures', 'that', 'the', 'military', 'always',
...               'obeys', 'the', 'commands', 'of', 'the', 'party']

>>> hypothesis2 = ['It', 'is', 'to', 'insure', 'the', 'troops',
...               'forever', 'hearing', 'the', 'activity', 'guidebook',
...               'that', 'party', 'direct']

>>> reference1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'that',
...               'ensures', 'that', 'the', 'military', 'will', 'forever',
...               'heed', 'Party', 'commands']

>>> reference2 = ['It', 'is', 'the', 'guiding', 'principle', 'which',
...               'guarantees', 'the', 'military', 'forces', 'always',
...               'being', 'under', 'the', 'command', 'of', 'the',
...               'Party']

>>> reference3 = ['It', 'is', 'the', 'practical', 'guide', 'for', 'the',
...               'army', 'always', 'to', 'heed', 'the', 'directions',
...               'of', 'the', 'party']

>>> sentence_nist([reference1, reference2, reference3], hypothesis1) # doctest: +ELLIPSIS
3.3709...

>>> sentence_nist([reference1, reference2, reference3], hypothesis2) # doctest: +ELLIPSIS
1.4619...

:param references: reference sentences
:type references: list(list(str))
:param hypothesis: a hypothesis sentence
:type hypothesis: list(str)
:param n: highest n-gram order
:type n: int
)Úcorpus_nist)Ú
referencesÚ
hypothesisÚns   &&&Ú;/usr/lib/python3/dist-packages/nltk/translate/nist_score.pyÚsentence_nistr
      s   € ôh ˜
�| j \°1Ó5Ð5ó    c           	     ó  a€ \        V 4      \        V4      8X  g   Q R4       h\        4       p^ pV  FR  pV FI  p\        ^V^,           4       F  pVP                  \	        Wg4      4       K  	  V\        V4      ,          pKK  	  KT  	  / oV FH  pVRR p	V	'       d   W“9   d
   W9,          p
MTp
\
        P                  ! W£V,          ,          ^4      SV&   KJ  	  \        4       p\        4       p^ ^ rí\        ^V^,           4       EFM  p\        W4       EF9  w  r_\        V4      p. pV FÖ  p\        V4      p\        V4      V8¼  d   \        \	        W÷4      4      M	\        4       p\        V4      V8¼  d   \        \	        Wg4      4      M	\        4       pVV,          p\        V3R lVP                  4        4       4      p\        VP                  4       4      pV^ 8X  d   ^ MVV,          pVP                  VVVV34       KØ  	  \        V4      w  pp
ppW·;;,          V
,          uu&   WÇ;;,          V,          uu&   VV,          pVV,          pEK<  	  EKP  	  ^ pV F!  pW·,          WÇ,          ,          pVV,          pK#  	  V\        WÞ4      ,          # )au  
Calculate a single corpus-level NIST score (aka. system-level BLEU) for all
the hypotheses and their respective references.

:param references: a corpus of lists of reference sentences, w.r.t. hypotheses
:type references: list(list(list(str)))
:param hypotheses: a list of hypothesis sentences
:type hypotheses: list(list(str))
:param n: highest n-gram order
:type n: int
zBThe number of hypotheses and their reference(s) should be the sameNc              3   óH   <"  € T F  w  rSV,          V,          x € K  	  R # 5i)N© )Ú.0Ú_ngramÚcountÚinformation_weightss   &  €r	   Ú	<genexpr>Úcorpus_nist.<locals>.<genexpr>‘   s'   øé € ð !á)?™˜ð (¨Õ/°%×7Ò7Û)?ùs   ƒ"éÿÿÿÿ)Úlenr   ÚrangeÚupdater   ÚmathÚlogÚzipÚsumÚitemsÚvaluesÚappendÚmaxÚnist_length_penalty)Úlist_of_referencesÚ
hypothesesr   Ú
ngram_freqÚtotal_reference_wordsr   Ú	referenceÚir   Ú_mgramÚ	numeratorÚ"nist_precision_numerator_per_ngramÚ$nist_precision_denominator_per_ngramÚl_refÚl_sysr   Úhyp_lenÚnist_score_per_refÚ_ref_lenÚ
hyp_ngramsÚ
ref_ngramsÚngram_overlapsÚ
_numeratorÚ_denominatorÚ
_precisionÚ	precisionÚdenominatorÚref_lenÚnist_precisionr   s   &&&                          @r	   r   r   I   sŒ  ø€ ô Ð!Ó"¤cØó'ô ð LàKóLð ô
 “€JØÐó 
ð 	ã#ˆIä˜1˜a !�e–_�Ø×!Ñ!¤&¨Ó"6Ö7ñ %à!¤S¨£^Õ3Ò!ó	 $ñ 
ð ÐÛˆØ˜˜�ˆ÷ �fÔ*Ø"Õ*‰Ià-ˆIÜ&*§h¢h¨yÀfÕ;MÕ/MÈqÓ&QÐ˜FÓ#ñ ô *1«Ð&Ü+2«9Ð(Ø�aˆ5ä�1�a˜!•e�_ˆä&)Ð*<×&IÑ"ˆJÜ˜*“oˆGð "$ÐÛ'�	Ü˜y›>�ô ˜:“¨!Ô+ô œF :Ó1Ô2ä ›ð ô 69¸³^ÀqÔ5H”GœF 9Ó0Ô1ÌgËið ð ",¨jÕ!8�ä ô !à)7×)=Ñ)=Ô)?ó!ó �
ô  # :×#4Ñ#4Ó#6Ó7�Ø".°!Ô"3™Q¸ÀlÕ9R�
Ø"×)Ñ)Ø ¨\¸8ÐDöñ' (ô. :=Ð=OÓ9PÑ6ˆI�y +¨wØ.×1°YÕ>Ó1Ø0×3°{ÕBÓ3Ø�WÕˆEØ�WÕ‹EôA 'Jñ ðJ €NÛ/ˆà.Õ1Ø2Õ5õ6ð 	ð 	˜)Õ#Šñ 0ð Ô/°Ó=Õ=Ð=r   c                óH  € W,          p^ Tu;8  d   ^8  dw   M MsRRrC\         P                  ! V4      \         P                  ! V4      ^,          ,          p\         P                  ! V\         P                  ! V4      ^,          ,          4      # \        \	        VR4      R4      # )aú  
Calculates the NIST length penalty, from Eq. 3 in Doddington (2002)

    penalty = exp( beta * log( min( len(hyp)/len(ref) , 1.0 )))

where,

    `beta` is chosen to make the brevity penalty factor = 0.5 when the
    no. of words in the system output (hyp) is 2/3 of the average
    no. of words in the reference translation (ref)

The NIST penalty is different from BLEU's such that it minimize the impact
of the score of small variations in the length of a translation.
See Fig. 4 in  Doddington (2002)
g      ø?g      à?g      ð?g        )r   r   Úexpr    Úmin)r9   r.   ÚratioÚratio_xÚscore_xÚbetas   &&    r	   r!   r!   ­   ss   € ð  Õ€EØˆ5†}�1‡}Ø �Ü�xŠx˜Ó ¤4§8¢8¨GÓ#4¸Õ#9Õ9ˆÜ�xŠx˜œtŸxšx¨›°!Õ3Õ3Ó4Ð4ä”3�u˜c“? CÓ(Ð(r   )é   )
Ú__doc__Ú	fractionsr   Úcollectionsr   Ú	nltk.utilr   r
   r   r!   r   r   r	   Ú<module>rG      s(   ðñ !ã Û Ý å ô46ôna>ôH)r   