+
    ÖÇÜhê%  ã                   óÈ   € R t ^ RIt^ RIHt ^ RIHt ^ RIHtHt ^ RI	H
t
Ht  ! R R]P                  4      t ! R R	]P                  4      t ! R
 R]P                  4      tR# )z
Tests for stack decoder
N)Údefaultdict)Úlog)ÚPhraseTableÚStackDecoder)Ú_HypothesisÚ_Stackc                   ój   a € ] tR t^t o R tR tR tR tR tR t	R t
]R 4       t]R	 4       tR
tV tR# )ÚTestStackDecoderc                ó¢  € \         P                  4       p\        VR 4      pRpVP                  V4      pV P	                  V^ ,          ^.4       V P	                  V^,          ^.4       V P	                  V^,          ^.4       V P	                  V^,          ^^.4       V P                  V^,          4       V P	                  V^,          ^.4       R # )N©ÚmyÚ
hovercraftÚisÚfullÚofÚeels)r	   Úcreate_fake_phrase_tabler   Úfind_all_src_phrasesÚassertEqualÚassertFalse)ÚselfÚphrase_tableÚstack_decoderÚsentenceÚsrc_phrase_spanss   &    ÚM/usr/lib/python3/dist-packages/nltk/test/unit/translate/test_stack_decoder.pyÚtest_find_all_src_phrasesÚ*TestStackDecoder.test_find_all_src_phrases   sÄ   € ä'×@Ñ@ÓBˆÜ$ \°4Ó8ˆØCˆð )×=Ñ=¸hÓGÐð 	×ÑÐ)¨!Õ,¨q¨cÔ2Ø×ÑÐ)¨!Õ,¨q¨cÔ2Ø×ÑÐ)¨!Õ,¨q¨cÔ2Ø×ÑÐ)¨!Õ,¨q°!¨fÔ5Ø×ÑÐ)¨!Õ,Ô-Ø×ÑÐ)¨!Õ,¨q¨cÖ2ó    c                óÌ   € \        R R 4      pRVn        \        4       pRVn        VP	                  VR4      p\        VP                  4      ^,          pV P                  W44       R # )Nç      à?©é   é   ©é   é
   )r   Údistortion_factorr   Úsrc_phrase_spanÚdistortion_scorer   r   )r   r   Ú
hypothesisÚscoreÚexpected_scores   &    r   Útest_distortion_scoreÚ&TestStackDecoder.test_distortion_score&   s^   € ä$ T¨4Ó0ˆØ*-ˆÔ'Ü “]ˆ
Ø%+ˆ
Ô"ð ×.Ñ.¨z¸7ÓCˆô ˜]×<Ñ<Ó=ÀÕGˆØ×Ñ˜Ö/r   c                óˆ   € \        R R 4      pRVn        \        4       pVP                  VR4      pV P	                  VR4       R # )Nr    ç        r$   )r   r'   r   r)   r   )r   r   r*   r+   s   &   r   Ú(test_distortion_score_of_first_expansionÚ9TestStackDecoder.test_distortion_score_of_first_expansion4   sC   € ä$ T¨4Ó0ˆØ*-ˆÔ'Ü “]ˆ
ð ×.Ñ.¨z¸7ÓCˆð 	×Ñ˜ Ö$r   c                óê  € \         P                  4       p\         P                  4       p\        W4      pRpVP	                  V4      pV P                  V^,          ^,          VP                  R4      ^ ,          P                  VP                  R4      ,           4       V P                  V^ ,          ^,          VP                  R4      ^ ,          P                  VP                  R4      ,           4       R# )r   Nr   ©r   ©r   r   )	r	   r   Úcreate_fake_language_modelr   Úcompute_future_scoresr   Útranslations_forÚlog_probÚprobability©r   r   Úlanguage_modelr   r   Úfuture_scoress   &     r   Útest_compute_future_costsÚ*TestStackDecoder.test_compute_future_costsA   sÔ   € ä'×@Ñ@ÓBˆÜ)×DÑDÓFˆÜ$ \ÓBˆØCˆð &×;Ñ;¸HÓEˆð 	×ÑØ˜!Õ˜QÕà×-Ñ-¨oÓ>¸qÕA×JÑJØ ×,Ñ,¨_Ó=õ>ô	
ð 	×ÑØ˜!Õ˜QÕà×-Ñ-Ð.BÓCÀAÕF×OÑOØ ×,Ñ,Ð-AÓBõCö	
r   c                ó  € \         P                  4       p\         P                  4       p\        W4      pRpVP	                  V4      pV P                  V^,          ^,          V^,          ^,          V^,          ^,          ,           4       R# )r   Nr   )r	   r   r6   r   r7   r   r;   s   &     r   Ú9test_compute_future_costs_for_phrases_not_in_phrase_tableÚJTestStackDecoder.test_compute_future_costs_for_phrases_not_in_phrase_table[   sx   € ä'×@Ñ@ÓBˆÜ)×DÑDÓFˆÜ$ \ÓBˆØCˆð &×;Ñ;¸HÓEˆð 	×ÑØ˜!Õ˜QÕØ˜!Õ˜QÕ -°Õ"2°1Õ"5Õ5ö	
r   c                óÒ   € \        4       pR  Vn        \        R 4      pRV^ ,          ^&   RV^,          ^&   \        RR4      pVP	                  W^4      pV P                  VR4       R# )c                 ó
   € RR.# )é    ©rE   é   )r#   r%   © ©Ú_s   &r   Ú<lambda>Ú4TestStackDecoder.test_future_score.<locals>.<lambda>n   ó	   € °6¸6Ñ2Br   c                  ó    € \        \        4      # ©N)r   ÚfloatrH   r   r   rK   rL   o   s	   € ´¼UÔ1Cr   çš™™™™™Ù?r    NçÍÌÌÌÌÌì?)r   Úuntranslated_spansr   r   Úfuture_scorer   )r   r*   Úfuture_score_tabler   rT   s   &    r   Útest_future_scoreÚ"TestStackDecoder.test_future_scorek   sp   € ä “]ˆ
Ù(Bˆ
Ô%Ü(Ñ)CÓDÐØ#&Ð˜1Õ˜aÑ Ø#&Ð˜1Õ˜aÑ Ü$ T¨4Ó0ˆð %×1Ñ1°*ÐRSÓTˆð 	×Ñ˜ yÖ1r   c                óž   € \        4       pR  Vn        ^^.^.. ^.. RO. ^..p\        P                  ! W!4      pV P	                  V. RO4       R# )c                 ó
   € RR.# )rE   rF   )r"   é   rH   rI   s   &r   rK   Ú5TestStackDecoder.test_valid_phrases.<locals>.<lambda>~   rM   r   N)r#   rZ   é   )©rE   é   ©r^   rG   r!   )é   r#   )r`   rZ   )r   rS   r   Úvalid_phrasesr   )r   r*   Úall_phrases_fromÚphrase_spanss   &   r   Útest_valid_phrasesÚ#TestStackDecoder.test_valid_phrasesz   sV   € ä “]ˆ
á(Bˆ
Ô%Ø ˜F Q C¨¨a¨S²)¸RÀ!ÀÐEÐô $×1Ò1Ð2BÓOˆð 	×Ñ˜Ò'OÖPr   c                 ó–  € \        4       p V P                  RRR4       V P                  RRR4       V P                  R	RR4       V P                  R
RR4       V P                  R
RR4       V P                  RRR4       V P                  RRR4       V P                  RRR4       V P                  RRR4       V P                  RRR4       V # )r   gš™™™™™é?gffffffæ?r    ç{®Gáz„?r4   )Ú r5   )rh   rh   )r   Úcheese©r   )r   r   )r   r   r   )rh   rh   rh   )r   r   Úspam©r   )rk   )r   Úadd)r   s    r   r   Ú)TestStackDecoder.create_fake_phrase_table‡   sÇ   € ä"“}ˆØ×Ñ˜¨%°Ô5Ø×ÑÐ-¨x¸Ô=Ø×ÑÐ)¨8°SÔ9Ø×Ñ˜ %¨Ô-Ø×Ñ˜ %¨Ô-Ø×Ñ˜¨°4Ô8Ø×ÑÐ/°¸sÔCØ×ÑÐ/°¸3Ô?Ø×Ñ˜ E¨3Ô/Ø×Ñ˜ E¨3Ô/ØÐr   c                 ó  a€ \        R  4      o\        R4      SR&   \        R4      SR&   \        R4      SR&   \        R4      SR	&   \        R4      SR
&   \        R4      SR&   \        R4      SR&   \        R\        3RV3R l/4      ! 4       p V # )c                  ó   € R# )g     8�@g     8�ÀrH   rH   r   r   rK   Ú=TestStackDecoder.create_fake_language_model.<locals>.<lambda>™   s   € ©Fr   çš™™™™™¹?ç333333Ó?rh   r:   c                 ó   <€ SV,          # rO   rH   )rJ   ÚphraseÚlanguage_probs   &&€r   rK   rq   ¢   s
   ø€ ¸]È6Ö=Rr   )r   r4   rj   )r   )r   rl   r5   )r   r   ÚtypeÚobject)r<   rv   s    @r   r6   Ú+TestStackDecoder.create_fake_language_model–   s˜   ø€ ô $¡NÓ3ˆÜ!$ S£ˆ�gÑÜ),¨S«ˆ�oÑ&Ü!$ S£ˆ�gÑÜ#& s£8ˆ�iÑ Ü!$ S£ˆ�gÑÜ#& s£8ˆ�iÑ Ü.1°#«hˆÐ*Ñ+ÜØ”�	˜MÔ+RÐSô
ó ˆð Ðr   rH   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r-   r1   r>   rA   rV   rd   Ústaticmethodr   r6   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r	   r	      sQ   ø‡ € ò3ò"0ò%ò
ò4
ò 2òQð ñó ðð ñó ö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	# )
ÚTestHypothesisc                ób   € \        4       p\        R RRVR7      p\        RRRVR7      pW0n        R# )r    )Ú	raw_scorer(   Ú
trg_phraseÚpreviousrQ   N)r"   r\   )ÚhelloÚworldr_   )ÚandÚgoodbye)r   Úhypothesis_chain)r   ÚrootÚchildÚ
grandchilds   &   r   ÚsetUpÚTestHypothesis.setUp¨   s?   € Ü‹}ˆÜØØ"Ø)Øô	
ˆô !ØØ"Ø)Øô	
ˆ
ð !+Ör   c                ób   € V P                   P                  4       pV P                  V. RO4       R# )r‰   N)r‰   rŠ   r‹   rŒ   )r�   Útranslation_so_farr   )r   Útranslations   & r   Útest_translation_so_farÚ&TestHypothesis.test_translation_so_far¸   s)   € à×+Ñ+×>Ñ>Ó@ˆð 	×Ñ˜Ò&JÖKr   c                ó^   € \        4       pVP                  4       pV P                  V. 4       R # rO   )r   r”   r   )r   r*   r•   s   &  r   Ú,test_translation_so_far_for_empty_hypothesisÚ;TestHypothesis.test_translation_so_far_for_empty_hypothesis¿   s+   € ä “]ˆ
ð !×3Ñ3Ó5ˆð 	×Ñ˜ bÖ)r   c                ó^   € V P                   P                  4       pV P                  V^4       R# )r#   N)r�   Útotal_translated_wordsr   )r   rœ   s   & r   Útest_total_translated_wordsÚ*TestHypothesis.test_total_translated_wordsÉ   s*   € à!%×!6Ñ!6×!MÑ!MÓ!OÐð 	×ÑÐ/°Ö3r   c                ó‚   € V P                   P                  4       pVP                  4        V P                  V. RO4       R# )r^   N)r^   r"   r`   r#   rZ   )r�   Útranslated_positionsÚsortr   )r   r    s   & r   Útest_translated_positionsÚ(TestHypothesis.test_translated_positionsÐ   s6   € à#×4Ñ4×IÑIÓKÐð 	×!Ñ!Ô#Ø×ÑÐ-ªÖ?r   c                ód   € V P                   P                  ^
4      pV P                  V. RO4       R# )r&   N)r]   )rG   r"   )r\   r&   )r�   rS   r   )r   rS   s   & r   Útest_untranslated_spansÚ&TestHypothesis.test_untranslated_spansØ   s-   € à!×2Ñ2×EÑEÀbÓIÐð 	×ÑÐ+Ò-FÖGr   c                ób   € \        4       pVP                  ^
4      pV P                  VR.4       R# )r&   N)rE   r&   )r   rS   r   )r   r*   rS   s   &  r   Ú,test_untranslated_spans_for_empty_hypothesisÚ;TestHypothesis.test_untranslated_spans_for_empty_hypothesisß   s1   € ä “]ˆ
ð (×:Ñ:¸2Ó>Ðð 	×ÑÐ+¨g¨YÖ7r   )r�   N)rz   r{   r|   r}   r‘   r–   r™   r�   r¢   r¥   r¨   r   r€   r�   s   @r   r„   r„   §   s0   ø‡ € ò+ò Lò*ò4ò@òH÷8ð 8r   r„   c                   ó>   a € ] tR t^êt o R tR tR tR tR tRt	V t
R# )Ú	TestStackc                ó  € \        ^4      p\        R4      pVP                  \        R4      4       VP                  V4       VP                  \        R4      4       VP                  \        R4      4       V P                  W!9   4       R# )r"   rg   gš™™™™™É?rr   rs   N©r   r   Úpushr   ©r   ÚstackÚpoor_hypothesiss   &  r   Ú7test_push_bumps_off_worst_hypothesis_when_stack_is_fullÚATestStack.test_push_bumps_off_worst_hypothesis_when_stack_is_fullë   si   € ä�q“	ˆÜ% dÓ+ˆð 	�
‰
”;˜sÓ#Ô$Ø�
‰
�?Ô#Ø�
‰
”;˜sÓ#Ô$Ø�
‰
”;˜sÓ#Ô$ð 	×Ñ˜Ñ1Ö2r   c                ó  € \        ^R4      p\        R4      p\        R4      pVP                  V4       VP                  V4       VP                  \        R4      4       V P                  W!9   4       V P                  W19   4       R# )r"   r    rg   g;ßO�—n‚?rR   Nr­   )r   r°   r±   Úworse_hypothesiss   &   r   Ú;test_push_removes_hypotheses_that_fall_below_beam_thresholdÚETestStack.test_push_removes_hypotheses_that_fall_below_beam_thresholdù   ss   € ä�q˜#“ˆÜ% dÓ+ˆÜ& uÓ-Ðð 	�
‰
�?Ô#Ø�
‰
Ð#Ô$Ø�
‰
”;˜sÓ#Ô$ð 	×Ñ˜Ñ1Ô2Ø×ÑÐ)Ñ2Ö3r   c                ó°   € \        ^R4      p\        R4      pVP                  \        R4      4       VP                  V4       V P                  W!9   4       R# )r"   r    rg   rR   Nr­   r¯   s   &  r   ÚAtest_push_does_not_add_hypothesis_that_falls_below_beam_thresholdÚKTestStack.test_push_does_not_add_hypothesis_that_falls_below_beam_threshold  sI   € ä�q˜#“ˆÜ% dÓ+ˆð 	�
‰
”;˜sÓ#Ô$Ø�
‰
�?Ô#ð 	×Ñ˜Ñ1Ö2r   c                óü   € \        ^4      p\        R4      pVP                  \        R4      4       VP                  V4       VP                  \        R4      4       V P                  VP	                  4       V4       R# )r"   g®Gáz®ï?r0   r    N)r   r   r®   r   Úbest)r   r°   Úbest_hypothesiss   &  r   Ú%test_best_returns_the_best_hypothesisÚ/TestStack.test_best_returns_the_best_hypothesis  s]   € ä�q“	ˆÜ% dÓ+ˆð 	�
‰
”;˜sÓ#Ô$Ø�
‰
�?Ô#Ø�
‰
”;˜sÓ#Ô$ð 	×Ñ˜Ÿ™› Ö7r   c                ó\   € \        ^4      pV P                  VP                  4       R4       R# )r"   N)r   r   r¼   )r   r°   s   & r   Ú*test_best_returns_none_when_stack_is_emptyÚ4TestStack.test_best_returns_none_when_stack_is_empty!  s#   € ä�q“	ˆð 	×Ñ˜Ÿ™› tÖ,r   rH   N)rz   r{   r|   r}   r²   r¶   r¹   r¾   rÁ   r   r€   r�   s   @r   r«   r«   ê   s#   ø‡ € ò3ò4ò
3ò8÷-ð -r   r«   )Ú__doc__ÚunittestÚcollectionsr   Úmathr   Únltk.translater   r   Únltk.translate.stack_decoderr   r   ÚTestCaser	   r„   r«   rH   r   r   Ú<module>rÊ      sW   ðñó Ý #Ý ç 4ß <ôP�x×(Ñ(ô Pôf@8�X×&Ñ&ô @8ôF<-�×!Ñ!ö <-r   