a
    •˜ëj
  ã                   @   s@   d dl Z d dlmZ d dlmZ d dlmZ G dd„ deƒZdS )é    N)ÚAny)Úoverride)ÚStringEvaluatorc                       s’   e Zd ZdZddœeedœ‡ fdd„Zeedœdd	„ƒZ	eedœd
d„ƒZ
eee dœdd„ƒZeedœdd„ƒZeeeeedœ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   ©Úflags)r   Ú_c                   s   t ƒ  ¡  || _dS )z�Initialize the RegexMatchStringEvaluator.

        Args:
            flags: Flags to use for the regex match. Defaults to 0 (no flags).
        N)ÚsuperÚ__init__r   )Úselfr   r   ©Ú	__class__© úd/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain/evaluation/regex_match/base.pyr
       s    
z"RegexMatchStringEvaluator.__init__)Úreturnc                 C   s   dS )z&This evaluator does not require input.Fr   ©r   r   r   r   Úrequires_input)   s    z(RegexMatchStringEvaluator.requires_inputc                 C   s   dS )z$This evaluator requires a reference.Tr   r   r   r   r   Úrequires_reference.   s    z,RegexMatchStringEvaluator.requires_referencec                 C   s   ddgS )zUGet the input keys.

        Returns:
            List[str]: The input keys.
        Ú	referenceÚ
predictionr   r   r   r   r   Ú
input_keys3   s    z$RegexMatchStringEvaluator.input_keysc                 C   s   dS )zYGet the evaluation name.

        Returns:
            str: The evaluation name.
        Zregex_matchr   r   r   r   r   Úevaluation_name<   s    z)RegexMatchStringEvaluator.evaluation_name)r   r   Úkwargsr   c                K   s"   t j||| jd�}dtt|ƒƒiS )aG  Evaluate the regex match between the prediction and the reference.

        Args:
            prediction: The prediction string.
            reference: The reference regex pattern.
            **kwargs: Additional keyword arguments (not used).

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