Ë
    çÍ:jÝ>  ã                   óþ   — d Z ddlZddlmZmZ ddlmZ d„ Zej                  Z
d„ ZdZ	 ddlmZ dZ	 d
Z	 dZ	  G d„ de¬«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ d«      Zy# e$ r d	„ ZY ŒKw xY w)zÌ
Provides scoring functions for a number of association measures through a
generic, abstract implementation in ``NgramAssocMeasures``, and n-specific
``BigramAssocMeasures`` and ``TrigramAssocMeasures``.
é    N)ÚABCMetaÚabstractmethod©Úreducec                 ó,   — t        j                  | «      S ©N)Ú_mathÚlog2)Úxs    úm/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/metrics/association.pyú<lambda>r      s   € ”%—*‘*˜Q“-€ ó    c                 ó   — t        d„ | «      S )Nc                 ó   — | |z  S r   © )r   Úys     r   r   z<lambda>.<locals>.<lambda>   s
   € ¨¨Q©€ r   r   )Úss    r   r   r      s   € ”VÑ.°Ó2€ r   g#B’¡œÇ;)Úfisher_exactc                  ó   — t         ‚r   ©ÚNotImplementedError)Ú_argsÚ_kwargss     r   r   r      s   € Ü!Ð!r   éþÿÿÿéÿÿÿÿc                   óØ   — e Zd ZdZdZeed„ «       «       Zeed„ «       «       Ze	d„ «       Z
ed„ «       Ze	d„ «       Ze	d„ «       Zed	„ «       Ze	d
„ «       Ze	d„ «       Ze	d„ «       Ze	d„ «       Zy)ÚNgramAssocMeasuresa¿  
    An abstract class defining a collection of generic association measures.
    Each public method returns a score, taking the following arguments::

        score_fn(count_of_ngram,
                 (count_of_n-1gram_1, ..., count_of_n-1gram_j),
                 (count_of_n-2gram_1, ..., count_of_n-2gram_k),
                 ...,
                 (count_of_1gram_1, ..., count_of_1gram_n),
                 count_of_total_words)

    See ``BigramAssocMeasures`` and ``TrigramAssocMeasures``

    Inheriting classes should define a property _n, and a method _contingency
    which calculates contingency values from marginals in order for all
    association measures defined here to be usable.
    r   c                  ó   — t        d«      ‚)z>Calculates values of a contingency table from marginal values.ú?The contingency table is not availablein the general ngram caser   ©Ú	marginalss    r   Ú_contingencyzNgramAssocMeasures._contingencyB   ó   € ô "ØPó
ð 	
r   c                  ó   — t        d«      ‚)úACalculates values of contingency table marginals from its values.r   r   )Úcontingencys    r   Ú
_marginalszNgramAssocMeasures._marginalsJ   r#   r   c              #   ó  ‡ ‡‡K  — t        ‰«      }t        ‰ j                  «      D �cg c]  }d|z  ‘Œ	 }}t        t        ‰«      «      D ]-  Št	        ˆ ˆˆfd„|D «       «      |‰ j                  dz
  z  z  –— Œ/ yc c}w ­w)ú3Calculates expected values for a contingency table.é   c              3   óx   •‡K  — | ]0  Št        ˆˆˆfd „t        d‰j                  z  «      D «       «      –— Œ2 y­w)c              3   ó@   •K  — | ]  }|‰z  ‰‰z  k(  sŒ‰|   –— Œ y ­wr   r   )Ú.0r   ÚcontÚiÚjs     €€€r   ú	<genexpr>z@NgramAssocMeasures._expected_values.<locals>.<genexpr>.<genexpr>]   s$   øè ø€ ÒP A¸aÀ!¹eÈÈQÉÓ=O˜˜Q�ÑPùs   ƒ”
é   N)ÚsumÚrangeÚ_n)r-   r0   Úclsr.   r/   s    @€€€r   r1   z6NgramAssocMeasures._expected_values.<locals>.<genexpr>\   s1   ùè ø€ ò àô ÕP¬¨q°#·&±&©yÓ)9ÔP×Pñùs   „6:N)r3   r4   r5   ÚlenÚ_product)r6   r.   Ún_allr/   Úbitss   `` ` r   Ú_expected_valuesz#NgramAssocMeasures._expected_valuesR   sƒ   úè ø€ ô �D“	ˆÜ % c§f¡f£Ö.˜1��Q“Ð.ˆÐ.ô ”s˜4“yÓ!ò 	ˆAô õ à!ôó ð ˜SŸV™V a™ZÑ(ñ	*óñ	ùò /ùs   …#B ¨A;´AB c                  ó(   — | t            | t           z  S )z Scores ngrams by their frequency)ÚNGRAMÚTOTALr    s    r   Úraw_freqzNgramAssocMeasures.raw_freqc   s   € ð œÑ )¬EÑ"2Ñ2Ð2r   c                 ó–   — |t            t        |t           «      |t           | j                  dz
  z  z  z
  |t            t
        z   dz  z  S )z�Scores ngrams using Student's t test with independence hypothesis
        for unigrams, as in Manning and Schutze 5.3.1.
        r*   g      à?)r=   r8   ÚUNIGRAMSr>   r5   Ú_SMALL©r6   r!   s     r   Ú	student_tzNgramAssocMeasures.student_th   sR   € ð ”eÑÜ�y¤Ñ*Ó+¨y¼Ñ/?ÀCÇFÁFÈQÁJÑ/OÑPñQà”uÑ¤Ñ&¨3Ñ.ñ/ð 	/r   c                 óz   —  | j                   |Ž }| j                  |«      }t        d„ t        ||«      D «       «      S )zZScores ngrams using Pearson's chi-square as in Manning and Schutze
        5.3.3.
        c              3   óF   K  — | ]  \  }}||z
  d z  |t         z   z  –— Œ y­w)r2   N)rB   ©r-   ÚobsÚexps      r   r1   z,NgramAssocMeasures.chi_sq.<locals>.<genexpr>y   s&   è ø€ ÒU¹¸¸c�C˜#‘I !Ñ# s¬V¡|Õ4ÑUùs   ‚!)r"   r;   r3   Úzip)r6   r!   r.   Úexpss       r   Úchi_sqzNgramAssocMeasures.chi_sqr   s=   € ð
  ˆs×Ñ Ð+ˆØ×#Ñ# DÓ)ˆÜÑUÄSÈÈtÃ_ÔUÓUÐUr   c                  ó`   — | t            |j                  dd«      z  t        | t           «      z  S )zÂScores ngrams using a variant of mutual information. The keyword
        argument power sets an exponent (default 3) for the numerator. No
        logarithm of the result is calculated.
        Úpoweré   )r=   Úgetr8   rA   )r!   Úkwargss     r   Úmi_likezNgramAssocMeasures.mi_like{   s5   € ð œÑ 6§:¡:¨g°qÓ#9Ñ9¼HØ”hÑó=
ñ 
ð 	
r   c                 ó’   — t        |t           |t           | j                  dz
  z  z  «      t        t	        |t
           «      «      z
  S )z^Scores ngrams by pointwise mutual information, as in Manning and
        Schutze 5.4.
        r*   )Ú_log2r=   r>   r5   r8   rA   rC   s     r   ÚpmizNgramAssocMeasures.pmi…   sG   € ô
 �YœuÑ%¨	´%Ñ(8¸S¿V¹VÀa¹ZÑ(HÑHÓIÌEÜ�YœxÑ(Ó)óM
ñ 
ð 	
r   c           
      ó|   —  | j                   |Ž }dt        d„ t        || j                  |«      «      D «       «      z  S )zFScores ngrams using likelihood ratios as in Manning and Schutze 5.3.4.r2   c              3   ó`   K  — | ]&  \  }}|t        ||t        z   z  t        z   «      z  –— Œ( y ­wr   )Ú_lnrB   rG   s      r   r1   z6NgramAssocMeasures.likelihood_ratio.<locals>.<genexpr>’   s4   è ø€ ò 
á��Sð ”#�c˜S¤6™\Ñ*¬VÑ3Ó4Õ4ñ
ùs   ‚,.)r"   r3   rJ   r;   ©r6   r!   r.   s      r   Úlikelihood_ratioz#NgramAssocMeasures.likelihood_ratioŽ   sI   € ð  ˆs×Ñ Ð+ˆØ”3ñ 
ä  c×&:Ñ&:¸4Ó&@ÓAô
ó 
ñ 
ð 	
r   c                 óž   — t        |t           «      |t           | j                  dz
  z  z  }|t           t        |t           |z  «      dz
  z  S )z1Scores ngrams using the Poisson-Stirling measure.r*   )r8   rA   r>   r5   r=   rT   )r6   r!   rI   s      r   Úpoisson_stirlingz#NgramAssocMeasures.poisson_stirling—   sN   € ô �y¤Ñ*Ó+¨y¼Ñ/?ÀCÇFÁFÈQÁJÑ/OÑPˆØœÑ¤5¨´5Ñ)9¸CÑ)?Ó#@À1Ñ#DÑEÐEr   c                 óH   —  | j                   |Ž }|d   t        |dd «      z  S )z&Scores ngrams using the Jaccard index.r   Nr   )r"   r3   rY   s      r   ÚjaccardzNgramAssocMeasures.jaccard�   s/   € ð  ˆs×Ñ Ð+ˆØ�A‰wœ˜T # 2˜Y›Ñ'Ð'r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   Ústaticmethodr   r"   r'   Úclassmethodr;   r?   rD   rL   rR   rU   rZ   r\   r^   r   r   r   r   r   -   sü   „ ñð$ 
€BàØñ
ó ó ð
ð Øñ
ó ó ð
ð ñó ðð  ñ3ó ð3ð ñ/ó ð/ð ñVó ðVð ñ
ó ð
ð ñ
ó ð
ð ñ
ó ð
ð ñFó ðFð
 ñ(ó ñ(r   r   )Ú	metaclassc                   ó„   — e Zd ZdZdZed„ «       Zed„ «       Zed„ «       Ze	d„ «       Z
e	d„ «       Ze	d„ «       Zed	„ «       Zy
)ÚBigramAssocMeasuresaˆ  
    A collection of bigram association measures. Each association measure
    is provided as a function with three arguments::

        bigram_score_fn(n_ii, (n_ix, n_xi), n_xx)

    The arguments constitute the marginals of a contingency table, counting
    the occurrences of particular events in a corpus. The letter i in the
    suffix refers to the appearance of the word in question, while x indicates
    the appearance of any word. Thus, for example:

    - n_ii counts ``(w1, w2)``, i.e. the bigram being scored
    - n_ix counts ``(w1, *)``
    - n_xi counts ``(*, w2)``
    - n_xx counts ``(*, *)``, i.e. any bigram

    This may be shown with respect to a contingency table::

                w1    ~w1
             ------ ------
         w2 | n_ii | n_oi | = n_xi
             ------ ------
        ~w2 | n_io | n_oo |
             ------ ------
             = n_ix        TOTAL = n_xx
    r2   c                 ó>   — |\  }}|| z
  }|| z
  }| |||| z
  |z
  |z
  fS )zECalculates values of a bigram contingency table from marginal values.r   )Ún_iiÚn_ix_xi_tupleÚn_xxÚn_ixÚn_xiÚn_oiÚn_ios          r   r"   z BigramAssocMeasures._contingencyÂ   s<   € ð %‰ˆˆtØ�d‰{ˆØ�d‰{ˆØ�d˜D $¨¡+°Ñ"4°tÑ";Ð<Ð<r   c                 ó.   — | || z   || z   f||z   |z   | z   fS )r%   r   )ri   rn   ro   Ún_oos       r   r'   zBigramAssocMeasures._marginalsÊ   s,   € ð �t˜d‘{ D¨4¡KÐ0°$¸±+ÀÑ2DÀtÑ2KÐLÐLr   c              #   ó†   K  — t        | «      }t        d«      D ]$  }| |   | |dz     z   | |   | |dz     z   z  |z  –— Œ& y­w)r)   é   r*   r2   N)r3   r4   )r.   rk   r/   s      r   r;   z$BigramAssocMeasures._expected_valuesÏ   sX   è ø€ ô �4‹yˆä�q“ò 	KˆAØ˜‘7˜T ! a¡%™[Ñ(¨T°!©W°t¸AÀ¹E±{Ñ-BÑCÀdÑJÓJñ	Kùs   ‚?Ac                 óv   —  | j                   |Ž \  }}}}||z  ||z  z
  dz  ||z   ||z   z  ||z   z  ||z   z  z  S )zdScores bigrams using phi-square, the square of the Pearson correlation
        coefficient.
        r2   )r"   )r6   r!   ri   ro   rn   rq   s         r   Úphi_sqzBigramAssocMeasures.phi_sq×   s`   € ð
 "2 ×!1Ñ!1°9Ð!=Ñˆˆd�D˜$à�t‘˜d T™kÑ)¨aÑ/Ø�D‰[˜T D™[Ñ)¨T°D©[Ñ9¸TÀD¹[ÑIñ
ð 	
r   c                 ó<   — |\  }}|| j                  |||f|«      z  S )zƒScores bigrams using chi-square, i.e. phi-sq multiplied by the number
        of bigrams, as in Manning and Schutze 5.3.3.
        )ru   )r6   ri   rj   rk   rl   rm   s         r   rL   zBigramAssocMeasures.chi_sqâ   s)   € ð
 %‰ˆˆtØ�c—j‘j ¨¨d |°TÓ:Ñ:Ð:r   c                 óZ   —  | j                   |Ž \  }}}}t        ||g||ggd¬«      \  }}|S )zºScores bigrams using Fisher's Exact Test (Pedersen 1996).  Less
        sensitive to small counts than PMI or Chi Sq, but also more expensive
        to compute. Requires scipy.
        Úless)Úalternative)r"   r   )r6   r!   ri   ro   rn   rq   ÚoddsÚpvalues           r   ÚfisherzBigramAssocMeasures.fisherê   sB   € ð "2 ×!1Ñ!1°9Ð!=Ñˆˆd�D˜$ä%¨¨d |°d¸D°\Ð&BÐPVÔW‰ˆˆvØˆr   c                 ó"   — |\  }}d| z  ||z   z  S )z(Scores bigrams using Dice's coefficient.r2   r   )ri   rj   rk   rl   rm   s        r   ÚdicezBigramAssocMeasures.diceö   s    € ð %‰ˆˆtØ�4‰x˜4 $™;Ñ'Ð'r   N)r_   r`   ra   rb   r5   rc   r"   r'   r;   rd   ru   rL   r|   r~   r   r   r   rg   rg   ¤   sœ   „ ñð6 
€Bàñ=ó ð=ð ñMó ðMð ñKó ðKð ñ
ó ð
ð ñ;ó ð;ð ñ	ó ð	ð ñ(ó ñ(r   rg   c                   ó4   — e Zd ZdZdZed„ «       Zed„ «       Zy)ÚTrigramAssocMeasuresa×  
    A collection of trigram association measures. Each association measure
    is provided as a function with four arguments::

        trigram_score_fn(n_iii,
                         (n_iix, n_ixi, n_xii),
                         (n_ixx, n_xix, n_xxi),
                         n_xxx)

    The arguments constitute the marginals of a contingency table, counting
    the occurrences of particular events in a corpus. The letter i in the
    suffix refers to the appearance of the word in question, while x indicates
    the appearance of any word. Thus, for example:

    - n_iii counts ``(w1, w2, w3)``, i.e. the trigram being scored
    - n_ixx counts ``(w1, *, *)``
    - n_xxx counts ``(*, *, *)``, i.e. any trigram
    rO   c                 ó¼   — |\  }}}|\  }}}	|| z
  }
|| z
  }|| z
  }|	| z
  |
z
  |z
  }|| z
  |
z
  |z
  }|| z
  |z
  |z
  }|| z
  |
z
  |z
  |z
  |z
  |z
  |z
  }| |
||||||fS )zÔCalculates values of a trigram contingency table (or cube) from
        marginal values.
        >>> TrigramAssocMeasures._contingency(1, (1, 1, 1), (1, 73, 1), 2000)
        (1, 0, 0, 0, 0, 72, 0, 1927)
        r   )Ún_iiiÚn_iix_tupleÚn_ixx_tupleÚn_xxxÚn_iixÚn_ixiÚn_xiiÚn_ixxÚn_xixÚn_xxiÚn_oiiÚn_ioiÚn_iioÚn_ooiÚn_oioÚn_iooÚn_ooos                    r   r"   z!TrigramAssocMeasures._contingency  s®   € ð !,Ñˆ��uØ +Ñˆ��uØ˜‘ˆØ˜‘ˆØ˜‘ˆØ˜‘ Ñ%¨Ñ-ˆØ˜‘ Ñ%¨Ñ-ˆØ˜‘ Ñ%¨Ñ-ˆØ˜‘ Ñ%¨Ñ-°Ñ5¸Ñ=ÀÑEÈÑMˆà�u˜e U¨E°5¸%ÀÐGÐGr   c                  óŠ   — | \  }}}}}}}}|||z   ||z   ||z   f||z   |z   |z   ||z   |z   |z   ||z   |z   |z   ft        | «      fS )z»Calculates values of contingency table marginals from its values.
        >>> TrigramAssocMeasures._marginals(1, 0, 0, 0, 0, 72, 0, 1927)
        (1, (1, 1, 1), (1, 73, 1), 2000)
        ©r3   )	r&   r‚   rŒ   r�   r�   rŽ   r�   r‘   r’   s	            r   r'   zTrigramAssocMeasures._marginals&  s�   € ð BMÑ>ˆˆu�e˜U E¨5°%¸àØ�U‰]˜E E™M¨5°5©=Ð9à˜‘ Ñ%¨Ñ-Ø˜‘ Ñ%¨Ñ-Ø˜‘ Ñ%¨Ñ-ðô
 �Óð	
ð 		
r   N©r_   r`   ra   rb   r5   rc   r"   r'   r   r   r   r€   r€   ý   s6   „ ñð& 
€BàñHó ðHð$ ñ
ó ñ
r   r€   c                   ó4   — e Zd ZdZdZed„ «       Zed„ «       Zy)ÚQuadgramAssocMeasuresaF  
    A collection of quadgram association measures. Each association measure
    is provided as a function with five arguments::

        trigram_score_fn(n_iiii,
                        (n_iiix, n_iixi, n_ixii, n_xiii),
                        (n_iixx, n_ixix, n_ixxi, n_xixi, n_xxii, n_xiix),
                        (n_ixxx, n_xixx, n_xxix, n_xxxi),
                        n_all)

    The arguments constitute the marginals of a contingency table, counting
    the occurrences of particular events in a corpus. The letter i in the
    suffix refers to the appearance of the word in question, while x indicates
    the appearance of any word. Thus, for example:

    - n_iiii counts ``(w1, w2, w3, w4)``, i.e. the quadgram being scored
    - n_ixxi counts ``(w1, *, *, w4)``
    - n_xxxx counts ``(*, *, *, *)``, i.e. any quadgram
    rs   c                 ó  — |\  }}}}|\  }	}
}}}}|\  }}}}|| z
  }|| z
  }|| z
  }|| z
  |z
  |z
  }|| z
  |z
  |z
  }|| z
  |z
  |z
  }|| z
  |z
  |z
  |z
  |z
  |z
  |z
  }|| z
  }|| z
  |z
  |z
  }|
| z
  |z
  |z
  }|| z
  |z
  |z
  |z
  |z
  |z
  |z
  }|	| z
  |z
  |z
  }|| z
  |z
  |z
  |z
  |z
  |z
  |z
  }|| z
  |z
  |z
  |z
  |z
  |z
  |z
  } || z
  |z
  |z
  |z
  |z
  |z
  |z
  |z
  |z
  |z
  |z
  |z
  |z
  |z
  | z
  }!| |||||||||||||| |!fS )zXCalculates values of a quadgram contingency table from
        marginal values.
        r   )"Ún_iiiiÚn_iiix_tupleÚn_iixx_tupleÚn_ixxx_tupleÚn_xxxxÚn_iiixÚn_iixiÚn_ixiiÚn_xiiiÚn_iixxÚn_ixixÚn_ixxiÚn_xixiÚn_xxiiÚn_xiixÚn_ixxxÚn_xixxÚn_xxixÚn_xxxiÚn_oiiiÚn_ioiiÚn_iioiÚn_ooiiÚn_oioiÚn_iooiÚn_oooiÚn_iiioÚn_oiioÚn_ioioÚn_ooioÚn_iiooÚn_oiooÚn_ioooÚn_oooos"                                     r   r"   z"QuadgramAssocMeasures._contingencyP  s>  € ð
 ,8Ñ(ˆ�˜ Ø;GÑ8ˆ�˜ ¨°Ø+7Ñ(ˆ�˜ Ø˜&‘ˆØ˜&‘ˆØ˜&‘ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆØ˜&‘ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆØ˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆàØñàñð ñð ñ	ð
 ñð ñð ñð ñð ñ	ð ñ
ð ñð ñð ñð ñð ñð 	ð( ØØØØØØØØØØØØØØØð!
ð 	
r   c                  óÌ  — | \  }}}}}}}}}	}
}}}}}}||	z   }||z   }||z   }||z   }||z   |	z   |z   }||z   |	z   |z   }||z   |z   |z   }||z   |z   |z   }||z   |z   |z   }||z   |	z   |
z   }||z   |z   |	z   |z   |z   |z   |z   }||z   |z   |	z   |z   |
z   |z   |z   }||z   |z   |	z   |z   |z   |
z   |z   }||z   |z   |z   |z   |z   |z   |z   }t        | «      }|||||f||||||f||||f|fS )a  Calculates values of contingency table marginals from its values.
        QuadgramAssocMeasures._marginals(1, 0, 2, 46, 552, 825, 2577, 34967, 1, 0, 2, 48, 7250, 9031, 28585, 356653)
        (1, (2, 553, 3, 1), (7804, 6, 3132, 1378, 49, 2), (38970, 17660, 100, 38970), 440540)
        r”   ) r&   r™   r¬   r­   r¯   r®   r°   r±   r²   r³   r´   rµ   r¶   r·   r¸   r¹   rº   rž   rŸ   r    r¡   r¢   r£   r¤   r¥   r¦   r§   r¨   r©   rª   r«   r9   s                                    r   r'   z QuadgramAssocMeasures._marginalsŒ  s¸  € ð. ñ#	
ØØØØØØØØØØØØØØØØð ˜&‘ˆØ˜&‘ˆØ˜&‘ˆØ˜&‘ˆà˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆØ˜&‘ 6Ñ)¨FÑ2ˆà˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆØ˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆØ˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆØ˜&‘ 6Ñ)¨FÑ2°VÑ;¸fÑDÀvÑMÐPVÑVˆä�KÓ ˆð Ø�V˜V VÐ,Ø�V˜V V¨V°VÐ<Ø�V˜V VÐ,Øð
ð 	
r   Nr•   r   r   r   r—   r—   9  s5   „ ñð( 
€Bàñ9
ó ð9
ðv ñ1
ó ñ1
r   r—   c                   ó&   — e Zd ZdZd„ Zed„ «       Zy)ÚContingencyMeasuresz�Wraps NgramAssocMeasures classes such that the arguments of association
    measures are contingency table values rather than marginals.
    c                 ó  — d|j                   j                  z   | j                   _        t        |«      D ]P  }|j                  d«      rŒt	        ||«      }|j                  d«      s| j                  ||«      }t        | ||«       ŒR y)zAConstructs a ContingencyMeasures given a NgramAssocMeasures classÚContingencyÚ__Ú_N)Ú	__class__r_   ÚdirÚ
startswithÚgetattrÚ_make_contingency_fnÚsetattr)ÚselfÚmeasuresÚkÚvs       r   Ú__init__zContingencyMeasures.__init__Æ  sw   € à"/°(×2DÑ2D×2MÑ2MÑ"Mˆ�‰ÔÜ�X“ò 	 ˆAØ�|‰|˜DÔ!ØÜ˜ !Ó$ˆAØ—<‘< Ô$Ø×-Ñ-¨h¸Ó:�Ü�D˜!˜QÕñ	 r   c                 óZ   ‡ ‡— ˆ ˆfd„}‰j                   |_         ‰j                  |_        |S )z‡From an association measure function, produces a new function which
        accepts contingency table values as its arguments.
        c                  ó(   •—  ‰ ‰j                   | Ž Ž S r   )r'   )r&   rÉ   Úold_fns    €€r   Úresz5ContingencyMeasures._make_contingency_fn.<locals>.res×  s   ø€ ÙÐ.˜8×.Ñ.°Ð<Ð=Ð=r   )rb   r_   )rÉ   rÏ   rÐ   s   `` r   rÆ   z(ContingencyMeasures._make_contingency_fnÑ  s%   ù€ õ	>ð —n‘nˆŒØ—‘ˆŒØˆ
r   N)r_   r`   ra   rb   rÌ   rc   rÆ   r   r   r   r½   r½   Á  s    „ ñò	 ð ñ
ó ñ
r   r½   )rb   Úmathr	   Úabcr   r   Ú	functoolsr   rT   ÚlogrX   r8   rB   Úscipy.statsr   ÚImportErrorr=   rA   r>   r   rg   r€   r—   r½   r   r   r   ú<module>r×      s­   ðñó ß 'Ý á€Ø‡i�i€á2€à	€ð"Ý(ð 	
€Ø )à€Ø 7à
€Ø 9ôt( 7õ t(ônV(Ð,ô V(ôr9
Ð-ô 9
ôxE
Ð.ô E
÷Pò øðM ò "ô"ð"ús   ªA1 Á1A<Á;A<