
    j                     Z    d dl Z d dlmZmZmZ ddlmZmZ  G d dej                        Z	y)    N)AnyUnionOptional   )base_metricscore_resultc            
            e Zd ZdZ	 	 	 ddeeej                  f   dedede	e   f fdZ
deded	ej                  fd
Z xZS )
RegexMatcha  
    A metric that checks if an output string matches a given regular expression pattern.

    This metric returns a score of 1.0 if the output string matches the regex pattern,
    and 0.0 otherwise.

    Args:
        regex: The regular expression pattern to match against. Can be a string or a compiled regex pattern.
        name: The name of the metric. Defaults to "regex_match_metric".
        track: Whether to track the metric. Defaults to True.
        project_name: Optional project name to track the metric in for the cases when there are no parent span/trace to inherit project name from.

    Example:
        >>> from opik.evaluation.metrics import RegexMatch
        >>> regex_metric = RegexMatch("\d{3}-\d{2}-\d{4}")
        >>> result = regex_metric.score("My SSN is 123-45-6789")
        >>> print(result.value)
        1.0
        >>> result = regex_metric.score("My phone is 555-1234")
        >>> print(result.value)
        0.0
    regexnametrackproject_namec                     t         |   |||       t        |t              rt	        j
                  |      | _        y || _        y )N)r   r   r   )super__init__
isinstancestrrecompile_regex_pattern)selfr   r   r   r   	__class__s        /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/metrics/heuristics/regex_match.pyr   zRegexMatch.__init__   sJ     	% 	 	
 ",E3!7BJJu 	=B 	    outputignored_kwargsreturnc                     | j                   j                  |      r!t        j                  d| j                        S t        j                  d| j                        S )a  
        Calculate the score based on whether the output string matches the regex pattern.

        Args:
            output: The output string to check against the regex pattern.
            **ignored_kwargs: Additional keyword arguments that are ignored.

        Returns:
            score_result.ScoreResult: A ScoreResult object with a value of 1.0 if the output
                matches the regex pattern, 0.0 otherwise.
        g      ?)valuer   g        )r   searchr   ScoreResultr   )r   r   r   s      r   scorezRegexMatch.score0   sF     %%f-++#DIIFF''c		BBr   )regex_match_metricTN)__name__
__module____qualname____doc__r   r   r   Patternboolr   r   r   r   r!   r"   __classcell__)r   s   @r   r
   r
      ss    4 )&*
S"**_%
 
 	

 sm
"CC C3 C<;S;S Cr   r
   )
r   typingr   r   r    r   r   
BaseMetricr
    r   r   <module>r/      s%    	 ' ' (8C'' 8Cr   