Difference between revisions of "Turing Test and Eliza"
(Created page with "--~~~~ ---- =Introduction to the Turing Test= <br /> <center><videoflash>qrTqmWbYD3Q</videoflash></center> <br />") |
|||
Line 5: | Line 5: | ||
<center><videoflash>qrTqmWbYD3Q</videoflash></center> | <center><videoflash>qrTqmWbYD3Q</videoflash></center> | ||
<br /> | <br /> | ||
+ | =Eliza Program= | ||
+ | <br /> | ||
+ | ==Version 1: Let's start with something very basic== | ||
+ | <br /> | ||
+ | <source lang="python"> | ||
+ | # Eliza1.py | ||
+ | # D. Thiebaut | ||
+ | # A very short beginning program for Eliza | ||
+ | |||
+ | |||
+ | |||
+ | # -------------------------------------------------------------------------- | ||
+ | # just print the string to the console | ||
+ | # will be transformed to something better later... | ||
+ | def myprint( string ): | ||
+ | print( string ) | ||
+ | |||
+ | # sayGoodBye | ||
+ | # say goodbye to the user. | ||
+ | def sayGoodBye( name ): | ||
+ | myprint( "Good bye " + name ) | ||
+ | |||
+ | # isGoodBye | ||
+ | # checks to see if what the user said is one of the keywords for | ||
+ | # ending the conversation. | ||
+ | def isGoodBye( userAnswer ): | ||
+ | if userAnswer.lower().strip() in [ "bye", "goodbye", "ciao" ]: | ||
+ | return True | ||
+ | else: | ||
+ | return False | ||
+ | |||
+ | def greetings(): | ||
+ | myprint( "Hello there!" ) | ||
+ | myprint( "What is your name?" ) | ||
+ | name = input( "> " ) | ||
+ | myprint( "Welcome " + name ) | ||
+ | return name | ||
+ | |||
+ | # -------------------------------------------------------------------------- | ||
+ | # main function | ||
+ | # -------------------------------------------------------------------------- | ||
+ | def main(): | ||
+ | |||
+ | # greet user and get her name | ||
+ | userName = greetings() | ||
+ | |||
+ | # conversation: get user input, and respond | ||
+ | for i in range( 1000 ): | ||
+ | |||
+ | # get user's statement | ||
+ | userAnswer = input( "> " ) | ||
+ | |||
+ | # if it is a goodbye statement, exit the loop | ||
+ | if isGoodBye( userAnswer ) == True: | ||
+ | break | ||
+ | |||
+ | # tell the user to continue speaking | ||
+ | myprint( "Please tell me more..." ) | ||
+ | |||
+ | |||
+ | # if we're here, it's because the loop stopped. | ||
+ | # say goodbye to the user | ||
+ | sayGoodBye( userName ) | ||
+ | |||
+ | |||
+ | main() | ||
+ | |||
+ | |||
+ | |||
+ | </source> | ||
+ | <br /> | ||
+ | ==Version 2: Let's randomize the program's prompts== | ||
+ | <br /> | ||
+ | <source lang="python" highlight="5,39,40,41,57"> | ||
+ | # Eliza2.py | ||
+ | # D. Thiebaut | ||
+ | # A very short beginning program for Eliza | ||
+ | # with random prompts from the program. | ||
+ | import random | ||
+ | |||
+ | |||
+ | # -------------------------------------------------------------------------- | ||
+ | # just print the string to the console | ||
+ | # will be transformed to something better later... | ||
+ | def myprint( string ): | ||
+ | print( string ) | ||
+ | |||
+ | # sayGoodBye | ||
+ | # say goodbye to the user. | ||
+ | def sayGoodBye( name ): | ||
+ | myprint( "Good bye " + name ) | ||
+ | |||
+ | # isGoodBye | ||
+ | # checks to see if what the user said is one of the keywords for | ||
+ | # ending the conversation. | ||
+ | def isGoodBye( userAnswer ): | ||
+ | if userAnswer.lower().strip() in [ "bye", "goodbye", "ciao" ]: | ||
+ | return True | ||
+ | else: | ||
+ | return False | ||
+ | |||
+ | def greetings(): | ||
+ | myprint( "Hello there!" ) | ||
+ | myprint( "What is your name?" ) | ||
+ | name = input( "> " ) | ||
+ | myprint( "Welcome " + name ) | ||
+ | return name | ||
+ | |||
+ | # -------------------------------------------------------------------------- | ||
+ | # main function | ||
+ | # -------------------------------------------------------------------------- | ||
+ | def main(): | ||
+ | prompts = ["Please go on...", "Please tell me more...", | ||
+ | "Interesting... Go on, please!", "Yes? Really? Go on", | ||
+ | "Weird... I'm not sure what to think of that..." ] | ||
+ | |||
+ | # greet user and get her name | ||
+ | userName = greetings() | ||
+ | |||
+ | # conversation: get user input, and respond | ||
+ | for i in range( 1000 ): | ||
+ | |||
+ | # get user's statement | ||
+ | userAnswer = input( "> " ) | ||
+ | |||
+ | # if it is a goodbye statement, exit the loop | ||
+ | if isGoodBye( userAnswer ) == True: | ||
+ | break | ||
+ | |||
+ | # tell the user to continue speaking | ||
+ | myprint( random.choice( prompts ) ) | ||
+ | |||
+ | # if we're here, it's because the loop stopped. | ||
+ | # say goodbye to the user | ||
+ | sayGoodBye( userName ) | ||
+ | |||
+ | main() | ||
+ | |||
+ | </source> |
Revision as of 13:56, 5 March 2015
--D. Thiebaut (talk) 21:23, 4 March 2015 (EST)
Contents
Introduction to the Turing Test
Eliza Program
Version 1: Let's start with something very basic
# Eliza1.py
# D. Thiebaut
# A very short beginning program for Eliza
# --------------------------------------------------------------------------
# just print the string to the console
# will be transformed to something better later...
def myprint( string ):
print( string )
# sayGoodBye
# say goodbye to the user.
def sayGoodBye( name ):
myprint( "Good bye " + name )
# isGoodBye
# checks to see if what the user said is one of the keywords for
# ending the conversation.
def isGoodBye( userAnswer ):
if userAnswer.lower().strip() in [ "bye", "goodbye", "ciao" ]:
return True
else:
return False
def greetings():
myprint( "Hello there!" )
myprint( "What is your name?" )
name = input( "> " )
myprint( "Welcome " + name )
return name
# --------------------------------------------------------------------------
# main function
# --------------------------------------------------------------------------
def main():
# greet user and get her name
userName = greetings()
# conversation: get user input, and respond
for i in range( 1000 ):
# get user's statement
userAnswer = input( "> " )
# if it is a goodbye statement, exit the loop
if isGoodBye( userAnswer ) == True:
break
# tell the user to continue speaking
myprint( "Please tell me more..." )
# if we're here, it's because the loop stopped.
# say goodbye to the user
sayGoodBye( userName )
main()
Version 2: Let's randomize the program's prompts
# Eliza2.py
# D. Thiebaut
# A very short beginning program for Eliza
# with random prompts from the program.
import random
# --------------------------------------------------------------------------
# just print the string to the console
# will be transformed to something better later...
def myprint( string ):
print( string )
# sayGoodBye
# say goodbye to the user.
def sayGoodBye( name ):
myprint( "Good bye " + name )
# isGoodBye
# checks to see if what the user said is one of the keywords for
# ending the conversation.
def isGoodBye( userAnswer ):
if userAnswer.lower().strip() in [ "bye", "goodbye", "ciao" ]:
return True
else:
return False
def greetings():
myprint( "Hello there!" )
myprint( "What is your name?" )
name = input( "> " )
myprint( "Welcome " + name )
return name
# --------------------------------------------------------------------------
# main function
# --------------------------------------------------------------------------
def main():
prompts = ["Please go on...", "Please tell me more...",
"Interesting... Go on, please!", "Yes? Really? Go on",
"Weird... I'm not sure what to think of that..." ]
# greet user and get her name
userName = greetings()
# conversation: get user input, and respond
for i in range( 1000 ):
# get user's statement
userAnswer = input( "> " )
# if it is a goodbye statement, exit the loop
if isGoodBye( userAnswer ) == True:
break
# tell the user to continue speaking
myprint( random.choice( prompts ) )
# if we're here, it's because the loop stopped.
# say goodbye to the user
sayGoodBye( userName )
main()