Skip to content

Instantly share code, notes, and snippets.

@benawad
Created Oct 31, 2014
Embed
What would you like to do?
def convert_numbers(s):
try:
return int(s)
except ValueError:
return None
def scan(sentence):
words = sentence.split()
sentence = []
for word in words:
word_tuple = ('error', word)
num = convert_numbers(word)
if (num != None):
word_tuple = ('number', num)
lc_word = word.lower()
if (lc_word == 'north' or lc_word == 'south' or lc_word == 'east' or lc_word == 'west' or lc_word == 'down' or lc_word == 'up' or lc_word == 'left' or lc_word == 'right' or lc_word == 'right'):
word_tuple = ('direction', word)
if (lc_word == 'go' or lc_word == 'stop' or lc_word == 'kill' or lc_word == 'eat'):
word_tuple = ('verb', word)
if (lc_word == 'the' or lc_word == 'in' or lc_word == 'of' or lc_word == 'from' or lc_word == 'at' or lc_word == 'it'):
word_tuple = ('stop', word)
if (lc_word == 'door' or lc_word == 'bear' or lc_word == 'princess' or lc_word == 'cabinet'):
word_tuple = ('noun', word)
sentence.append(word_tuple)
return sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment