-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregate.py
More file actions
43 lines (31 loc) · 871 Bytes
/
aggregate.py
File metadata and controls
43 lines (31 loc) · 871 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
32
33
34
35
36
37
38
39
40
41
42
43
from tools import aggregator
import argparse
import re
import pdb
import json
import os
def export_to_json(ner_dict, path):
json_file = json.dumps(ner_dict, indent=4)
filename = re.sub('_ner.json', '_cluster.json', path)
f = open(filename, 'w')
f.write(json_file)
f.close()
def main(path=None):
json_file = open(path, 'r')
ner_dict = json.load(json_file)
aggregated_ner_dict = aggregator.aggregate_entities(ner_dict)
export_to_json(aggregated_ner_dict, path)
if __name__ == '__main__':
"""Input example:
$python convert.py --file \
filename.json
"""
parser = argparse.ArgumentParser()
parser.add_argument(
'-f',
'--file',
help='List of files to be converted before transner',
required=False
)
args = parser.parse_args()
main(path=args.file)