o
    6ti                     @   sn   d dl Z d dlZddedefddZdee dee fd	d
Z	ddededefddZ	dee fddZ
dS )    NFqsheet
no_contextc                 C   s   t | d }d}|D ]$}|d|d  d7 }|d D ]}||d  d|d  7 }|d7 }qq|r>| d	  d
| d}|S | d	  d| d  d
| d}|S )N	questions 
prompt
subpromptsquestionpart_n questionpreamblez

                 z
                 context)jsonloads)r   r   subquestionsall_subquestionssqspr    r   O/home/ubuntu/.local/lib/python3.10/site-packages/lm_eval/tasks/lingoly/utils.pyload_questionsheet   s&   


r   questionpart_nsanswersc                 C   s@   i }i }t | D ]\}}d||< || ||< qt|}||fS )Nr   )	enumerater   dumps)r   r   formatted_outputformatted_answersiqnr   r   r   format_answers   s   
r   question_indexc                 C   s   t | d }|| }d}g }g }|d|d  d7 }|d D ]!}||d  d|d  7 }||d  ||d	  |d7 }qt||\}	}
t| |}d
| d| d|	 d}||
fS )Nr   r   r   r   r   r	   r
   r   answera  Below is a problem sheet from a lingusitics exam. You will first see the entire sheet, then be asked to respond to specific questions from the sheet. Your answers to the questions should rely only on reasoning about the information provided in the sheet.
                zJ

                Now respond to the following questions:
                zg

                Format your response as a json file with the keys as provided below:
                z
                )r   r   appendr   r   )r   r    r   r   r   r   r   r   r   r   r   question_bodyr   r   r   r   load_question+   s*   

	r$   question_sheetsc                 C   s   g }g }g }g }| D ]:}t tt|d D ],}t||dd\}}t||dd\}	}
||	 || |t| ||d  qq
||||d}tj	|}|S )Nr   F)r   Toverall_question_n)r   	nc_promptr   index)
rangelenr   r   r$   r"   strdatasetsDataset	from_dict)r%   prompts
nc_promptsr   indicesr   r   r   r!   r'   _qsheetsdatasetr   r   r   load_all_questionsM   s(   

	r5   )F)r   r,   dictboolr   listr+   r   intr$   r5   r   r   r   r   <module>   s    
"