
    j?                         d dl mZmZmZmZmZ 	 d dlZd dlmZ d dl
mZ d dlmZmZ 	 d dlmZ eee   egef   Z G d dej*                        Zy# e	$ r dZdZY Bw xY w# e	$ r dZY :w xY w)	    )AnyCallableOptionalSequenceUnionN)wordnet)MetricComputationError)base_metricscore_result)meteor_scorec                        e Zd ZdZ	 	 	 	 	 	 	 ddee   dededededed	ee   d
df fdZ	dede
eee   f   ded
ej                  fdZ xZS )METEORa  Computes the METEOR score between output and reference text.

    This implementation wraps ``nltk.translate.meteor_score.meteor_score`` while
    allowing a custom scoring function to be injected (useful for testing).

    References:
      - Banerjee & Lavie, "METEOR: An Automatic Metric for MT Evaluation with Improved
        Correlation with Human Judgments" (ACL Workshop 2005)
        https://aclanthology.org/W05-0909/
      - Hugging Face Evaluate: METEOR metric overview
        https://huggingface.co/spaces/evaluate-metric/meteor

    Args:
        meteor_fn: Optional callable with the same interface as
            ``nltk.translate.meteor_score.meteor_score``. When omitted the
            function from NLTK is used.
        alpha: Precision weight.
        beta: Penalty exponent.
        gamma: Fragmentation penalty weight.
        name: Optional metric name.
        track: Whether Opik should track the metric automatically.
        project_name: Optional project name used when tracking.
    N	meteor_fnalphabetagammanametrackproject_namereturnc                    t         
|   |||       ||| _        y t        t	        d      t
        t        	 t        j                          dt        t           d	t        d
t        ffd}	|	| _        y # t        $ rd 	 t        j                  dd       t        j                  dd       t        j                          n# t        $ r}t	        d      |d }~ww xY wY w xY w)N)r   r   r   zjMETEOR metric requires the optional 'nltk' package. Install via `pip install nltk` or provide `meteor_fn`.r   T)quietzomw-1.4zMETEOR metric requires the NLTK corpora 'wordnet' and 'omw-1.4'. Install manually via `python -m nltk.downloader wordnet omw-1.4`.
references
hypothesisr   c           	          	 t        t        j                  | |            S # t        $ r}t	        d      |d }~ww xY w)N)r   r   r   zdNLTK resource requirement for METEOR not satisfied. Download WordNet via `nltk.download('wordnet')`.)floatnltk_meteor_scorer   LookupErrorr	   )r   r   errorr   r   r   s      /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/metrics/heuristics/meteor.py_scorerz METEOR.__init__.<locals>._scorerT   sY    
! )66&
%dRW 
 # !0K !!!s   "& 	A ;A )super__init__
_meteor_fnr   ImportErrornltkr   ensure_loadedr   download	Exceptionr   strr   )selfr   r   r   r   r   r   r   download_errorr!   	__class__s     ```     r    r#   zMETEOR.__init__/   s     	d%lK 'DO (!B 
 G$7.))+!HSM !s !u ! &DO3  ..it<it<--/$ .)`  ... 0.s6   A< <	C)AC	C)		C#CC##C)(C)output	referenceignored_kwargsc                 H   |j                         st        d      t        |t              r|g}nt	        |      }|rt        d |D              rt        d      | j                  ||      }t        j                  t        |      | j                  dt        |      d      S )Nz#Candidate is empty (METEOR metric).c              3   >   K   | ]  }|j                            y w)N)strip).0refs     r    	<genexpr>zMETEOR.score.<locals>.<genexpr>o   s      GJSSYY[Js   z#Reference is empty (METEOR metric).zMETEOR score: z.4f)valuer   reason)r3   r	   
isinstancer*   listanyr$   r   ScoreResultr   r   )r+   r.   r/   r0   r   scores         r    r=   zMETEOR.scorec   s     ||~()NOOi%)2JiJS GJ GG()NOO
F3'',#E%L#56
 	
    )Ng?g      @g      ?meteor_metricTN)__name__
__module____qualname____doc__r   MeteorFnr   r*   boolr#   r   r   r   r   r<   r=   __classcell__)r-   s   @r    r   r      s    4 )-#&*2&H%2& 2& 	2&
 2& 2& 2& sm2& 
2&h

 hsm+,
 	

 
	!	!
r>   r   )typingr   r   r   r   r   r&   nltk.corpusr   r%   opik.exceptionsr	   opik.evaluation.metricsr
   r   nltk.translater   r   r*   r   rD   
BaseMetricr    r>   r    <module>rN      s    ; ;#
 3 =@
 Xc]C(%/0a
[## a
!  DG  s"   
A A  	AA A*)A*