
    j0
                     V    d dl mZmZ d dlZddlmZmZ  G d dej                        Z	y)    )AnyOptionalN   )base_metricscore_resultc            
       p     e Zd ZdZ	 	 	 	 ddedededee   f fdZdeded	ed
e	j                  fdZ xZS )LevenshteinRatioay  
    A metric that calculates the Levenshtein ratio between two strings.

    This metric returns a score between 0.0 and 1.0, representing the similarity
    between the output and reference strings. A score of 1.0 indicates identical strings,
    while 0.0 indicates completely different strings. The comparison can be made
    case-sensitive or case-insensitive.

    For more information on Levenshtein distance, see:
    https://en.wikipedia.org/wiki/Levenshtein_distance

    Args:
        case_sensitive: Whether the comparison should be case-sensitive. Defaults to False.
        name: The name of the metric. Defaults to "levenshtein_ratio_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 LevenshteinRatio
        >>> levenshtein_metric = LevenshteinRatio(case_sensitive=True)
        >>> result = levenshtein_metric.score("Hello, World!", "Hello, World")
        >>> print(result.value)
        0.96
    case_sensitivenametrackproject_namec                 8    t         |   |||       || _        y )N)r   r   r   )super__init___case_sensitive)selfr
   r   r   r   	__class__s        /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/metrics/heuristics/levenshtein_ratio.pyr   zLevenshteinRatio.__init__!   s*     	% 	 	
  .    output	referenceignored_kwargsreturnc                    | j                   r|n|j                         }| j                   r|n|j                         }t        j                  j                  j                  ||      }t        j                  || j                        S )a  
        Calculate the Levenshtein ratio between the output and reference strings.

        Args:
            output: The output string to compare.
            reference: The reference string to compare against.
            **ignored_kwargs: Additional keyword arguments that are ignored.

        Returns:
            score_result.ScoreResult: A ScoreResult object with a value between 0.0 and 1.0,
                representing the Levenshtein ratio between the output and reference strings.
        )valuer   )	r   lower	rapidfuzzdistanceIndelnormalized_similarityr   ScoreResultr   )r   r   r   r   r   scores         r   r"   zLevenshteinRatio.score0   sd     ..FLLN!%!5!5I9??;L	""((>>uiP''e$))DDr   )Flevenshtein_ratio_metricTN)__name__
__module____qualname____doc__boolstrr   r   r   r   r!   r"   __classcell__)r   s   @r   r	   r	      su    6  %.&*.. . 	.
 sm.EE&)E=@E		!	!Er   r	   )
typingr   r   rapidfuzz.distance.Indelr    r   r   
BaseMetricr	    r   r   <module>r0      s"       (<E{-- <Er   