-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex48.py
More file actions
35 lines (32 loc) · 771 Bytes
/
ex48.py
File metadata and controls
35 lines (32 loc) · 771 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
35
class lexicon(object):
Direction_Words=["north","south","east","west","down","up","left","right","back"]
Verb_Words=["go","stop","kill","eat"]
Stop_Words=["the","in","of","from","at","it"]
Noun_Words=["door","bear","princess","cabinet"]
def convert_number(s):
try:
return int(s)
except ValueError:
return None
def convert_object(s):
if s in Direction_Words:
return ('direction', s)
elif s in Verb_Words:
return ('verb', s)
elif s in Stop_Words:
return ('stop', s)
elif s in Noun_Words:
return ('noun', s)
else:
return None
def scan(s):
out = []
words = s.split(s)
for word in words:
obj = convert_object(word)
if obj:
out.append(obj)
obj = convert_number(word)
if obj:
out.append(obj)
return out