-
Notifications
You must be signed in to change notification settings - Fork 0
/
ner_utils.py
47 lines (39 loc) · 1.14 KB
/
ner_utils.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
"""
Type: Utility function
Developer: Vignesh
Description: Supporting function for ner_bert.py
"""
def get_tags(input):
next = 0
tag = ''
entity = ''
record = {'ORG_E': [], 'PER_E': [], 'LOC_E': [], 'MISC_E': []}
entities = []
cat = {'ORG': 0, 'PER': 0, 'LOC': 0, 'MISC': 0}
for pred in input:
w = pred['word']
pred_tag = pred['tag']
if w != "PADword":
if pred_tag[0] == "B":
if next == 1:
record[tag+'_E'].append(entity)
cat[tag] = 1
else:
tag = pred_tag[2:]
#print(tag)
entity = w
next = 1
elif pred_tag[0] == 'I':
entity += ' '+w
else:
next = 0
if next == 0 and tag != '':
#print(tag)
record[tag+'_E'].append(entity)
cat[tag] = 1
tag = ''
if next == 1:
record[tag+'_E'].append(entity)
for key in record:
record[key] = list(set(record[key]))
return record, cat