-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocessjournals.py
52 lines (46 loc) · 1.88 KB
/
processjournals.py
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
# Temporary script for processing journal output from Eprints into a JSONL file
# for import into InvenioRDM and journals where human curation is needed
import csv, json
from idutils import is_issn, normalize_issn
issn_count = {}
vocab = []
with open("journal-names.tsv", "r") as f:
reader = csv.DictReader(f, delimiter="\t")
for row in reader:
issn = row["ISSN"]
if is_issn(issn):
issn = normalize_issn(issn)
issn_count[issn] = issn_count.get(issn, 0) + 1
multiple = {}
with open("journal-names.tsv", "r") as f:
reader = csv.DictReader(f, delimiter="\t")
for row in reader:
issn = row["ISSN"]
if is_issn(issn):
issn = normalize_issn(issn)
if issn_count[issn] > 1:
existing = multiple.get(issn)
if issn_count[issn] == 2:
if existing:
if row["Publisher"] == "NULL":
vocab.append({"id": issn, "title": {"en": existing[0]}})
else:
if row["Publisher"] != "NULL":
vocab.append(
{"id": issn, "title": {"en": row["Journal Name"]}}
)
else:
if existing:
multiple[issn].append([row["Journal Name"], row["Publisher"]])
else:
multiple[issn] = [[row["Journal Name"], row["Publisher"]]]
else:
vocab.append({"id": issn, "title": {"en": row["Journal Name"]}})
with open("journals.jsonl", "w") as f:
for group in vocab:
f.write(json.dumps(group) + "\n")
with open("multiple.tsv", "w") as f:
writer = csv.writer(f, delimiter="\t")
for key, listings in multiple.items():
for val in listings:
writer.writerow([key, val[0], val[1]])