-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_yml_to_tsv.py
executable file
·58 lines (39 loc) · 1.41 KB
/
convert_yml_to_tsv.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
53
54
55
56
57
58
# convert_yml_to_tsv.py
# Copyright 2019 Robert Jones [email protected] Craic Computing LLC
# This software is made freely available under the terms of the MIT license
# yaml format is
#
#- id: '28955949'
# text: 'Anti-IL-17A blocking antibody reduces cyclosporin A-induced relapse in experimental
# autoimmune encephalomyelitis mice. CNS, central nervous system CsA, cyclosporine
# TSV output format is
#
# <id> <label> <arbitrary char> <text>
import os
import yaml
import argparse
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--file", required=True, help="path to yaml file")
ap.add_argument("--label", required=True, help="label - integer")
args = vars(ap.parse_args())
file = args["file"]
label = args["label"]
data = []
with open(file, 'r') as f:
data = yaml.load(f)
static_char = 'a'
for record in data:
id = record['id']
text = record['text']
# strip internal newlines and tabs
text = text.replace('\n',' ')
text = text.replace('\t',' ')
# just get 1000 characters
#text = text[:1000]
# ... output the entire text - let bert select N words
# convert the text to lower case - unlclear if bert does this
text = text.lower()
print("{:s}\t{:s}\t{:s}\t{:s}".format(id, label, static_char, text))
if __name__ == "__main__":
main()