
    ju                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ 	 ddlmZ  G d	 d
e      Zy# e$ r dZY w xY w)zVADER sentiment metric wrapper.    )annotations)AnyOptional)
BaseMetric)ScoreResult)MetricComputationError)SentimentIntensityAnalyzerNc                  H     e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 d fdZddZ xZS )VADERSentimenta  
    Compute the VADER compound sentiment for a piece of text.

    References:
      - Hutto & Gilbert, "VADER: A Parsimonious Rule-based Model for Sentiment Analysis of
        Social Media Text" (ICWSM 2014)
        https://ojs.aaai.org/index.php/ICWSM/article/view/14550
      - VADER Sentiment GitHub repository (official implementation)
        https://github.com/cjhutto/vaderSentiment

    Args:
        name: Display name for the metric result. Defaults to
            ``"vader_sentiment_metric"``.
        track: Whether to automatically track metric results. Defaults to ``True``.
        project_name: Optional tracking project name. Defaults to ``None``.
        analyzer: Optional pre-initialised ``SentimentIntensityAnalyzer`` or
            compatible callable.

    Example:
        >>> from opik.evaluation.metrics import VADERSentiment
        >>> metric = VADERSentiment()
        >>> result = metric.score("I absolutely love this experience!")  # doctest: +SKIP
        >>> round(result.value, 2)  # doctest: +SKIP
        0.94
    c                ~    t         |   |||       ||| _        y t        t	        d      t               | _        y )N)nametrackproject_namezyVADER sentiment metric requires the optional 'nltk' package. Install via `pip install nltk` or provide a custom analyzer.)super__init__	_analyzerr	   ImportError)selfr   r   r   analyzer	__class__s        /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/metrics/heuristics/vader_sentiment.pyr   zVADERSentiment.__init__,   sM     	d%lK%DN +2!H  89DN    c                    |r|j                         st        d      | j                  j                  |      }t	        |j                  dd            }|dz   dz  }t        || j                  d|dd|i	      S )
NzText is empty (VADERSentiment).compoundg        g      ?g       @z#VADER compound score (normalized): z.4fvader)valuer   reasonmetadata)stripr   r   polarity_scoresfloatgetr   r   )r   outputignored_kwargsscoresr   
normalizeds         r   scorezVADERSentiment.scoreA   s|    V\\^()JKK//7J45n+
8C8HIv&	
 	
r   )vader_sentiment_metricTNN)
r   strr   boolr   zOptional[str]r   zOptional[Any]returnNone)r#   r)   r$   r   r+   r   )__name__
__module____qualname____doc__r   r'   __classcell__)r   s   @r   r   r      sP    8 -&*"&:: : $	:
  : 
:*
r   r   )r0   
__future__r   typingr   r   #opik.evaluation.metrics.base_metricr   $opik.evaluation.metrics.score_resultr   opik.exceptionsr   nltk.sentimentr	   r   r    r   r   <module>r9      sB    % "   : < 2&9
<
Z <
	  &!%&s   6 A A 