Dekudude 0 Light Poster

Hi there!

I have been working on an AI program for a while now, and in creating knowledge bases (what does x mean, etc) this small snippet of code has done very well. (just repaste and change variable names / file name) However, I am attempting to modify it to store names (first, last, AND description, not just first / description) and I am stuck.

nameList = [item for item in [line.strip() for line in open('names.txt')] if item]
names = {}
while nameList:
	nameKey = nameList.pop(0)
	names[nameKey] = nameList.pop(0)

success = False
object = None

for ask in askWhatIs: #I shouldn't need this...
	if re.search(ask, input): #Or this.. It's from other uses of the code.
		for name in names:
			if re.search(names, input):
				success = True
				who = name
if success:
	say = names[name]
	print say
	print
	speech.say(say)
	last = "answer"
Albert Einstein
Einstein is the scientist who found that E = MC^2

Elvis Presley
A famous singer from a couple decades back, composer of "Hound Dog", "A Little Less Conversation", and others.

From this, you can see that if I have the name "Albert Einstein" in my file with "Einstein is the scientist who found that E = MC^2" being returned. Now... What I want to do is if only first or last name is given, my program asks if I mean "First Name + Last Name." If so, give the description. If not, return something else. Therefore, I need to read the text file, split at the space (into first and last names) and then check the string, and see if either first or last name is entered.

Am I making sense? What I'm thinking is turning the name into a list and then returning the first or second value of the array, depending on what was inputted. (if Albert, then say Einstein, etc)

What are your guys' thoughts? I've tried making the changes myself, but to no avail... thanks for your time!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.