o
    7ti                     @   s   d dl Z d dlmZmZ d dlZg dZdedefddZdedefdd	Z	dedee fd
dZ
dededdfddZdddZedkrJe  dS dS )    N)DictList)enfrjpptruzhdocreturnc                 C   s   ddd}|| d  S )a  
    Return index of the correct choice.

    Note: We are using the "multiple input" mode of the multiple-choice
        output-type, which means we use different contexts with the same target
        for the different choices, rather than the same context and different targets.
    r      )12answer )r
   answer_to_numr   r   Q/home/ubuntu/.local/lib/python3.10/site-packages/lm_eval/tasks/xwinograd/utils.pydoc_to_text   s   
r   c                 C   s&   | d  dd }| d |d  S )z
    Return the target completion.

    Note that this does not depend on the correct choice as we are using
    "multiple input" mode.
    sentence_r   N)indexstripr
   idxr   r   r   doc_to_target   s   r   c                    s2    d  d d  d g} fdd|D S )zJReturn the choices that will be used as contexts in "multiple input" mode.r   r   option1option2c                    s    g | ]} d  d | qS )r   Nr   ).0optr   r   r   
<listcomp>(   s     z!doc_to_choice.<locals>.<listcomp>)r   )r
   optionsr   r   r   doc_to_choice$   s   r!   
output_dir	overwritec              	   C   s   g }t D ]J}d| d}z4t|  d| |rdnddd}|d td	|d| d
| W d   n1 s:w   Y  W q tyN   || Y qw t|dkr_tdd| dS )z
    Generate a yaml file for each language.

    :param output_dir: The directory to output the files to.
    :param overwrite: Whether to overwrite files if they already exist.
    
xwinograd_z.yaml/wxzutf-8)encodingz# Generated by utils.py
xwinograd_common_yaml)includedataset_nametaskNr   zJFiles were not created because they already exist (use --overwrite flag): z, )		LANGUAGESopenwriteyamldumpFileExistsErrorappendlenjoin)r"   r#   errlang	file_namefr   r   r   gen_lang_yamls+   s8   
r:   c                  C   sF   t  } | jddddd | jdddd	 |  }t|j|jd
 dS )z9Parse CLI args and generate language-specific yaml files.z--overwriteF
store_truez%Overwrite files if they already exist)defaultactionhelpz--output-dir.z Directory to write yaml files to)r<   r>   )r"   r#   N)argparseArgumentParseradd_argument
parse_argsr:   r"   r#   )parserargsr   r   r   mainL   s   rF   __main__)r   N)r@   typingr   r   r0   r-   intr   strr   r!   boolr:   rF   __name__r   r   r   r   <module>   s    
!
