| import json |
| import os |
| import glob |
| import re |
|
|
| DATA_DIR = '/mnt/data/projects/GomParam-v1/data' |
|
|
| def remove_english(text): |
| if not isinstance(text, str): |
| return text |
| |
| cleaned = re.sub(r'\s*\([A-Za-z\s/,-]+\)', '', text) |
| return cleaned.strip() |
|
|
| def process_file(filepath): |
| with open(filepath, 'r', encoding='utf-8') as f: |
| data = json.load(f) |
| |
| modified = False |
| for item in data: |
| for key in ['context', 'question', 'ans', 'sentence', 'passage']: |
| if key in item and isinstance(item[key], str): |
| new_val = remove_english(item[key]) |
| if new_val != item[key]: |
| item[key] = new_val |
| modified = True |
| |
| if 'candidates' in item: |
| new_cands = [] |
| for cand in item['candidates']: |
| new_cand = remove_english(cand) |
| if new_cand != cand: |
| modified = True |
| new_cands.append(new_cand) |
| item['candidates'] = new_cands |
|
|
| if modified: |
| with open(filepath, 'w', encoding='utf-8') as f: |
| json.dump(data, f, ensure_ascii=False, indent=2) |
| print(f"Fixed {os.path.basename(filepath)}") |
|
|
| def main(): |
| for file in glob.glob(os.path.join(DATA_DIR, '*.json')): |
| process_file(file) |
|
|
| if __name__ == '__main__': |
| main() |
|
|