
    AhX	                     :    S SK r S SKJr  S SKJr   " S S\5      rg)    N)Any)StringEvaluatorc                      ^  \ rS rSrSrSS.S\S\4U 4S jjjr\S\	4S	 j5       r
\S\	4S
 j5       r\S\\   4S j5       r\S\4S j5       rS\S\S\S\4S jrSrU =r$ )RegexMatchStringEvaluator   a  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                .   > [         TU ]  5         Xl        g )N)super__init__r	   )selfr	   r
   	__class__s      ]/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/evaluation/regex_match/base.pyr   "RegexMatchStringEvaluator.__init__   s    
    returnc                     g)z(
This evaluator does not require input.
F r   s    r   requires_input(RegexMatchStringEvaluator.requires_input"   s    
 r   c                     g)z&
This evaluator requires a reference.
Tr   r   s    r   requires_reference,RegexMatchStringEvaluator.requires_reference)   s    
 r   c                 
    SS/$ )z>
Get the input keys.

Returns:
    List[str]: The input keys.
	reference
predictionr   r   s    r   
input_keys$RegexMatchStringEvaluator.input_keys0   s     \**r   c                     g)zB
Get the evaluation name.

Returns:
    str: The evaluation name.
regex_matchr   r   s    r   evaluation_name)RegexMatchStringEvaluator.evaluation_name:   s     r   r   r   c                l    [         R                  " X!U R                  S9nS[        [	        U5      5      0$ )z
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_strings+RegexMatchStringEvaluator._evaluate_stringsD   s,    " djjAT%[)**r   )__name__
__module____qualname____firstlineno____doc__r)   r   r   propertyr*   r   r   liststrr   r#   dictr+   __static_attributes____classcell__)r   s   @r   r   r      s    , ()  C      D   +DI + +   + + 	+
 + 
+ +r   r   )r'   typingr   langchain.evaluation.schemar   r   r   r   r   <module>r:      s    	  7O+ O+r   