o
    rZh                     @   sB   d dl Z d dlmZ d dlmZ d dlmZ G dd de jZdS )    N)Counter)timeit)
Vocabularyc                   @   s   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zejd*d+d,d- Zd.S )/NgramModelVocabularyTestsztests Vocabulary Classc                 C   s   t g ddd| _d S N)zabcfdegr   r   r	   r   w   
unk_cutoff)r   vocab)cls r   P/var/www/auris/lib/python3.10/site-packages/nltk/test/unit/lm/test_vocabulary.py
setUpClass   s   z$NgramModelVocabularyTests.setUpClassc                 C   s   |  | j d S N)
assertTruer   selfr   r   r   test_truthiness   s   z)NgramModelVocabularyTests.test_truthinessc                 C   s   |  | jjd d S )Nr   )assertEqualr   cutoffr   r   r   r   test_cutoff_value_set_correctly   s   z9NgramModelVocabularyTests.test_cutoff_value_set_correctlyc                 C   s8   |  t d| j_W d    d S 1 sw   Y  d S )N   )assertRaisesAttributeErrorr   r   r   r   r   r   test_unable_to_change_cutoff   s   
"z6NgramModelVocabularyTests.test_unable_to_change_cutoffc                 C   sP   |  t}tddd W d    n1 sw   Y  d}| |t|j d S )Nabcr   r   z*Cutoff value cannot be less than 1. Got: 0)r!   
ValueErrorr   r   str	exception)r   exc_infoZexpected_error_msgr   r   r   test_cutoff_setter_checks_value#   s
   z9NgramModelVocabularyTests.test_cutoff_setter_checks_valuec                 C   s@   |  | jjd d |  | jjd d |  | jjd d d S )Nr   r   r	   r
      )r   r   countsr   r   r   r   test_counts_set_correctly)   s   z3NgramModelVocabularyTests.test_counts_set_correctlyc                 C   s4   |  d| jv  | d| jv  | d| jv  d S )Nr   r
   r   )r   r   assertFalser   r   r   r   %test_membership_check_respects_cutoff.   s   z?NgramModelVocabularyTests.test_membership_check_respects_cutoffc                 C   s   |  dt| j d S )N   )r   lenr   r   r   r   r   test_vocab_len_respects_cutoff6   s   z8NgramModelVocabularyTests.test_vocab_len_respects_cutoffc                 C   s>   g d}g d}|  |t| jj  |  |t| j d S )N)	r   r	   r
   r   r   r   r   r   r   )r   r	   r   r   <UNK>)assertCountEquallistr   r+   keys)r   Zvocab_countsZvocab_itemsr   r   r   test_vocab_iter_respects_cutoff;   s   z9NgramModelVocabularyTests.test_vocab_iter_respects_cutoffc                 C   sR   t dd}| t|d | | | |j| |td | |j| d S )Nr   r   r   abcde)r   r   r0   r-   ZassertIn	unk_labelupdater4   )r   emptyr   r   r   test_update_empty_vocabB   s   

z1NgramModelVocabularyTests.test_update_empty_vocabc                 C   s,   |  | jdd |  | jdd d S )Nr   r
   r2   r   r   lookupr   r   r   r   test_lookupK   s   z%NgramModelVocabularyTests.test_lookupc                 C   sb   |  | jddgd |  | jdd |  | jdd |  | jtttdd d S )Nr   r	   r   r	   )r   r
   r   r2   r    )r2   r2   r2   )r   r   r=   mapr&   ranger   r   r   r   test_lookup_iterablesO   s   z/NgramModelVocabularyTests.test_lookup_iterablesc                 C   sh   |  | jdd |  | jg d |  | jtg d |  | jdd tddD d d S )Nr   c                 s   s    | ]}|V  qd S r   r   ).0nr   r   r   	<genexpr>[   s    zHNgramModelVocabularyTests.test_lookup_empty_iterables.<locals>.<genexpr>r   )r   r   r=   iterrB   r   r   r   r   test_lookup_empty_iterablesW   s   (z5NgramModelVocabularyTests.test_lookup_empty_iterablesc                 C   s`   |  | jddgddggd |  | jddgdgd |  | jddgggggd d S )Nr   r	   r
   )r?   r@   )r?   r2   ))))r?   r<   r   r   r   r   test_lookup_recursive]   s
   $z/NgramModelVocabularyTests.test_lookup_recursivec                 C   sz   |  t | jd  W d    n1 sw   Y  |  t t| jd d g W d    d S 1 s6w   Y  d S r   r!   	TypeErrorr   r=   r4   r   r   r   r   test_lookup_Noned      "z*NgramModelVocabularyTests.test_lookup_Nonec                 C   sz   |  t | jd W d    n1 sw   Y  |  t t| jddg W d    d S 1 s6w   Y  d S )Nr*   r   rJ   r   r   r   r   test_lookup_intj   rM   z)NgramModelVocabularyTests.test_lookup_intc                 C   s   |  | jdd d S )N r2   r<   r   r   r   r   test_lookup_empty_strp   s   z/NgramModelVocabularyTests.test_lookup_empty_strc                 C   sj   t g ddd}t g ddd}t g dddd}t ddgdd}| || | || | || d S )N)r   r	   r
   r*   r   Zblah)r   r8   r   r	   )r   r   ZassertNotEqual)r   v1v2Zv3Zv4r   r   r   test_eqalitys   s   z&NgramModelVocabularyTests.test_eqalityc                 C   s   |  t| jd d S )Nz8<Vocabulary with cutoff=2 unk_label='<UNK>' and 5 items>)r   r&   r   r   r   r   r   test_str}   s   
z"NgramModelVocabularyTests.test_strc                 C   s"   |  | jttg ddd d S r   )r   r   r   r   r   r   r   r   test_creation_with_counter   s   z4NgramModelVocabularyTests.test_creation_with_counterz?Test is known to be flaky as it compares (runtime) performance.)reasonc                 C   sP   t d}ddlm} t | }tdt d}tdt d}| j||dd d S )	Nr7   r   )englishzlen(small_vocab))globalszlen(large_vocab)r*   )Zplaces)r   Znltk.corpus.europarl_rawrW   wordsr   localsZassertAlmostEqual)r   Zsmall_vocabrW   Zlarge_vocabZsmall_vocab_len_timeZlarge_vocab_len_timer   r   r   test_len_is_constant   s   z.NgramModelVocabularyTests.test_len_is_constantN)__name__
__module____qualname____doc__classmethodr   r   r   r#   r)   r,   r.   r1   r6   r;   r>   rC   rH   rI   rL   rN   rP   rS   rT   rU   unittestskipr[   r   r   r   r   r      s6    
	
r   )ra   collectionsr   r   Znltk.lmr   ZTestCaser   r   r   r   r   <module>   s
   