
    -ji                       d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
  ej        e          ZddZddZddZe	j        g de	j        ddge	j        ddge	j        ddge	j        ddge	j        g de	j        g diZddZdS )    )annotationsN)DatasetSequence)ContextPrecision)EvaluationModeMetricdatasetr   
column_mapdict[str, str]returnc                h    d |                                 D             }|                     |          S )zL
    Remap the column names in case dataset uses different column names
    c                    i | ]\  }}||	S  r   ).0kvs      Z/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/ragas/validation.py
<dictcomp>z&remap_column_names.<locals>.<dictcomp>   s    >>>41a!Q>>>    )itemsrename_columns)r	   r
   inverse_column_maps      r   remap_column_namesr      s9    
 ?>:+;+;+=+=>>>!!"4555r   dsc                <   d| j         v rd| j         vrd}t          | j         |         t                    rg| j         |         j        j        dk    rLt
                              d           d | d         D             }|                     d|| j        dz             } | S )Nground_truthsground_truthstringzpassing column names as 'ground_truths' is deprecated and will be removed in the next version, please use 'ground_truth' instead. Note that `ground_truth` should be of type string and not Sequence[string] like `ground_truths`c                    g | ]
}|d          S )r   r   )r   gts     r   
<listcomp>z3handle_deprecated_ground_truths.<locals>.<listcomp>    s    666B"Q%666r   a)new_fingerprint)	features
isinstancer   featuredtypeloggerwarning
add_column_fingerprint)r   column_namesr    s      r   handle_deprecated_ground_truthsr-      s    "+%%.*K*K&r{<0(;;	L)178CCNN t   76"_"5666B "!   B Ir   c           
     `   dD ]4}|| j         v r)| j         |         j        dk    rt          d| d          5dD ]s}|| j         v rht          | j         |         t                    r| j         |         j        j        dk    s-t          d| dt          | j         |                              td S )N)questionanswerr   r   zDataset feature "z" should be of type string)contextsz*" should be of type Sequence[string], got )r$   r'   
ValueErrorr%   r   r&   type)r   r,   s     r   validate_column_dtypesr4   *   s    >  2;&&{<(.(:: PPPP   % 	 	2;&&2;|4h??K-5;xGG P P P.22;|3L.M.MP P  	 	r   )r/   r0   r1   r/   r0   r1   r   )r/   r   r0   )r/   r1   r   metricslist[Metric]c           
     X   |D ]}t          t          |j                           }t          | j                                                  }|                    |          sJd}t          |t                    rd|vrd}t          d|j	         dt          ||z
             d|           dS )z
    validates the dataset and returns the evaluation type

    possible evaluation types
    1. (q,a,c)
    2. (q,a)
    3. (q,c)
    4. (g,a)
     r   zLooks like you're trying to use 'context_precision' without ground_truth. Please use consider using  `context_utilization' instead.zThe metric [z>] that that is used requires the following additional columns z to be present in the dataset. N)setEVALMODE_TO_COLUMNSevaluation_moder$   keysissubsetr%   r   r2   namelist)r   r5   mrequired_columnsavailable_columns	extra_msgs         r   validate_evaluation_modesrD   I   s       213DEFF 0 0 2 233(():;; 	I1.//b"*;;; b	=qv = =&*+;>O+O&P&P= =1:= =  	 r   )r	   r   r
   r   r   r   )r   r   r   r   )r   r   )r   r   r5   r6   )
__future__r   loggingdatasetsr   r    ragas.metrics._context_precisionr   ragas.metrics.baser   r   	getLogger__name__r(   r   r-   r4   qacqaqcgcgaqgaqcgr:   rD   r   r   r   <module>rS      s9   " " " " " "  & & & & & & & & = = = = = = 5 5 5 5 5 5 5 5		8	$	$6 6 6 6   (   * :::
H-
J/
31>>>@@@      r   