It is very simple. ie.
question = 'What is Python'
choices = (
'a programming language',
'a tv series',
'a snake'
)
It then queries google with:
"What is Python a programming language"
"What is Python a tv series"
"What is Python a snake"
and chooses the result that gets the most hits.
Simple, but far better then random.
Well it's not of much use, but kind of fun and very low budget AI ...
regards Max M
#######################################
from urllib import urlopen, urlencode
import re
class multiChoiceGuesser:
def __init__(self, question='', replys=()):
self.question = question
self.replys = replys
def guessedAnswer(self):
hits = []
for reply in self.replys:
hits.append(self._getGoogleHits(self.question + ' ' + reply))
return hits.index(max(hits))
def _getGoogleHits(self, query):
query = urlencode({'q':query})
urlHandle = urlopen('http://www.google.com/search?%s' % query)
googlePage = urlHandle.read()
try:
numberAsString = re.search(
'of about <b>(.*?)</b>.', googlePage, re.S
).group(1)
hits = re.sub(',', '',numberAsString)
urlHandle.close()
hits = int(hits)
except:
hits = 0
return hits
def guess(question, choices):
mcg = multiChoiceGuesser(question, choices)
print 'The question is: ', question
print 'The most likely answer is: ', choices[mcg.guessedAnswer()]
print ''
if __name__ == '__main__':
"""
The test suite.
"""
question = 'In which part of the world is Denmark located'
choices = ('Europe',
'America',
'Asia',
'usa'
)
guess(question, choices)
question = 'Who created Linux'
choices = ('Linus Torvalds',
'RMS',
'Steve Jobs',
'Bill Gates'
)
guess(question, choices)
question = 'What is Python'
choices = ('a programming language',
'a tv series',
'a snake'
)
guess(question, choices)
question = 'Who is norman bates'
choices = ('a character in Psycho',
'A hotel owner',
'the main character in american psycho'
)
guess(question, choices)
question = 'What is Madonna\'s full name?'
choices = ('Madonna Lewis Ciccone',
'Madonna lillith Ciccone',
'Madonna Louise Ciccone'
)
guess(question, choices)
#######################################
The question is: In which part of the world is Denmark located
The most likely answer is: Europe
The question is: Who created Linux
The most likely answer is: Linus Torvalds
The question is: What is Python
The most likely answer is: a programming language
The question is: Who is norman bates
The most likely answer is: a character in Psycho
The question is: What is Madonna's full name?
The most likely answer is: Madonna Louise Ciccone
> I have written this little Python program that usually raises a few
> eyebrows. It answer multiple choice questions.
Sounds like something for (tada sound) "Useless Python":
http://www.lowerstandard.com/python
Kudos, Dietmar
--
I haven't lost my mind -- it's backed up on tape somewhere.
Cool! I can think of at least one "useful"
application: automating cheating for
Who Wants to be a Millionaire. As it is,
when people phone their friend, you
can sometimes hear some frenzied typing
over the line ...
Manoj
Microsoft showed a similar program at the IJCAI that
would answer questions. It answered some questions
like "What is A.I." and "Who made the movie A.I.", but
when asked "Who is Bill Gates married to" it's reply
was "I'm not sure, either Malinda French or Microsoft"
Another program shown at an AI conference was a
document classifier. To determine which folder to add
the document to, it simply compare the size of the
tarred folders before and after adding the document.
Of all the AI programs used for document sorting it
came closest to a human sorter.
Thanks,
Jeff Sandys
I don't get that last part. How does comparing the size of the
folders before and after do anything useful? Wouldn't all of the
folders increase by the size of the file?
Tom
Tom Good:
>I don't get that last part. How does comparing the size of the
>folders before and after do anything useful? Wouldn't all of the
>folders increase by the size of the file?
I'm assuming they were also compressed. Depending on the
compression scheme, if there is a lot of text (words, phrases)
that are shared between the documents then closely related
text should compress better then more distantly related text.
But that makes a lot of assumptions on the compression, like
that it doesn't reset itself after a given amount of data.
Andrew
da...@dalkescientific.com
>Jeff Sandys <san...@juno.com> wrote in message news:<3BBCBA9F...@juno.com>...
>> Another program shown at an AI conference was a
>> document classifier. To determine which folder to add
>> the document to, it simply compare the size of the
>> tarred folders before and after adding the document.
>I don't get that last part. How does comparing the size of the
>folders before and after do anything useful? Wouldn't all of the
>folders increase by the size of the file?
As a guess, I think he may have meant that it adds the file to all the
folders, and then compresses the folders. The folder that shows the
smallest increase in size (after compression) is the 'correct' folder.
The idea being that the compressor will exploit redundancy, and that
redundancy correlates highly with being in the 'correct' folder.
Obviously, this is speculation. Hopefully Jeff will clarify what he
meant.
--
Chad Netzer
chad....@stanfordalumni.org