-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexicon2.py
35 lines (25 loc) · 938 Bytes
/
lexicon2.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
class lexicon:
D = {'direction': ['north', 'south', 'east','west', 'down', 'up', 'left', 'right', 'back'],
'verbs': ['go', 'stop', 'kill', 'eat'],
'stop': ['the', 'in', 'of', 'from', 'at', 'it'],
'nouns': ['door', 'bear', 'princess', 'cabinet']
}
def convert_numbers(self, word):
try:
return int(word)
except ValueError:
return None
def scan(self, sentence):
words = sentence.split(" ")
res = []
for word in words:
if self.convert_numbers(word) != None:
res.append(('numbers', self.convert_numbers(word)))
else:
type = 'error'
for t in lexicon.D:
if word in lexicon.D[t]:
type = t
break
res.append((type, word)) # error for res=res.append()
return res