Arxiv / categories.py
chungimungi's picture
Upload 2 files
0fcf8aa verified
raw
history blame contribute delete
No virus
930 Bytes
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}")