
    9|hg	                     >    d dl Z d dlmZmZ d dlmZ  G d de      Zy)    N)AnyList)StringEvaluatorc                        e Zd ZdZdddedef fdZedefd       Z	edefd	       Z
edee   fd
       Zedefd       ZdedededefdZ x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                0    t         |           || _        y )N)super__init__r	   )selfr	   r
   	__class__s      d/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain/evaluation/regex_match/base.pyr   z"RegexMatchStringEvaluator.__init__   s    
    returnc                      y)z8
        This evaluator does not require input.
        F r   s    r   requires_inputz(RegexMatchStringEvaluator.requires_input"   s    
 r   c                      y)z6
        This evaluator requires a reference.
        Tr   r   s    r   requires_referencez,RegexMatchStringEvaluator.requires_reference)   s    
 r   c                 
    ddgS )z^
        Get the input keys.

        Returns:
            List[str]: The input keys.
        	reference
predictionr   r   s    r   
input_keysz$RegexMatchStringEvaluator.input_keys0   s     \**r   c                      y)zb
        Get the evaluation name.

        Returns:
            str: The evaluation name.
        regex_matchr   r   s    r   evaluation_namez)RegexMatchStringEvaluator.evaluation_name:   s     r   r   r   c                r    t        j                  ||| j                        }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#   s        r   _evaluate_stringsz+RegexMatchStringEvaluator._evaluate_stringsD   s.    " JdjjAT%[)**r   )__name__
__module____qualname____doc__r$   r   r   propertyr%   r   r   r   strr   r   dictr&   __classcell__)r   s   @r   r   r      s    , ()  C     D   +DI + +   + + 	+
 + 
+r   r   )r"   typingr   r   langchain.evaluation.schemar   r   r   r   r   <module>r1      s    	  7O+ O+r   