File - Mr. Smith`s Classes

Download Report

Transcript File - Mr. Smith`s Classes

AP Magpie
Chatbox
"If a computer could think, how could we tell?"
Alan Turing's suggestion was, that “if the
responses from the computer were
indistinguishable from that of a human,
the computer could be said to be thinking. “
This field is generally known as natural language
processing.
Getting Started ( 5 minutes)
• From the class website open and read over
the document.
• magpie_lab_student_guide_updated_sept_2014.pdf
Learning Objectives
• Students will be able to create a Chatbot that
employs artificial intelligence.
A couple of useful String Methods
• int x = stringVar.indexOf(“Hello”);
– Finds the index of the first occurrence of “Hello”
in the String stringVar.
– Returns -1 if no “Hello”
• String chop = stringVar.trim();
– Returns a copy of the string stored in stringVar
with leading and trailing spaces deleted.
Example: Dry Run
Note: 3 Spaces
before ‘Hello’
The Loebner Prize in Artificial Intelligence
• Dr. Loebner pledged a Grand Prize of $100,000
and a Gold Medal (pictured above) for the first
computer whose responses were
indistinguishable from a human's.
Activity 1: Hands On (10 – 15 minutes)
• Experiment with the different Chatbots. Look for how they
respond and how you might incorporated this into your Chat
bot
• • How does it respond to “where do you come from”?
• • What is the most interesting response?
• • What is the most peculiar response?
• • How does it respond to “asdfghjkl;”?
• Can you identify keywords to which your chatbot responds?
(Record on your worksheet)
• Think of several keywords and the responses they might
cause. (Record on your worksheet)
• Work with another group and have two different chatbots
converse with each other.
• http://sites.google.com/site/webtoolsbox/bots
Chatbots
• http://sites.google.com/site/webtoolsbox/bots
Breaking Down a Chatbot
• Create a folder in your APJava folder called
Magpie Project
• Go to the Assignments\MagpieProject folder
and copy ‘activity2’ folder into your Magpie
Project folder.
• Additional parts of this project will be added
to the folder as you continue with the project.
Open Magpie2 and
MagpieRunner2
• Read over the code
Magpie2
• Constructor
• Methods
– What is sent to them?
– What is returned?
• MagpieRunner2
– What does it do to start?
– What do you have to enter to quit?
Activity 2:
Modify the Chatbot
Turn it in as
YourNamesChatbot2
• Have it respond “Tell me more about your pets” when the statement contains the word “dog”
or “cat.” For example, a possible statement and response would be:
Statement: I like my cat Mittens.
Response: Tell me more about your pets.
• Have it respond favorably when it sees the name of your teacher. Be sure to use appropriate
pronouns! For example, a possible statement and response would be:
Statement: Mr. Finkelstein is telling us about robotics.
Response: He sounds like a good teacher.
• Have the code check that the statement has at least one character. You can do this by using the
trim method to remove spaces from the beginning and end, and then checking the length of the
trimmed string. If there are no characters, the response should tell the user to enter something.
For example, a possible statement and response would be:
Statement:
Response: Say something, please.
• Add two more noncommittal responses to the possible random responses.
• Pick three more keywords, such as “no” and “brother” and edit the getResponse method to
respond to each of these. Enter the three keywords and responses below.