|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from argparse import ArgumentParser |
|
parser = ArgumentParser() |
|
|
|
|
|
parser.add_argument("--output_path", "-op", type=str, default="./") |
|
args, opt = parser.parse_known_args() |
|
|
|
dataset = 'all2023' |
|
split = 'val' |
|
output_path = args.output_path |
|
|
|
|
|
|
|
|
|
|
|
import pandas as pd |
|
import numpy as np |
|
import os |
|
from tqdm import tqdm |
|
|
|
|
|
IGNORED_CATEGOREIES = set([ |
|
"atom-ph", "bayes-an", "chao-dyn", "chem-ph", "cmp-lg", "comp-gas", "cond-mat", "dg-ga", "funct-an", |
|
"mtrl-th", "patt-sol", "plasm-ph", "q-alg", "q-bio", "solv-int", "supr-con", "test", "test.dis-nn", |
|
"test.mes-hall", "test.mtrl-sci", "test.soft", "test.stat-mech", "test.str-el", "test.supr-con" |
|
]) |
|
print("number of ignored categories: ", len(IGNORED_CATEGOREIES)) |
|
CATEGORY_ALIASES = { |
|
'math.MP': 'math-ph', |
|
'stat.TH': 'math.ST', |
|
'math.IT': 'cs.IT', |
|
'q-fin.EC': 'econ.GN', |
|
'cs.SY': 'eess.SY', |
|
'cs.NA': 'math.NA' |
|
} |
|
print("number of category aliases: ", len(CATEGORY_ALIASES)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file_path = 'data/raw/all2023/all-2023-new-reps.tsv' |
|
save_dir = os.path.join(output_path, dataset) |
|
os.makedirs(save_dir, exist_ok=True) |
|
save_path = os.path.join(save_dir, f"{split}.json") |
|
print("Reading from file: ", file_path) |
|
|
|
FEATURES = [ |
|
'paper_id', |
|
'version', |
|
'yymm', |
|
'created', |
|
'title', |
|
'secondary_subfield', |
|
'abstract', |
|
'primary_subfield', |
|
'field', |
|
'fulltext' |
|
] |
|
|
|
for i, original_df in tqdm(enumerate(pd.read_csv(file_path, sep='\t', chunksize=10**4))): |
|
|
|
original_df.drop(columns=['type', 'status'], inplace=True) |
|
|
|
|
|
original_df.rename(columns={ |
|
'category': 'primary_subfield', |
|
'doc_paper_id': 'paper_id', |
|
'version title': 'version', |
|
}, inplace=True) |
|
|
|
for feature in FEATURES: |
|
if feature not in original_df.columns: |
|
original_df[feature] = "" |
|
|
|
|
|
df = original_df[~original_df['primary_subfield'].isin(IGNORED_CATEGOREIES)] |
|
df = df[(df['version'] == 1)] |
|
if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum(): |
|
ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ") |
|
|
|
|
|
if i == 0: |
|
df.astype(str).to_json(save_path, lines=True, orient="records") |
|
else: |
|
df.astype(str).to_json(save_path, lines=True, orient="records", mode='a') |
|
|
|
print("Saved to: ", save_path) |
|
|
|
|