Artificial Intelligence in Python

Python has many of the features of LISP, a language very popular among artificial intelligence (AI) researchers. It is well suited to the sort of symbolic processing used in AI.

I'm no expert in AI, but I've tinkered a bit. As I develop more AI programs in Python, I'll post them here. If you have something or know of something along these lines, please let me know and I'll include it here as well.


Therapist

therapist.py is a little Python program inspired by ELIZA, a famous natural-language AI demo from the 1960s. It's all smoke and mirrors; the program hasn't the foggiest idea what it is saying, and you'll find that tripping it up is fairly easy. But it's at least amusing, and may occasionally be theraputic.


Python2C

python2c.py is close relative of therapist -- a little smaller, more serious, and just as cheezy. This program attempts to convert Python code into the equivalent C++ code, as in this example. It's very limited in this skill, but it does demonstrate the concept of a Python compiler. This program was updated by Dirk Heise in January 1998, and now does significantly more transformation -- it could now be considered actually useful in some cases!

For another attempt at a Python to C converter, see: Issues in Building Ariel -- OpenGL and Python to C.


Semantic Networks

The semnet.py module defines several simple classes for building and using semantic networks. A semantic network is a way of representing knowledge, and it enables the program to do simple reasoning with very little effort on the part of the programmer.

The following classes are defined:

With these three object types, you can very quickly define knowledge about a set of objects, and query them for logical conclusions. For example, if you declare that a fish is an animal, and animals are made of cells, it will automatically know that fish are made of cells. If you further assert that cells are made of molecules, it will know that fish are made of molecules.

In addition to semnet.py (which does nothing interesting on its own), I've prepared two demo programs. demo1.py shows how to build and query a semantic net directly from Python code; have a look to see how easy it is! demo2.py shows how to do the same thing, but with an interactive user interface (you'll also need tostr.py for this).


Expert-System Inference Shell

Mark Lutz has developed an expert-system shell. It is available on the Python archives:

http://www.python.org/ftp/python/contrib/All/holmes.tar.gz
Thanks, Mark!


http://www.strout.net/python/ai/index.html
Last Updated: 1/16/98 . . . . . . Joe Strout