File size: 930 Bytes
0fcf8aa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import json
from tqdm import tqdm
_CATEGORIES = "categories"
def get_unique_categories(json_file_path):
categories = set()
with open(json_file_path, encoding="utf8") as f:
for entry in tqdm(f, desc="Processing papers"):
data = json.loads(entry)
if _CATEGORIES in data:
categories.update(data[_CATEGORIES].split())
return categories
def save_unique_categories(categories, output_file_path):
categories_list = sorted(categories)
with open(output_file_path, 'w', encoding='utf8') as f:
json.dump(categories_list, f, ensure_ascii=False, indent=4)
json_file_path = 'arxiv-metadata-oai-snapshot.json'
output_file_path = 'categories.json'
unique_categories = get_unique_categories(json_file_path)
save_unique_categories(unique_categories, output_file_path)
print(f"Unique categories saved to {output_file_path}")
|