-
Notifications
You must be signed in to change notification settings - Fork 1
/
entity_check.py
36 lines (25 loc) · 955 Bytes
/
entity_check.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
def calcEntityCheck(headQuery,tailQuery,dxtr):
# getting entites in the head query
head_result=dxtr.nice_annotate(headQuery, min_conf=0.8)
# print head_entities
head_entities=set()
for item in head_result:
if type(item)==tuple:
head_entities.add(item[1])
# print head_entities
# getting entites in the tail query
tail_result=dxtr.nice_annotate(tailQuery, min_conf=0.8)
tail_entities=set()
for item in tail_result:
if type(item)==tuple:
tail_entities.add(item[1])
# print tail_entities
# getting the common entities
common_entites=head_entities.intersection(tail_entities)
# print common_entites
if (len(head_entities)+len(tail_entities)-len(common_entites))==0:
return 0
else:
entity_score= float(len(common_entites))/(len(head_entities)+len(tail_entities)-len(common_entites))
return entity_score
# entity_check("Dexter is an American television series","Comedy Central is an American television channel")