o ׊_c�@sNddlZddlZdd�Zdd�Zdd�Zdd �Zd d �Zdd d�Zdd�ZdS)�NcCs@g}t�|�D]\}}}|D]}tj�||�}|�|�qq|S)N)�os�walk�path�join�append)�dirnameZfl�root�dirs�files�itemr�r �2/Users/sunweiwei/IRLab/generet/generet/utils/io.py�all_files �rcCs>t|dd��}dd�|D�Wd�S1swYdS)N�utf-8��encodingcSsg|]}|dd��qS)N�����r )�.0�liner r r � �zread_file..)�open��filename�fr r r � read_files $�rcCs�d�|�d�dd��}z tj|dd�WnYt|ddd��}|D] }|�t|�d�q$Wd�dS1s;wYdS) N�/rT��exist_ok�wrr� )r�splitr�makedirsr�write�str)�objrrrrr r r � write_files�"�r&cCsbd�|�d�dd��}tj|dd�t|d��}t�||�Wd�dS1s*wYdS)NrrTr�wb)rr!rr"r�pickle�dump)r%rrrr r r � write_pkls  "�r*cCs8t|d�� }t�|�Wd�S1swYdS)NZrb)rr(�loadrr r r �read_pkl%s $�r,�cs(t��|d���fdd�t|�D�S)Nr-cs$g|]}�|�|d���qS�r-r )rZids��inpZlengthr r r,s$zseg_array..)�len�range)r0Znumr r/r � seg_array*sr3cCsLt|�}gg}|D]}|dkr|�g�q |d�|�q dd�|D�}|S)N�rcSsg|]}|gkr|�qSr r )rr r r r r7rzread_dialog..)rr)r�raw�datarr r r � read_dialog/s r7r.) rr(rrr&r*r,r3r7r r r r �s