-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentity_values.py
More file actions
34 lines (26 loc) · 966 Bytes
/
entity_values.py
File metadata and controls
34 lines (26 loc) · 966 Bytes
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
import os
import csv
#A class to keep track of the replaced entity values for use in subsequent anonymization including restoring text where required.
class EntityValues():
def __init__(self):
self._entity_values={}
def get_value(self,id):
return self._entity_values.get(id,None)
def set_value(self,id,value):
if id not in self._entity_values:
self._entity_values[id] = value
return value
def set_label_value(self,label,ix,value):
newLabel = label+ "-"+str(ix)
self.set_value(newLabel,value)
return newLabel
def write_csv(self, filepath):
a_file = open(filepath, "w")
writer = csv.writer(a_file)
for key, value in self._entity_values.items():
writer.writerow([key, value])
a_file.close()
def get_entity_values(self):
return self._entity_values
def is_empty(self):
return self._entity_values=={}