o
    }oi                     @   s>   d dl Z d dlZd dlZdd Zdd Zedkre  dS dS )    Nc                 C   s   t j| dd d}t|d?}tt|D ]/}|d | |d | }}tjj||d}	||g|	  }
dd |
D }t	d
||d	 qW d    d S 1 sOw   Y  d S )
N	)	delimiterheaderwr      )sizec                 S   s   g | ]}t |qS  )str).0id_r   r   V/home/ubuntu/.local/lib/python3.10/site-packages/scripts/construct_random_negatives.py
<listcomp>   s    z'construct_negatives.<locals>.<listcomp>)file)pdread_csvopenrangelennprandomrandinttolistprintjoin)
input_fileoutput_filenum_passagesnum_negativesqrelsfiquery_idrel_passage_id	negatives
output_ids
output_strr   r   r   construct_negatives   s   "r&   c                  C   s   t jdd} | jdtddd | jdtdd	d | jd
tddd |  }dD ]}t|j d| d|j d| d|j|j	d q'd S )NzNegative passages construction)descriptionz--datamsmarco_datasetzpath to folder with data)typedefaulthelpz--num_passagesi_ ztotal number of passagesz--num_negatives
   z number of negatives per positive)traindevz/qrels.z.tsvz/query2passages.)r   r   r   r   )
argparseArgumentParseradd_argumentr	   int
parse_argsr&   datar   r   )parserargsmoder   r   r   main    s   r8   __main__)r/   numpyr   pandasr   r&   r8   __name__r   r   r   r   <module>   s   
