o
    Jjgg	                     @   s8   d dl Z d dlmZmZ d dlmZ G dd deZdS )    N)AnyList)StringEvaluatorc                       s   e Zd ZdZdddedef fddZedefd	d
Z	edefddZ
edee fddZedefddZdedededefddZ  ZS )RegexMatchStringEvaluatora  Compute a regex match between the prediction and the reference.

    Examples
    ----------
    >>> evaluator = RegexMatchStringEvaluator(flags=re.IGNORECASE)
    >>> evaluator.evaluate_strings(
            prediction="Mindy is the CTO",
            reference="^mindy.*cto$",
        )  # This will return {'score': 1.0} due to the IGNORECASE flag

    >>> evaluator = RegexMatchStringEvaluator()
    >>> evaluator.evaluate_strings(
            prediction="Mindy is the CTO",
            reference="^Mike.*CEO$",
        )  # This will return {'score': 0.0}

    >>> evaluator.evaluate_strings(
            prediction="Mindy is the CTO",
            reference="^Mike.*CEO$|^Mindy.*CTO$",
        )  # This will return {'score': 1.0} as the prediction matches the second pattern in the union
    r   flagsr   kwargsc                   s   t    || _d S )N)super__init__r   )selfr   r   	__class__ ]/var/www/html/zoom/venv/lib/python3.10/site-packages/langchain/evaluation/regex_match/base.pyr
      s   

z"RegexMatchStringEvaluator.__init__returnc                 C      dS )z8
        This evaluator does not require input.
        Fr   r   r   r   r   requires_input"      z(RegexMatchStringEvaluator.requires_inputc                 C   r   )z6
        This evaluator requires a reference.
        Tr   r   r   r   r   requires_reference)   r   z,RegexMatchStringEvaluator.requires_referencec                 C   s   ddgS )z^
        Get the input keys.

        Returns:
            List[str]: The input keys.
        	reference
predictionr   r   r   r   r   
input_keys0   s   z$RegexMatchStringEvaluator.input_keysc                 C   r   )zb
        Get the evaluation name.

        Returns:
            str: The evaluation name.
        regex_matchr   r   r   r   r   evaluation_name:   s   z)RegexMatchStringEvaluator.evaluation_namer   r   c                K   s"   t j||| jd}dtt|iS )a7  
        Evaluate the regex match between the prediction and the reference.

        Args:
            prediction (str): The prediction string.
            reference (Optional[str], optional): The reference regex pattern.

        Returns:
            dict: The evaluation results containing the score.
        r   score)rematchr   intbool)r   r   r   r   r   r   r   r   _evaluate_stringsD   s   z+RegexMatchStringEvaluator._evaluate_strings)__name__
__module____qualname____doc__r   r   r
   propertyr   r   r   r   strr   r   dictr    __classcell__r   r   r   r   r      s(    		r   )r   typingr   r   langchain.evaluation.schemar   r   r   r   r   r   <module>   s    