Skip to content

Instantly share code, notes, and snippets.

@Baerito
Created March 29, 2016 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Baerito/8525e9a42e57560859b2 to your computer and use it in GitHub Desktop.
Save Baerito/8525e9a42e57560859b2 to your computer and use it in GitHub Desktop.
def analyzeSentence(sentence, main_data):
"""Takes in a sentence, analyze it, and saves the important"""
"""data into the main data structure"""
sentence = sentence.lower()
if sentence == 'fuck you':
print('I love you too')
elif sentence == 'what is your name':
if main_data['botname'] != 'p':
print('My name is', main_data['botname'])
else:
main_data['botname'] = input('What is my name: ')
return main_data
def sentence(sentence, qword, v, do):
split_sentence = sentence.split()
for word in split_sentence:
if not word in qword and not word in v and not word in do:
print("I don't know what", word, "means")
definition = input('Enter definition: ')
part = input('Part of Speech(v, do, q_word): ')
if part == 'q_word':
q_word[word] = definition
elif part == 'v':
v[word] = definition
elif part == 'do':
do[word] = definition
return qword, v, do
#--- main
main_data = {'botname': 'p'}
terminate = False
q_word = dict()
v = dict()
DO = dict()
while not terminate:
user_input = input('Say something: ')
main_data = analyzeSentence(user_input, main_data)
q_word, v, DO = sentence(user_input, q_word, v, DO)
if user_input == '\see':
print(q_word)
print(v)
print(DO)
if user_input == '\end':
terminate = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment