File size: 953 Bytes
f51d9c9
 
8b513d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f51d9c9
 
 
 
 
 
 
 
 
8b513d0
 
 
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
MAX_ITEMS_PREVIEW=20

class EntityCandidates:

    def __init__(self, entity_elements):
        self.entity_elements = entity_elements

    def __iter__(self):
        for entity in self.entity_elements:
            yield entity

    def __len__(self):
        return len(self.entity_elements)

    def __getitem__(self, item):
        return self.entity_elements[item]

    def pretty_print(self):
        for entity in self.entity_elements:
            entity.pretty_print()

    def __repr__(self) -> str:
        preview_str=""
        for index,entity_element in enumerate(self):
            if index>MAX_ITEMS_PREVIEW:
                break
            preview_str+="{}\n".format(entity_element.get_preview_string())
        
        return preview_str

    def __str__(self):
        return str(["entity {}: {} (<{}>)".format(i, entity.get_label(), entity.get_description()) for i, entity in
                    enumerate(self.entity_elements)])