forked from manueldeprada/Pretraining-T5-PyTorch-Lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_cord19.py
More file actions
31 lines (29 loc) · 1012 Bytes
/
Copy pathextract_cord19.py
File metadata and controls
31 lines (29 loc) · 1012 Bytes
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 csv
import json
final = []
# open the file
with open('metadata.csv') as f_in:
reader = csv.DictReader(f_in)
for row in reader:
# access metadata
title = row['title']
abstract = row['abstract']
text = []
if row['pmc_json_files']:
for json_path in row['pmc_json_files'].split('; '):
with open(json_path) as f_json:
full_text_dict = json.load(f_json)
# grab full text
for paragraph_dict in full_text_dict['body_text']:
paragraph_text: str = paragraph_dict['text']
if len(paragraph_text) > 1:
text.append(paragraph_text)
if len(text) == 0 and len(abstract) < 2:
continue
final.append({
'title': title,
'abstract': abstract,
'text': text
})
with open("data/cord19-filtered.json", 'w') as f_json:
json.dump(final, f_json)