| | import json |
| | import re |
| |
|
| | def clean_prefixes(data): |
| | cleaned_data = {} |
| | prefix_pattern = re.compile(r'^/c/[^/]+/') |
| |
|
| | for lang, words in data.items(): |
| | cleaned_words = {} |
| | for key, values in words.items(): |
| | |
| | cleaned_key = prefix_pattern.sub('', key).replace('_', ' ') |
| | |
| | |
| | cleaned_values = [prefix_pattern.sub('', value).replace('_', ' ') for value in values] |
| | |
| | cleaned_words[cleaned_key] = cleaned_values |
| | |
| | cleaned_data[lang] = cleaned_words |
| | |
| | return cleaned_data |
| |
|
| | |
| | input_file_path = "cn_relations.json" |
| | with open(input_file_path, "r") as json_file: |
| | data = json.load(json_file) |
| |
|
| | cleaned_data = clean_prefixes(data) |
| |
|
| | print(cleaned_data['zdj']) |
| |
|
| | |
| | output_file_path = "cn_relations_clean.json" |
| | with open(output_file_path, "w") as json_file: |
| | json.dump(cleaned_data, json_file, ensure_ascii=False, indent=4) |
| |
|