-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.py
33 lines (25 loc) · 864 Bytes
/
entity.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
# Contains information regarding the Entity Class
# Entities refer to entities in language processed by the Google ML NLP platform.
class Entity():
def __init__(self, name, entity_type):
self.name = name
self.type = entity_type
self.count = 0
self.salience_sum = 0
self.score_sum = 0
self.magnitude_sum = 0
def increment_count(self):
self.count += 1
def increment_salience(self, salience):
self.salience_sum += salience
def increment_score(self, score):
self.score_sum += score
def increment_magnitude(self, magnitude):
self.magnitude_sum += magnitude
def avg_score(self):
return self.score_sum / self.count
# Compare entities by calculating their average scores
def __lt__(self, other):
return abs(self.avg_score()) > abs(other.avg_score())
def __eq__(self, other):
return abs(self.avg_score()) == abs(other.avg_score())