|
|
|
|
|
import random |
|
import sys, os, pdb |
|
import json, math |
|
import datasets |
|
from datasets import load_dataset |
|
import csv |
|
import shutil |
|
|
|
random.seed(42) |
|
|
|
class UniformFileName(object): |
|
def __init__(self) -> None: |
|
pass |
|
|
|
def _load_dir_json(self, dir_path=None): |
|
if dir_path is None or not os.path.exists(dir_path): return None |
|
total_data = [] |
|
for filename in sorted(os.listdir(dir_path)): |
|
if not filename.startswith("dialogues_"): continue |
|
if not filename.endswith(".json"): continue |
|
file_path = os.path.join(dir_path, filename) |
|
data = self._load_json(path=file_path) |
|
if type(data) == list: |
|
total_data.extend(data) |
|
else: |
|
total_data.append(data) |
|
return total_data |
|
|
|
def uniform(self): |
|
for category in os.listdir("."): |
|
if not os.path.isdir(os.path.join("./", category)): continue |
|
for data_name in os.listdir(os.path.join("./", category)): |
|
if not os.path.isdir(os.path.join("./", category, data_name)): continue |
|
for mode in ["train", "val", "test"]: |
|
folder_to_check = os.path.join("./", category, data_name, mode) |
|
if not os.path.exists(folder_to_check): continue |
|
filelist = os.listdir(folder_to_check) |
|
if "dialogues_1.json" in filelist: continue |
|
if "dialogs_1.json" not in filelist: raise ValueError(f"dialog file does not exist for {folder_to_check}") |
|
for filename in filelist: |
|
if filename.startswith("dialogs_") and filename.endswith(".json"): |
|
filename_new = filename.replace("dialogs_", "dialogues_") |
|
shutil.copy(os.path.join(folder_to_check, filename), os.path.join(folder_to_check, filename_new)) |
|
print(f"copy from {filename} to {filename_new} in {folder_to_check}") |
|
|
|
def main(): |
|
uniform = UniformFileName() |
|
uniform.uniform() |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|
|
|