File size: 2,466 Bytes
0337404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9806a2a
372f231
0337404
 
 
 
 
372f231
0337404
 
 
 
 
 
 
 
c05668f
0337404
 
 
 
 
 
 
 
 
 
 
 
 
 
372f231
 
 
 
 
 
0337404
 
 
 
 
f7685b7
0337404
 
 
 
 
 
 
c05668f
 
 
 
0337404
f7685b7
0337404
f7685b7
c05668f
0337404
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# ---
# jupyter:
#   jupytext:
#     cell_metadata_filter: -all
#     custom_cell_magics: kql
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#       jupytext_version: 1.11.2
#   kernelspec:
#     display_name: arxiv-classifier-next
#     language: python
#     name: python3
# ---

# %%
# 
# parse arguments
# 
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--dataset", "-d", type=str, default="minor")
parser.add_argument("--split", "-s", type=str, default="train")
parser.add_argument("--output_path", "-op", type=str, default="./")
parser.add_argument("--input_path", "-ip", type=str, default="./data",
                    help="Path to the input data files")
args, opt = parser.parse_known_args()

dataset = args.dataset
split = args.split
output_path = args.output_path
input_path = args.input_path

# %%
# 
# Remaining imports
# 
import pandas as pd
import os
from tqdm import tqdm
from util_preprocess import preprocess_primary_secondary

# %% [markdown]
# Rename columns to reflect standarized terminology:
# - Field: Bio/cs/physics
# - Subfield: Subcategories within each
#     - Primary subfield (bio., cs.LG): Given primary subfield, you can infer the field
#     - Secondary subfields: Includes primary subfield, but also includes any subfields that were tagged in the paper (1-5)
#
# Old terminology to standardized terminology translation:
# - Prime category = Primary subfield
# - Abstract category = secondary subfield
# - Major category = field

# %%
file_path = os.path.join(
    input_path, 
    'raw', 
    dataset, 
    f"{split}_{dataset}_cats_full.json"
)
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)

for i, original_df in tqdm(enumerate(pd.read_json(file_path, lines=True, chunksize=10**4, dtype=str))):
    # Rename columns
    original_df.rename(columns={
        'major_category':   'field',
        'prime_category':   'primary_subfield',
        'abs_categories':   'secondary_subfield'
    }, inplace=True)

    # Apply preprocessing rules
    df = preprocess_primary_secondary(original_df)

    # Save to file
    if i == 0:
        df.to_json(save_path, lines=True, orient="records")
    else:
        df.to_json(save_path, lines=True, orient="records", mode='a')
print("Saved to file: ", save_path)
# %%