-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.py
55 lines (44 loc) · 1.59 KB
/
player.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from text_to_speech import *
from speech_recog import *
from nltk.stem.snowball import SnowballStemmer
stemmer = SnowballStemmer('english')
yes_syns = [['yes', 'yup', 'yeah', 'yea', 'indeed', 'sure']]
class Player:
def __init__(self, list_of_StoryNodes):
#requires that first StorNode in list is start node
self.location = list_of_StoryNodes[0]
self.completed = {}
self.name = self.setName()
#put all nodes in story in dictionary as not completed
for node in list_of_StoryNodes:
self.completed[node.name] = False
def get_target(self, s, targets, targets_syn): #this method looks for a one word target in user's speech
#check if user says exactly the node's name
temp = []
for i in targets_syn:
temp2 = []
for j in i:
temp2.append(stemmer.stem(j))
temp.append(temp2)
targets_syn = temp
for t in targets:
if s.lower() == t.lower():
return t
s = s.lower().split()
temp = []
for i in s:
temp.append(stemmer.stem(i))
s = temp
for word in s:
for t in targets_syn:
if word in t:
return targets[targets_syn.index(t)]
return None
def setName(self):
yes = 'no'
while self.get_target(yes, ['yes'], yes_syns) != 'yes':
speak("What is your name?")
s = getInputString()
speak("Is your name " + s + "?")
yes = getInputString()
return s