-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotate.py
49 lines (40 loc) · 1.34 KB
/
annotate.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
import argparse
import json
import os
from pgr import PathwayGenerator
def main(path, pilot, service):
pgr = PathwayGenerator(file_path=path, pilot=pilot, service=service, use_cuda=True, cuda_device=4, annotation_model='en')
ner_dict = pgr.do_annotate(pgr.to_list())
doccano_dict, ner_path = pgr.export_annotation_to_doccano()
response = input('Do you want to export the ner_dict object into a .json file? y/n:\t')
if response == 'y':
file_out = open(os.path.splitext(pgr.path)[0] +'_ner.json', 'w', encoding='utf-8')
file_out.write(json.dumps(ner_dict))
file_out.write('\n')
print('Annotation process ended. You can find the jsonl at the following path: {}'.format(ner_path))
if __name__ == '__main__':
"""Input example:
$python annotate.py --file \
filename.txt
"""
parser = argparse.ArgumentParser()
parser.add_argument(
'-f',
'--file',
help='List of files to be converted before transner',
required=True
)
parser.add_argument(
'-p',
'--pilot',
help='Specify pilot.',
required=True
)
parser.add_argument(
'-s',
'--service',
help='Specify service.',
required=True
)
args = parser.parse_args()
main(path=args.file, pilot=args.pilot, service=args.service)