
    Ngg	                     F    d dl Z d dlmZmZ d dlmZ  G d de          ZdS )    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                V    t                                                       || _        d S )N)super__init__r	   )selfr	   r
   	__class__s      a/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain/evaluation/regex_match/base.pyr   z"RegexMatchStringEvaluator.__init__   s$    


    returnc                     dS )z8
        This evaluator does not require input.
        F r   s    r   requires_inputz(RegexMatchStringEvaluator.requires_input"   s	    
 ur   c                     dS )z6
        This evaluator requires a reference.
        Tr   r   s    r   requires_referencez,RegexMatchStringEvaluator.requires_reference)   s	    
 tr   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                     dS )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                v    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   s5    " JdjAA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           X D    X +DI + + + X+     X+ + 	+
 + 
+ + + + + + + +r   r   )r"   typingr   r   langchain.evaluation.schemar   r   r   r   r   <module>r1      sv    				         7 7 7 7 7 7O+ O+ O+ O+ O+ O+ O+ O+ O+ O+r   