-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotation_list.py
33 lines (25 loc) · 1.2 KB
/
annotation_list.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
from annotation import Annotation
class AnnotationList(object):
def __init__(self, dandelion_raw_list):
self.dandelion_raw_list = dandelion_raw_list
self.good_annotations = []
if self.dandelion_raw_list:
for annotation_dict in self.dandelion_raw_list.get("annotations", []):
my_annotation = Annotation(annotation_dict)
if not my_annotation.suppress:
for top_entity in self.dandelion_raw_list.get("topEntities", []):
if my_annotation.uri == top_entity["uri"]:
my_annotation.is_top_entity = True
my_annotation.top_entity_score = top_entity["score"]
self.good_annotations.append(my_annotation)
@property
def raw_annotations(self):
return self.dandelion_raw_list["annotations"]
def list(self):
return self.good_annotations
def to_dict_simple(self):
response = [a.to_dict_simple() for a in self.good_annotations if a.confidence >= 0.65]
return response
def picture_candidates(self):
response = [a.to_dict_simple() for a in self.good_annotations]
return response