-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActorDictionaryCopy.py
More file actions
executable file
·32 lines (26 loc) · 1.04 KB
/
Copy pathActorDictionaryCopy.py
File metadata and controls
executable file
·32 lines (26 loc) · 1.04 KB
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
#regular expression
import re
class ActorDictionary:
actor_filenames= ['Phoenix.Countries.actors.txt',
'Phoenix.International.actors.txt',
'Phoenix.MilNonState.actors.txt']
folder = 'data/dictionaries'
actor_set = set()
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
for word in line.split(' '):
if len(word) > 1:
self.actor_set.add(word)
fs.close()
def contains(self, actorname):
test = actorname.replace('_',' ').strip()
print("TESTTTTTTTTTTTTTT",test)
return test in self.actor_set