+
    ÖÇÜhÑ=  ã                   ó  € R t ^ RIt^ RIt^ RIHt ^ RIHtHtH	t	H
t
HtHt  ! R R]P                  4      t ! R R]P                  4      t ! R R	]P                  4      t ! R
 R]P                  4      t ! R R]P                  4      tR# )z.
Tests for BLEU translation evaluation metric
N)Úfind)ÚSmoothingFunctionÚbrevity_penaltyÚclosest_ref_lengthÚcorpus_bleuÚmodified_precisionÚsentence_bleuc                   ó>   a € ] tR t^t o R tR tR tR tR tRt	V t
R# )ÚTestBLEUc                ó¦  € RP                  4       pRP                  4       pRP                  4       pW.p\        \        WC^R7      4      p\        V^4      R8X  g   Q hV P	                  VR^R7       \        \        WC^R7      4      R8X  g   Q h\        R	4      P                  4       p\        R
4      P                  4       p\        R4      P                  4       pRP                  4       pWV.p\        \        WC^R7      4      R8X  g   Q h\        \        WC^R7      4      R8X  g   Q h\        R4      P                  4       p\        R4      P                  4       pWV.p\        \        WC^R7      4      p\        \        WG^R7      4      pV P	                  VR^R7       V P	                  VR^R7       \        V^4      R8X  g   Q h\        V^4      R8X  g   Q h\        \        WC^R7      4      p	\        \        WG^R7      4      p
V P	                  V	R^R7       V P	                  V
R^R7       \        V	^4      R8X  g   Q h\        V
^4      R8X  g   Q hR# )zU
Examples from the original BLEU paper
https://www.aclweb.org/anthology/P02-1040.pdf
zthe cat is on the matzthere is a cat on the matzthe the the the the the the)Úng›æ§èHÒ?gvi&Œ$IÒ?©Úplacesç        zWIt is a guide to action that ensures that the military will forever heed Party commandszlIt is the guiding principle which guarantees the military forces always being under the command of the PartyzQIt is the practical guide for the army always to heed the directions of the partyzof theç      ð?z^It is a guide to action which ensures that the military always obeys the commands of the partyzSIt is to insure the troops forever hearing the activity guidebook that party directg’Ö‹ã8î?g/Í„‘$Iâ?gñôJY†8î?g›æ§èHâ?gÿåœÐÒÒâ?g):õõ:±³?gû:pÎˆÒâ?grùé·¯³?N)ÚsplitÚfloatr   ÚroundÚassertAlmostEqualÚstr)ÚselfÚref1Úref2Úhyp1Ú
referencesÚhyp1_unigram_precisionÚref3Úhyp2Úhyp2_unigram_precisionÚhyp1_bigram_precisionÚhyp2_bigram_precisions   &          ÚD/usr/lib/python3/dist-packages/nltk/test/unit/translate/test_bleu.pyÚtest_modified_precisionÚ TestBLEU.test_modified_precision   s�  € ð '×,Ñ,Ó.ˆØ*×0Ñ0Ó2ˆà,×2Ñ2Ó4ˆà�\ˆ
ô "'Ô'9¸*ÈaÔ'PÓ!QÐÜÐ+¨QÓ/°6Ô9Ð9Ð9à×ÑÐ5°zÈ!ÐÔLô Ô'¨
¸AÔ>Ó?À3ÔFÐFÐFô ð/ó
÷ ‰%‹'ð 	ô ðAó
÷ ‰%‹'ð 	ô ð*ó
÷ ‰%‹'ð 	ð
 �~‰~Óˆà $Ð'ˆ
äÔ'¨
¸AÔ>Ó?À3ÔFÐFÐFô Ô'¨
¸AÔ>Ó?À3ÔFÐFÐFô ð5ó
÷ ‰%‹'ð 	ô ð*ó
÷ ‰%‹'ð 	ð
  $Ð'ˆ
ô "'Ô'9¸*ÈaÔ'PÓ!QÐÜ!&Ô'9¸*ÈaÔ'PÓ!QÐà×ÑÐ5°zÈ!ÐÔLØ×ÑÐ5°zÈ!ÐÔLäÐ+¨QÓ/°6Ô9Ð9Ð9ÜÐ+¨QÓ/°6Ô9Ð9Ð9ô !&Ô&8¸ÈQÔ&OÓ PÐÜ %Ô&8¸ÈQÔ&OÓ PÐà×ÑÐ4°jÈÐÔKØ×ÑÐ4°jÈÐÔKäÐ*¨AÓ.°&Ô8Ð8Ð8ÜÐ*¨AÓ.°&Ô8Ð8Ò8ó    c                óX  € R .^,          R .^,          .pR .^,          p\        V4      p\        W4      pV P                  \        WC4      R^R7       R .^,          R .^,          R .^,          R .^,          .pR .^,          p\        V4      p\        W4      p\        WC4      R8X  g   Q hR# )Úagvàœ¥½ë?r   r   N)Úlenr   r   r   )r   r   Ú
hypothesisÚhyp_lenÚclosest_ref_lens   &    r!   Útest_brevity_penaltyÚTestBLEU.test_brevity_penaltyd   s°   € ð �e˜b•j 3 %¨!¥)Ð,ˆ
Ø�U˜Q•Yˆ
Ü�j“/ˆÜ,¨ZÓAˆØ×ÑÜ˜OÓ5°vÀað 	ô 	
ð �e˜b•j 3 %¨!¥)¨c¨U°Q­Y¸¸À½	ÐBˆ
Ø�U˜Q•Yˆ
Ü�j“/ˆÜ,¨ZÓAˆÜ˜Ó8¸CÔ?Ð?Ò?r$   c                óÈ   € R P                  4       .pRP                  4       p\        ^\        V4      4       F'  pRV,          3V,          p\        WV4      ^ 8X  d   K'  Q h	  R# )ú7The candidate has no alignment to any of the referencesúJohn loves Maryr   N©r   Úranger'   r   ©r   r   r(   r   Úweightss   &    r!   Útest_zero_matchesÚTestBLEU.test_zero_matchesu   s\   € àO×UÑUÓWÐXˆ
Ø&×,Ñ,Ó.ˆ
ô �qœ#˜j›/Ö*ˆAØ˜Q•w�j 1•nˆGÜ  ¸ÓAÀQÖFÐFÐFó +r$   c                óÈ   € R P                  4       .pR P                  4       p\        ^\        V4      4       F'  pRV,          3V,          p\        WV4      R8X  d   K'  Q h	  R# )r/   r   Nr0   r2   s   &    r!   Útest_full_matchesÚTestBLEU.test_full_matches   s\   € à'×-Ñ-Ó/Ð0ˆ
Ø&×,Ñ,Ó.ˆ
ô �qœ#˜j›/Ö*ˆAØ˜Q•w�j 1•nˆGÜ  ¸ÓAÀSÖHÐHÐHó +r$   c                óÞ   € R P                  4       .pRP                  4       pV P                  \        W4      R^R7        V P                  \        \        W4       R#   \
         d     R# i ; i)r/   zJohn loves Mary who loves Miker   r   N©r   r   r   ÚassertWarnsÚUserWarningÚAttributeError©r   r   r(   s   &  r!   Ú5test_partial_matches_hypothesis_longer_than_referenceÚ>TestBLEU.test_partial_matches_hypothesis_longer_than_reference‰   sg   € Ø'×-Ñ-Ó/Ð0ˆ
Ø5×;Ñ;Ó=ˆ
ð 	×Ñœ}¨ZÓDÀcÐRSÐÔTð	Ø×Ñœ[¬-¸ÖPøÜô 	Úð	úó   Á A ÁA,Á+A,© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r"   r+   r4   r7   r?   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r!   r
   r
      s(   ø‡ € òM9ò^@ò"GòI÷
ð 
r$   r
   c                   óJ   a € ] tR t^—t o R tR tR tR tR tR t	R t
RtV tR	# )
ÚTestBLEUFringeCasesc                ó¢  € R P                  4       .pRP                  4       p\        V4      ^,           pRV,          3V,          pV P                  \        WV4      R^R7        V P	                  \
        \        W4       RP                  4       .pRP                  4       pV P                  \        WV4      R^R7       R#   \         d     LNi ; i)zJohn loves Mary ?r/   r   r   r   N)r   r'   r   r   r;   r<   r=   r2   s   &    r!   Ú2test_case_where_n_is_bigger_than_hypothesis_lengthÚFTestBLEUFringeCases.test_case_where_n_is_bigger_than_hypothesis_length˜   sÐ   € à)×/Ñ/Ó1Ð2ˆ
Ø&×,Ñ,Ó.ˆ
Ü�
‹O˜aÕˆØ˜•7�*˜q•.ˆð 	×ÑÜ˜*°'Ó:¸CÈð 	ô 	
ð	Ø×Ñœ[¬-¸ÔPð (×-Ñ-Ó/Ð0ˆ
Ø&×,Ñ,Ó.ˆ
ð 	×ÑÜ˜*°'Ó:¸CÈð 	ö 	
øô ô 	Ùð	ús   Á$C  Ã CÃCc                óP   € R P                  4       .p. p\        W4      ^ 8X  g   Q hR# )r.   N©r   r   r>   s   &  r!   Útest_empty_hypothesisÚ)TestBLEUFringeCases.test_empty_hypothesis³   s+   € àO×UÑUÓWÐXˆ
Øˆ
Ü˜ZÓ4¸Ô9Ð9Ò9r$   c                ó–   € R P                  4       .pR.p\        4       P                  p \        WVR7       R#   \         d     R# i ; i)r.   ÚFoo)Úsmoothing_functionN)r   r   Úmethod4r   Ú
ValueError)r   r   r(   rW   s   &   r!   Útest_length_one_hypothesisÚ.TestBLEUFringeCases.test_length_one_hypothesis¹   sI   € àO×UÑUÓWÐXˆ
Ø�Wˆ
Ü#Ó%×-Ñ-ˆð	Ü˜*ÀW×MøÜô 	Úð	ús   ª9 ¹AÁAc                óP   € . .pR P                  4       p\        W4      ^ 8X  g   Q hR# )r/   NrQ   r>   s   &  r!   Útest_empty_referencesÚ)TestBLEUFringeCases.test_empty_referencesÃ   s*   € à�Tˆ
Ø&×,Ñ,Ó.ˆ
Ü˜ZÓ4¸Ô9Ð9Ò9r$   c                ó4   € . .p. p\        W4      ^ 8X  g   Q hR# )é    N)r   r>   s   &  r!   Ú$test_empty_references_and_hypothesisÚ8TestBLEUFringeCases.test_empty_references_and_hypothesisÉ   s!   € à�Tˆ
Øˆ
Ü˜ZÓ4¸Ô9Ð9Ò9r$   c                óÞ   € R P                  4       .pRP                  4       pV P                  \        W4      R^R7        V P                  \        \        W4       R#   \
         d     R# i ; i)z	let it goz	let go itr   r   Nr:   r>   s   &  r!   Ú3test_reference_or_hypothesis_shorter_than_fourgramsÚGTestBLEUFringeCases.test_reference_or_hypothesis_shorter_than_fourgramsÏ   si   € ð "×'Ñ'Ó)Ð*ˆ
Ø ×&Ñ&Ó(ˆ
ð 	×Ñœ}¨ZÓDÀcÐRSÐÔTð	Ø×Ñœ[¬-¸ÖPøÜô 	Úð	úrA   c                óª   € R P                  4       .pRP                  4       p\        P                  ! R.^,          4      p\        WV4      ^ 8X  g   Q hR# )r.   r/   ç      Ð?N)r   ÚnpÚarrayr   )r   r   r(   r3   s   &   r!   Útest_numpy_weightsÚ&TestBLEUFringeCases.test_numpy_weightsÝ   sJ   € àO×UÑUÓWÐXˆ
Ø&×,Ñ,Ó.ˆ
ä—(’(˜D˜6 A�:Ó&ˆÜ˜Z°WÓ=ÀÔBÐBÒBr$   rB   N)rC   rD   rE   rF   rN   rR   rY   r\   r`   rc   ri   rG   rH   rI   s   @r!   rL   rL   —   s/   ø‡ € ò
ò6:òò:ò:ò÷Cð Cr$   rL   c                   ó&   a € ] tR t^æt o R tRtV tR# )ÚTestBLEUvsMteval13ac                óª  € \        R 4      p\        R4      p\        R4      p\        V4      ;_uu_ 4       p\        \        VP	                  4       R,          P                  4       ^R 4      pRRR4       \        VRR7      ;_uu_ 4       p\        VRR7      ;_uu_ 4       p\        \        R V4      4      p\        \        R V4      4      p	\        \        ^^
4      X4       F9  w  r«\        W˜RV
,          3V
,          R	7      p\        W¼,
          4      R
8  d   K9  Q h	  \        4       p\        \        ^^
4      V4       FE  w  r«\        V	VRV
,          3V
,          VP                  R7      p\        W¼,
          4      R
8  d   KE  Q h	  RRR4       RRR4       R#   + '       g   i     EL7; i  + '       g   i     L.; i  + '       g   i     R# ; i)zmodels/wmt15_eval/ref.ruzmodels/wmt15_eval/google.ruz#models/wmt15_eval/mteval-13a.outputNÚutf8)Úencodingc                 ó"   € V P                  4       # ©N©r   ©Úxs   &r!   Ú<lambda>Ú6TestBLEUvsMteval13a.test_corpus_bleu.<locals>.<lambda>÷   s
   € °·±´	r$   c                 ó$   € V P                  4       .# rq   rr   rs   s   &r!   ru   rv   ù   s   € °·±³±r$   r   )r3   g{®Gázt?)r3   rV   éþÿÿÿéÿÿÿÿ)r   ÚopenÚmapr   Ú	readlinesr   ÚlistÚzipr1   r   Úabsr   Úmethod3)r   Úref_fileÚhyp_fileÚmteval_output_fileÚ
mteval_finÚmteval_bleu_scoresÚref_finÚhyp_finr(   r   ÚiÚmteval_bleuÚ	nltk_bleuÚ
chencherrys   &             r!   Útest_corpus_bleuÚ$TestBLEUvsMteval13a.test_corpus_bleuç   sŠ  € ÜÐ2Ó3ˆÜÐ5Ó6ˆÜ!Ð"GÓHÐô Ð$×%Ô%¨ô "%¤U¨J×,@Ñ,@Ó,BÀ2Õ,F×,LÑ,LÓ,NÈqÐQSÐ,TÓ!UÐ÷ &ô
 �( V×,Õ,°Ü�h¨×0Õ0°Gô "¤#Ñ&9¸7Ó"CÓD�
ä!¤#Ñ&;¸WÓ"EÓF�
ä&)¬%°°2«,Ð8JÖ&K‘N�AÜ +Ø"¸¸q½¸
ÀQ½ô!�Iô ˜{Õ6Ó7¸%Ö?Ð?Ð?ñ 'Lô /Ó0�
Ü&)¬%°°2«,Ð8JÖ&K‘N�AÜ +Ø"Ø"Ø!$ q¥ 
¨Q¥Ø+5×+=Ñ+=ô	!�Iô ˜{Õ6Ó7¸%Ö?Ð?Ð?ñ 'L÷' 1÷ -Ñ,÷ &×%Ð%ú÷ 1×0ú÷ -×,Ð,ús=   µ7FÂ	GÂA7F.	ÄA$F.	ÆF.	ÆGÆF+	Æ.F>Æ9GÇG	rB   N)rC   rD   rE   rF   rŒ   rG   rH   rI   s   @r!   rl   rl   æ   s   ø‡ € ÷'@ð '@r$   rl   c                   ó&   a € ] tR tRt o R tRtV tR# )ÚTestBLEUWithBadSentencei  c                ót  € R p\        R4      pVP                  4       ..pVP                  4       .p V P                  \        4      ;_uu_ 4        V P	                  \        W44      R^R7       RRR4       R#   + '       g   i     R# ; i  \         d"    T P	                  \        Y44      R^R7        R# i ; i)zQTeo S yb , oe uNb , R , T t , , t Tue Ar saln S , , 5istsi l , 5oe R ulO sae oR Rz›Their tasks include changing a pump on the faulty stokehold .Likewise , two species that are very similar in morphology were distinguished using genetics .r   r   N)r   r   r;   r<   r   r   r=   )r   ÚhypÚrefr   Ú
hypothesess   &    r!   Ú"test_corpus_bleu_with_bad_sentenceÚ:TestBLEUWithBadSentence.test_corpus_bleu_with_bad_sentence  s¨   € ØaˆÜð2ó
ˆð
 —y‘y“{�m�_ˆ
Ø—i‘i“k�]ˆ
ð		WØ×!Ñ!¤+×.Õ.à×&Ñ&Ü 
Ó7¸ÀQð 'ô ÷ /×.×.Ò.ûô ô	Wð ×"Ñ"¤;¨zÓ#FÈÐTUÐ"×Vð	Wús/   ²B ÁA7Á-B Á7B	ÂB ÂB Â(B7Â6B7rB   N)rC   rD   rE   rF   r”   rG   rH   rI   s   @r!   r�   r�     s   ø‡ € ÷Wð Wr$   r�   c                   ó&   a € ] tR tRt o R tRtV tR# )ÚTestBLEUWithMultipleWeightsi'  c                ó4  € . ROp. ROp. ROp. ROp. ROp. ROpR	pR
pRp	\        W#V.V..W.WxV	.R7      p
V
^ ,          \        W#V.V..W.V4      8X  g   Q hV
^,          \        W#V.V..W.V4      8X  g   Q hV
^,          \        W#V.V..W.V	4      8X  g   Q hR# )ÚIt)Úlist_of_referencesr“   r3   N)r™   Úisr&   ÚguideÚtoÚactionÚwhichÚensuresÚthatÚtheÚmilitaryÚalwaysÚobeysr¢   ÚcommandsÚofr¢   Úparty)r™   r›   r&   rœ   r�   rž   r¡   r    r¡   r¢   r£   ÚwillÚforeverÚheedÚPartyr¦   )r™   r›   r¢   ÚguidingÚ	principlerŸ   Ú
guaranteesr¢   r£   Úforcesr¤   ÚbeingÚunderr¢   Úcommandr§   r¢   r¬   )r™   r›   r¢   Ú	practicalrœ   Úforr¢   Úarmyr¤   r�   r«   r¢   Ú
directionsr§   r¢   r¨   )ÚheÚreadr¢   ÚbookÚbecauser¸   ÚwasÚ
interestedÚinÚworldÚhistory)r¸   r¼   r½   r¾   r¿   rÀ   r»   r¸   r¹   r¢   rº   )é   r_   r_   r_   )rf   rf   rf   rf   )r_   r_   r_   r_   rÁ   )r   )r   r   Úref1aÚref1bÚref1cr   Úref2aÚweight_1Úweight_2Úweight_3Úbleu_scoress   &          r!   Ú&test_corpus_bleu_with_multiple_weightsÚBTestBLEUWithMultipleWeights.test_corpus_bleu_with_multiple_weights(  sÿ   € ò
ˆò(
ˆò$
ˆò(
ˆò$
ˆò
ˆð  ˆØ+ˆØ"ˆä!Ø!&¨uÐ 5¸°wÐ?Ø�|Ø¨Ð2ô
ˆð
 ˜1�~¤Ø˜EÐ" U GÐ,¨t¨l¸Hó"
ô 
ð 	
ð 
ð ˜1�~¤Ø˜EÐ" U GÐ,¨t¨l¸Hó"
ô 
ð 	
ð 
ð ˜1�~¤Ø˜EÐ" U GÐ,¨t¨l¸Hó"
ô 
ð 	
ò 
r$   rB   N)rC   rD   rE   rF   rÊ   rG   rH   rI   s   @r!   r—   r—   '  s   ø‡ € ÷x
ð x
r$   r—   )Ú__doc__ÚunittestÚnumpyrg   Ú	nltk.datar   Únltk.translate.bleu_scorer   r   r   r   r   r   ÚTestCaser
   rL   rl   r�   r—   rB   r$   r!   Ú<module>rÒ      sˆ   ðñó ã å ÷÷ ôˆx× Ñ ô ôFLC˜(×+Ñ+ô LCô^(@˜(×+Ñ+ô (@ôVW˜h×/Ñ/ô Wô,y
 (×"3Ñ"3ö y
r$   