I'm 14 (15 in less than an hour actually :D ) and I'm really struggling on this. I'm trying to create a very basic learning AI. At the moment I'm just trying to set up the framework of it, the part which helps it learn new words, so it's a bit messy and rough. Anyway, the idea is that when it doesn't understand a word, it asks what it is and then if the user supplied synonym is recognised, it will add it to that synonym's list of synonyms. Unfortunately, I keep hitting errors and problems and now I'm just confused. Please take a look at it for me. Oh and I apologise for its poor structure and poor just about everything else:
#standard dictionary
dictionary = {1:"hi",2:"yes",3:"no"}
wordvariations=[[],["yes,Yes"],["no,No"]]
#variables
breaker=0
response = "error"
success=0
#import
from random import choice
#word types
question_words= {"who","what","where","why","when","which","how","whom","Who","What","Where","Why","When","Which","How","Whom"}
#What does that mean?
def what_does_that_mean(new_word):
link_word = input("Sorry, I don't know what that means. Could you tell me? It means the same as the word...\n")
success=0
for current_dict in wordvariations:
if link_word in current_dict == TRUE:
print ("Thanks")
current_dict.append[new_word]
success=1
break
if success == 0:
tryagain = input("Sorry, I don't know what that means either. Would you like to try again? (y/n) \n")
if input == "y":
testword= input("Give me another word \n")
what_does_this_mean(testword)
else: return
#First start
possible_greeting =input("Hey. Nice to meet you.\n")
split_greeting = possible_greeting.split()
for each_word in split_greeting:
if each_word in question_words:
response = "Sorry, I can't answer questions yet"
breaker=1
break
elif (each_word == ("too")):
response = "Thanks"
breaker=1
break
else: pass
if breaker ==1:
pass
else:
yes_no = input("Is that how you usually greet people?\n")
if yes_no == "yes":
wordvariations[1].append(possible_greeting)
elif yes_no=="no":
new_greeting = input("Ok then. How do you often greet people?")
wordvariations[1].append(new_greeting)
else:
what_does_that_mean(yes_no)
#print (response)
#Other stuff
current_greeting = choice(wordvariations[1])
print (current_greeting)
If any indentation looks really off, I've probably put it in the question box wrong.
I'll really appreciate any help here - I feel like I'm going round in circles. At the moment, the search doesn't seem to be working as it never finds a result. It's the word finding function area that needs fixing most, the rest is just a sort of start-up script to get things going. Try and ignore the entirely useless bits that are just there for later.
Thanks in advance :)