{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Workbook for Chapter 10 of Explorations in Computing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Important Note About ELIZA and IPython " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The tutorial exercises in the textbook assume readers are running ELIZA in a terminal window. It's easy to run ELIZA from an IPython Notebook as long as you ** make sure ELIZA is active in only one code cell at a time.**\n", "\n", "When you type a Python command that starts ELIZA the code cell will look something like this:\n", "

\n", "\n", "

\n", "\n", "Notice how there is a \"text entry box\" below the code cell. The \"H\" prompt to the left of the box is the indication that ELIZA is waiting for you to type an input. Click in this box, type a sentence, and hit the return key. ELIZA will process your sentence, print a reply, and display a new text bos for your next input.\n", "\n", "A very important detail in this screen shot is the asterisk between the square brackets to the left of the code cell. This means Python is still working on the expression typed in the code cell. This makes sense -- ELIZA is currently running.\n", "\n", "** Before you move on to another exercise you need to exit the session with ELIZA **\n", "\n", "Type `quit` in the text entry box and the ELIZA session will end. The asterisk will change to a number and IPython will be ready to execute code in another code cell.\n", "\n", "IPython will let you type in any cell in the notebook at any time. But if the Python kernel is busy with an ELIZA session it can't process other code cells. So if IPython seems to be ignoring you, check other code cells to make sure there isn't an asterisk that shows the kernel is busy. If you find one, and it's an interactive session with ELIZA, just type `quit`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Section 10.1: Overview of ELIZA" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Execute this cell to initialize the notebook:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from PythonLabs.ElizaLab import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Exercises " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T2. Call the method named `Eliza.run` to start a conversation. When Eliza is waiting for you to type a sentence you will see a text entry box below the code cell. Type your sentence in this box and hit return to see the output from Eliza. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T3. Because Eliza does not have a script yet, it can only apply a default rule that does not change the input. Type a few sentences in the entry form above. Everything you type will simply be echoed right back." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T4. Unlike an annoying sibling, Eliza will quit when you tell it to. Type the single word `bye`, or `quit`, or hit D (hold down the control key while typing D) to end a conversation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** Make sure you type `quit` in the text entry box above before you move on to the remaining exercises. **" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T5. Call the Eliza module's `load` method to read the \"doctor\" script that is included as part of the PythonLabs distribution:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T6. Execute `Eliza.run()` in the code cell below. Now the rules defined in doctor will be used to transform every sentence you type into a response." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T7. Try entering a few more sentences. If you see a strange or grammatically incorrect response can you figure out how Eliza transformed your input?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** Type `quit` in the text entry box above before moving on to the next exercises. **" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T8. To see a complete list of key words in the current script call `Eliza.info`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T9. Start a new conversation by typing `Eliza.run` again, and make up some input sentences on your own. You can type anything you would like, but you are more likely to keep up the illusion of chatting with a psychologist if your statements include key words from the list printed by the `info` method." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.2" } }, "nbformat": 4, "nbformat_minor": 0 }