Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.opencyc.conversation
Class Interpreter

    java.lang.Object
      |
      +--org.opencyc.conversation.Interpreter

public class Interpreter
extends java.lang.Object

Contains the attributes and behavior of a chat fsm interpreter.

The chat conversation is in the form of a text conversation using asynchronous receiving and sending of messages. This interpreter models the chat interaction with nested fsms in a stack. Mixed initiative is supported by a dictionary of fsm stacks, one of which is active, and the rest suspended. Sub fsms are passed a list of attribute/value pairs which form the initial state attributes. When done, sub fsms pass back result attribute/value pairs to the calling fsm's state attributes.

Author:
  Stephen L. Reed

  Copyright 2001 Cycorp, Inc., license is open source GNU LGPL.

  the license

  www.opencyc.org

  OpenCyc at SourceForge

  THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENCYC ORGANIZATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND KNOWLEDGE BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Field Summary
`protected ChatterBot` | `chatterBot` reference to the parent ChatterBot
`protected ChatUserModel` | `chatUserModel` Reference to the user model, which contains user state and history information, persisted in the Cyc KB.
`protected State` | `currentState` finite state machine current node
`protected Fsm` | `fsm` reference to the active fsm
`protected StackWithPointer` | `fsmStack` Reference to the current fsm stack, which is a stack of FsmInfo elements.
`protected java.util.HashMap` | `fsmStacks` dictionary of fsm stacks fsmStackId --> fsm stack
`protected Performative` | `nextPerformative` Next computed Performative, or null if none.
`protected Performer` | `performer` Performs fsm actions.
`protected java.util.HashMap` | `stateAttributes` Dictionary of state attribute and object values.
`protected TemplateFactory` | `templateFactory` Makes Template objects for the TemplateParser.
`protected TemplateParser` | `templateParser` Parses the users input text.

Constructor Summary
`protected` | `Interpreter()` Constructs a new Interpreter without arguments.
`` | `Interpreter(ChatterBot chatterBot, java.lang.String chatUserNickname, java.lang.String chatUserUniqueId, java.lang.String fsmStackId, Fsm fsm)` Constructs a new Interpreter object given the parent ChatterBot.

Method Summary
`java.lang.Object` | `getStateAttribute(java.lang.Object attribute)` Returns the value for the given state attribute.
`void` | `initialize(java.lang.String fsmStackId, Fsm fsm)` Initializes the fsm interpreter.
`protected Arc` | `lookupArc(Performative performative)` Returns the arc which corresponds to the performative received in the current state.
`void` | `popFsmStateInfo()` Pops the fsm state stack and restores the previous fsm state.
`void` | `pushFsmStateInfo(FsmStateInfo fsmStateInfo)` Pushes the given fsm state onto the current fsm stack.
`void` | `receiveChatMessage(java.lang.String chatMessage)` Receives the given chat message from the given chat partner, obtains the performative, transitions to the corresponding state and performs the required action.
`void` | `sendChatMessage(java.lang.String chatMessage)` Sends the given chat message into the chat system.
`void` | `setNextPerformative(Performative nextPerformative)` Sets the value of the computed next performative.
`void` | `setStateAttribute(java.lang.String attribute, java.lang.Object value)` Sets the value for the given state attribute.
`void` | `setupSubFsm(Fsm fsm, java.util.ArrayList arguments)` Sets up the given sub fsm and the input arguments as a list of attribute/value pairs.
`protected void` | `transitionState(Arc arc)` Transitions to the to-state given in the arc, and performs the action.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### chatterBot

    protected ChatterBot chatterBot

  reference to the parent ChatterBot

### chatUserModel

    protected ChatUserModel chatUserModel

  Reference to the user model, which contains user state and history information, persisted in the Cyc KB.

### fsmStacks

    protected java.util.HashMap fsmStacks

  dictionary of fsm stacks fsmStackId --> fsm stack

### fsmStack

    protected StackWithPointer fsmStack

  Reference to the current fsm stack, which is a stack of FsmInfo elements. Each of these elements contains the fsm and its state attributes.

### fsm

    protected Fsm fsm

  reference to the active fsm

### currentState

    protected State currentState

  finite state machine current node

### stateAttributes

    protected java.util.HashMap stateAttributes

  Dictionary of state attribute and object values.

### nextPerformative

    protected Performative nextPerformative

  Next computed Performative, or null if none.

### templateFactory

    protected TemplateFactory templateFactory

  Makes Template objects for the TemplateParser.

### templateParser

    protected TemplateParser templateParser

  Parses the users input text.

### performer

    protected Performer performer

  Performs fsm actions.

Constructor Detail

### Interpreter

    protected Interpreter()

  Constructs a new Interpreter without arguments. Used for unit testing.

### Interpreter

    public Interpreter(ChatterBot chatterBot,
                       java.lang.String chatUserNickname,
                       java.lang.String chatUserUniqueId,
                       java.lang.String fsmStackId,
                       Fsm fsm)

  Constructs a new Interpreter object given the parent ChatterBot.
  Parameters:
    `chatterBot` - the parent ChatterBot
    `chatUserNickname` - the preferred name (possibly not unique) of the chat partner
    `chatUserUniqueId` - the unique id assigned to the user by the chat system

Method Detail

### receiveChatMessage

    public void receiveChatMessage(java.lang.String chatMessage)
                            throws CycApiException,
                                   java.io.IOException,
                                   java.net.UnknownHostException,
                                   ChatException

  Receives the given chat message from the given chat partner, obtains the performative, transitions to the corresponding state and performs the required action.
  Parameters:
    `chatPartner` - the name of the chat partner
    `chatMessage` - the chat message

### lookupArc

    protected Arc lookupArc(Performative performative)

  Returns the arc which corresponds to the performative received in the current state.
  Parameters:
    `performative` - the performative
  Returns:
    the arc which corresponds to the performative received in the current state

### transitionState

    protected void transitionState(Arc arc)

  Transitions to the to-state given in the arc, and performs the action.
  Parameters:
    `arc` - the finite state machine arc

### initialize

    public void initialize(java.lang.String fsmStackId,
                           Fsm fsm)

  Initializes the fsm interpreter.
  Parameters:
    `fsmStackId` - provides an id for the first fsm stack
    `fsm` - the initial fsm, which is also the sole object on the fsm stack

### sendChatMessage

    public void sendChatMessage(java.lang.String chatMessage)
                         throws ChatException

  Sends the given chat message into the chat system.
  Parameters:
    `chatMessage` - the chat message

### setStateAttribute

    public void setStateAttribute(java.lang.String attribute,
                                  java.lang.Object value)

  Sets the value for the given state attribute.
  Parameters:
    `attribute` - the key object
    `value` - the value object

### setNextPerformative

    public void setNextPerformative(Performative nextPerformative)

  Sets the value of the computed next performative.
  Parameters:
    `nextAction` - the computed next performative

### getStateAttribute

    public java.lang.Object getStateAttribute(java.lang.Object attribute)

  Returns the value for the given state attribute.
  Parameters:
    `attribute` - the key object

### setupSubFsm

    public void setupSubFsm(Fsm fsm,
                            java.util.ArrayList arguments)

  Sets up the given sub fsm and the input arguments as a list of attribute/value pairs.
  Parameters:
    `fsm` - the new fsm
    `arguments` - a list of Object arrays of length two, the first array element is the attribute and the second array element is its value

### pushFsmStateInfo

    public void pushFsmStateInfo(FsmStateInfo fsmStateInfo)

  Pushes the given fsm state onto the current fsm stack.
  Parameters:
    `fsmStateInfo` - the new fsm and its state

### popFsmStateInfo

    public void popFsmStateInfo()

  Pops the fsm state stack and restores the previous fsm state.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD