AI used to be one of my favorite subjects right from college days. I was searching for some AI algorithms and happened to find a 'chat-bot' called Eliza in between. 'She' was good enough, even though she doesn't perfectly simulate a human user, she does a pretty good job. The next moment i wanted to use Eliza to talk to my friends on behalf of me through my Instant messenger.
Since i already had some ruby programs which could talk to IM servers, an interface to Eliza was just what i needed. I visted the Eliza's webpage, one of the simplest webpages ever. It just had a plain html form, with a textfield and a submit button. The page source said that textfield's name was "Entry1". That was all i needed !
Here's my Ruby interface for Eliza :
def eliza(str)
response = Net::HTTP.postform(URI.parse("http://www-ai.ijs.si/eliza-cgi-bin/elizascript"),{'Entry1'=>str})
return response.body.split("</strong>\n").last.split("\n").first
end
Hats off to Ruby...!
Now whenever a chat message arrives on my IM program, i simply call this 'eliza' method, get a response string from Eliza, and send it as reply in the IM program.
Here's the full Ruby code for the Eliza chat program.