ó
ů`]c           @   s;   d  d l  m Z d   Z d   Z d   Z d d  Z d S(   i˙˙˙˙(   t   divisionc         c   s\   t  |   }  t  |  } x= |  D]5 } y | |  | | | f VWq t k
 rS q Xq Wd S(   s¸   Finds the difference between the values in ranks1 and ranks2 for keys
    present in both dicts. If the arguments are not dicts, they are converted
    from (key, rank) sequences.
    N(   t   dictt   KeyError(   t   ranks1t   ranks2t   k(    (    s4   lib/python2.7/site-packages/nltk/metrics/spearman.pyt   _rank_dists   s    c         C   s}   d } d } x5 t  |  |  D]$ \ } } | | | 7} | d 7} q Wy  d d | | | | d SWn t k
 rx d SXd S(   sU  Returns the Spearman correlation coefficient for two rankings, which
    should be dicts or sequences of (key, rank). The coefficient ranges from
    -1.0 (ranks are opposite) to 1.0 (ranks are identical), and is only
    calculated for keys in both rankings (for meaningful results, remove keys
    present in only one list before ranking).i    i   i   g        N(   R   t   ZeroDivisionError(   R   R   t   nt   resR   t   d(    (    s4   lib/python2.7/site-packages/nltk/metrics/spearman.pyt   spearman_correlation   s     c         C   s   d   t  |   D S(   s   Given a sequence, yields each element with an increasing rank, suitable
    for use as an argument to ``spearman_correlation``.
    c         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   iR   (    (    s4   lib/python2.7/site-packages/nltk/metrics/spearman.pys	   <genexpr>2   s    (   t	   enumerate(   t   seq(    (    s4   lib/python2.7/site-packages/nltk/metrics/spearman.pyt   ranks_from_sequence.   s    gVçŻŇ<c         c   s{   d } d } xh t |   D]Z \ } \ } } y# t | |  | k rM | } n  Wn t k
 ra n X| | f V| } q Wd S(   sü   Given a sequence of (key, score) tuples, yields each key with an
    increasing rank, tying with previous key's rank if the difference between
    their scores is less than rank_gap. Suitable for use as an argument to
    ``spearman_correlation``.
    i    N(   t   NoneR   t   abst	   TypeError(   t   scorest   rank_gapt
   prev_scoret   rankR   t   keyt   score(    (    s4   lib/python2.7/site-packages/nltk/metrics/spearman.pyt   ranks_from_scores5   s    N(   t
   __future__R    R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/nltk/metrics/spearman.pyt   <module>   s   			