Early Riser - Day 4

Up and at ‘em! Even though I am getting up early now, thankfully I haven’t developed that annoying “cheerful” morning disposition yet. It has been a quiet morning and I have had the chance to “play” a little after some prayer and devotion time.

So I have become interested in AI again in the past few days. A couple weeks ago, I read an article in Wired about the Grand Challenge - basically, a race across miles and miles of desert where the cars have no drivers. Well, no human drivers at least. The cars have some sort of AI that guides each of them.

Anyhow, there were several cars that actually finished the race in 2005, which is a big improvement over 2004 (no cars made it).

Over the past couple weeks, my mind has been simmering that article and thoughts about AI, so I thought I’d mess around with AI programming a bit in Python. WARNING TO THE CASUAL READER: I have no training with AI programming (or programming in general, for that matter) so what follows is simply my toying around with stuff.

First, I checked out what Python-related AI stuff is already out there. I ran across the Natural Language Toolkit (NLTK). So far I have just gotten into the documentation which has already left me quite impressed.

After reading up some on the NLTK, I decided to simply play around with some basic ideas in Python. I thought the following structure would be good to represent simple knowledge:

t = {'God':{True:['love', 'powerful'],
                    False:[]},
        'love':{True:['good'],
                    False:['envy', 'hate']},
     }

Philosophical/theological implications of my example notwithstanding, I think that it is a simple model of how words in the context of other words can be either True or False. So I set out to make a little function to play with this structure.

>>> def assert_that(stmt):
	if ' is not ' in stmt:
		a = False
		i,c = stmt.split(' is not ')
	elif ' is ' in stmt:
		a = True
		i, c = stmt.split(' is ')
	else:
		a,i,c = (None, None, None)
	if a not in (True, False):
		return "I don't know how to assert \"%s\"." % stmt
	else:
		truths = t.get(i, None)
		if truths is None:
			return "I don't know anything about \"%s\"." % i
		if c in truths.get(a, []) and c not in truths.get(not a, []):
			return '"%s" appears to be correct.' % stmt
		else:
			return '"%s" appears to be incorrect.' % stmt

Then, I played around with it for a bit:

>>> assert_that('Frank is fair')
'I don\'t know anything about "Frank".'
>>> assert_that('God is love')
'"God is love" appears to be correct.'
>>> assert_that('love is good')
'"love is good" appears to be correct.'
>>> assert_that('love is God')
'"love is God" appears to be incorrect.'
>>> assert_that('God is powerful')
'"God is powerful" appears to be correct.'
>>> assert_that('God is not hate')
'"God is not hate" appears to be incorrect.'
>>> t.get('God')[False].append('hate')
>>> assert_that('God is not hate')
'"God is not hate" appears to be correct.'
>>> assert_that("love is not hate")
'"love is not hate" appears to be correct.'

Like I said, pretty basic stuff, but it was entertaining/educational for me. I might make a function to easily add new truths or contradictions to a word. That would be better than inserting stuff right into the dictionary of truth. Heh, I like that - “dictionary of truth”.

I’ll try to get into the NLTK soon as what I am messing with now is nothing compared to what is available in there.

cw

Leave a Reply