-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActorDictionary.py
45 lines (28 loc) · 1.1 KB
/
ActorDictionary.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
37
38
39
40
41
import re
from ClusterSImilarity import FuzzyClusterSimilarity
from petrarch2 import PETRglobals
class ActorDictionary:
actor_filenames= ["Phoenix.Countries.actors.txt", "Phoenix.International.actors.txt",
"Phoenix.MilNonState.actors.txt"
]
folder = 'data/dictionaries'
actor_set = set()
actor_roles = {}
fcs = FuzzyClusterSimilarity()
THERSHOLD = 0.75
def __init__(self):
for filename in self.actor_filenames:
fs = open(self.folder + "/" + filename)
for line in fs:
line = line.strip()
if line.startswith('#') or len(line) == 0: # if it is a comment
continue
line = line.split('#')[0]
line = re.sub(r'\[[^\]]*\]', '', line).replace('_', ' ').replace('+', '').strip()
#print line
if len(line) > 1:
self.actor_set.add(line)
fs.close()
def contains(self, actorname):
test = actorname.replace('_',' ').strip()
return test in self.actor_set