o
    5tir                     @   s   d Z ddlZddlZddlZddlmZmZmZ ddlmZm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ eeZeG d	d
 d
ZeG dd deZeG dd deZeG dd deZdS )zP EvaluationModuleInfo records information we know about a dataset and a metric.
    N)asdict	dataclassfield)ListOptionalUnion)FeaturesValue   )config)
get_loggerc                   @   s$  e Zd ZU dZeed< eed< eeee f ed< e	edZ
eed< e	edZeed< e	edZeed< e	edZee ed	< e	edZee ed
< dZeed< dZee ed< dZeed< dZee ed< dZee ed< dZee ed< dd Zdd ZedddZededd fddZdS )EvaluationModuleInfoal  Base class to store information about an evaluation used for `MetricInfo`, `ComparisonInfo`,
    and `MeasurementInfo`.

    `EvaluationModuleInfo` documents an evaluation, including its name, version, and features.
    See the constructor arguments and properties for a full list.

    Note: Not all fields are known on construction and may be updated later.
    descriptioncitationfeatures)default_factoryinputs_descriptionhomepagelicensecodebase_urlsreference_urlsF
streamableNformatmetricmodule_typemodule_nameconfig_nameexperiment_idc                 C   sH   | j d ur | j D ]\}}t|tstd| d|jj q
d S d S )NzSWhen using 'numpy' format, all features should be a `datasets.Value` feature. Here z is an instance of )r   r   items
isinstancer	   
ValueError	__class____name__)selfkeyvalue r&   A/home/ubuntu/.local/lib/python3.10/site-packages/evaluate/info.py__post_init__?   s   

z"EvaluationModuleInfo.__post_init__c                 C   s   t tj|tjddd}tt| | W d   n1 s w   Y  t tj|tj	ddd}|
| j W d   dS 1 sDw   Y  dS )aZ  Write `EvaluationModuleInfo` as JSON to `metric_info_dir`.
        Also save the license separately in LICENSE.

        Args:
            metric_info_dir (`str`):
                The directory to save `metric_info_dir` to.

        Example:

        ```py
        >>> my_metric.info.write_to_directory("/path/to/directory/")
        ```
        wutf-8encodingN)openospathjoinr   METRIC_INFO_FILENAMEjsondumpr   LICENSE_FILENAMEwriter   )r#   metric_info_dirfr&   r&   r'   write_to_directoryH   s   "z'EvaluationModuleInfo.write_to_directoryreturnc                 C   sh   t d|  |stdttj|tjdd}t	
|}W d   n1 s*w   Y  | |S )a  Create `EvaluationModuleInfo` from the JSON file in `metric_info_dir`.

        Args:
            metric_info_dir (`str`):
                The directory containing the `metric_info` JSON file. This
                should be the root directory of a specific metric version.

        Example:

        ```py
        >>> my_metric = EvaluationModuleInfo.from_directory("/path/to/directory/")
        ```
        zLoading Metric info from zMCalling EvaluationModuleInfo.from_directory() with undefined metric_info_dir.r*   r+   N)loggerinfor    r-   r.   r/   r0   r   r1   r2   load	from_dict)clsr6   r7   metric_info_dictr&   r&   r'   from_directory\   s   
z#EvaluationModuleInfo.from_directoryr?   c                    s4   dd t | D  | di  fdd| D S )Nc                 S   s   h | ]}|j qS r&   )name).0r7   r&   r&   r'   	<setcomp>u   s    z1EvaluationModuleInfo.from_dict.<locals>.<setcomp>c                    s   i | ]\}}| v r||qS r&   r&   )rB   kvfield_namesr&   r'   
<dictcomp>v   s    z2EvaluationModuleInfo.from_dict.<locals>.<dictcomp>r&   )dataclassesfieldsr   )r>   r?   r&   rF   r'   r=   s   s    zEvaluationModuleInfo.from_dict)r9   r   )r"   
__module____qualname____doc__str__annotations__r   r   r   r   r   r   r   listr   r   r   boolr   r   r   r   r   r   r(   r8   classmethodr@   dictr=   r&   r&   r&   r'   r   "   s,   
 
	r   c                   @      e Zd ZU dZdZeed< dS )
MetricInfoa  Information about a metric.

    `EvaluationModuleInfo` documents a metric, including its name, version, and features.
    See the constructor arguments and properties for a full list.

    Note: Not all fields are known on construction and may be updated later.
    r   r   Nr"   rK   rL   rM   r   rN   rO   r&   r&   r&   r'   rU   y      
 rU   c                   @   rT   )ComparisonInfoa  Information about a comparison.

    `EvaluationModuleInfo` documents a comparison, including its name, version, and features.
    See the constructor arguments and properties for a full list.

    Note: Not all fields are known on construction and may be updated later.
    
comparisonr   NrV   r&   r&   r&   r'   rX      rW   rX   c                   @   rT   )MeasurementInfoa  Information about a measurement.

    `EvaluationModuleInfo` documents a measurement, including its name, version, and features.
    See the constructor arguments and properties for a full list.

    Note: Not all fields are known on construction and may be updated later.
    measurementr   NrV   r&   r&   r&   r'   rZ      rW   rZ   )rM   rI   r2   r.   r   r   r   typingr   r   r   datasets.featuresr   r	    r   utils.loggingr   r"   r:   r   rU   rX   rZ   r&   r&   r&   r'   <module>   s$   V