
    Qd                     $    d Z d Zd Zd ZddZdS )z#
Tools for comparing ranked lists.
c              #      K   t          |           } t          |          }| D ](}	 || |         ||         z
  fV  # t          $ r Y %w xY wdS )zFinds 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)dictKeyError)ranks1ranks2ks      5lib/python3.11/site-packages/nltk/metrics/spearman.py_rank_distsr	      s}      
 &\\F&\\F  	VAY****** 	 	 	D	 s   <
A	A	c                     d}d}t          | |          D ]\  }}|||z  z  }|dz  }	 dd|z  |||z  dz
  z  z  z
  S # t          $ r Y dS w xY w)aU  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).          g        )r	   ZeroDivisionError)r   r   nresr   ds         r   spearman_correlationr      s     	
A
CFF++  1q1u	QAGqAEAI/00   sss   = 
A
Ac                 4    d t          |           D             S )zGiven a sequence, yields each element with an increasing rank, suitable
    for use as an argument to ``spearman_correlation``.
    c              3   $   K   | ]\  }}||fV  d S )N ).0ir   s      r   	<genexpr>z&ranks_from_sequence.<locals>.<genexpr>1   s*      ..tq!QF......    )	enumerate)seqs    r   ranks_from_sequencer   -   s     /.y~~....r   V瞯<c              #      K   d}d}t          |           D ]:\  }\  }}	 t          ||z
            |k    r|}n# t          $ r Y nw xY w||fV  |};dS )zGiven 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``.
    Nr   )r   abs	TypeError)scoresrank_gap
prev_scorerankr   keyscores          r   ranks_from_scoresr'   4   s       JD$V,,  <C	5:%&&11 	 	 	D	 4i

 s   8
AAN)r   )__doc__r	   r   r   r'   r   r   r   <module>r)      sZ    
    $/ / /     r   