Merlin, a fun little program
rdsteph at earthlink.net
Mon Jul 7 03:37:15 CEST 2003
I posted to my web site a fun little program called merlin.py today.
Please keep in mind that I am a hobbyist and this is just a little hack,
if you look at the code you will see that it is still possible to write
spaghetti code, even with Python. I apologize, and I do intend to clean
up the code, but it may take awhile. For now it works, with some bugs.
It is a composite of a few scripts. The first, based on a script Max M
uploaded to this newsgroup a while ago (2 years?), is a web scraper
based multiple choice guesser. I re-wrote the web scraper to use Yahoo
rather than Google, as Google somehow recognizes it as a script now and
so has disabled the ability to use Google, as they say it violates their
terms of service. I certainly do not want to violate anyone's terms of
service, this is a just a fun little script. I also used string
functions instead of regexes and an algorithm of my own. Kudos to David
Mertz' Text Processing in Python for helping me figure out how to do
this, indirectly. (BTW, I also posted a review of his new book on my web
site...and submitted it to Slashdot, but one never knows if they will
The stand alone version of the web scraper (askMerlin.py) uses NLQ, a
natural query language class found on the web at
http://gurno.com/adam/nlq/ to identify possible answers to a user's's
questions, to then be submitted to the main algorithm to choose amongst
the possible answers, which I call options. Of course, the program is
much more likely to be accurate when you give it a correct "option" to
be picked out from amongst several incorrect options that you also give
it; and in fact a bug in the composite program I call Merlin (
merlin.py) crashes completely if you do not give it any options; but
this can be fixed. askMerlin.py doesn't crash and uses NLQ, but gives
poor answers. However, I have a much better algorithm in mind for this
part of the program; instead of giving NLQ the main response page from a
query, I will give it the first "link" page from a query, which I
reckon to be much more likely to contain keywords that represent good
possible answers. Alas, this may have to wait until the next long
weekend, unless someone else takes up the task ;-)))
In the long run, the program is much more interesting using NLQ to find
answers to questions where the user offers no possible answers to choose
amongst or other clues; I think this has potential.
For now, please give Merlin options to choose amongst. Then, I include a
slightly improved Decision Analysis script, and two fun variations or
specific applications of it. This script has the virtue of being my own
creation, although I did recieve help from Paul Winkler and others on
Then I also include a script shamelessly stolen off the web that will be
instantly recognizable to most of you on this newsgroup, but perhaps not
to some newbies.
I have in mind more such fun stuff to be added.
Also, I intend to do a full GUI version, with a much better user
interface, and then to create executable installers for Windows, Linux,
and Mac OS X. For now though, the command line interface has the
advatage of working anywhere one can get a Python command prompt; I have
tested it on Windows, Linux, Mac OS X and the Sharp Zaurus PDA. The
additon of a GUI and creation of executable files should keep this
hobbyist busy for a while ;-)))
A GUI version of Decision Analysis, that I wrote using PythonCard, is
All of the above can wait until I add more fun stuff to it, make it
better, fix bugs, move it from the deprecated regex to the re module,
and clean up the code!
OK, so this hack may not be worth all the words I've given it, but, in
the spirit of computer programming for everybody, I am pleased that I am
producing something. I think it might be something other newbies might
be able to understand and hack on also, since it is so simple.
If not, so be it. I am having fun.
All of this is on my web site, right at the top, at
More information about the Python-list