standup.joke
Class JokeGraph

java.lang.Object
  extended by standup.joke.JokeGraph
All Implemented Interfaces:
XMLizable

public class JokeGraph
extends Object
implements XMLizable

A JokeGraph records all the internal structure of a JokeStructure, allowing us to inspect all the choices made by the Generator during the various stages of joke generation, i.e. schema instantiation, output specification function clause instantiation, and template filling.

Author:
Ruli Manurung

Field Summary
(package private)  Hashtable<String,List<JokeGraphEdge>> adjacency
          A Hashtable that stores all the JokeGraphEdge s in this JokeGraph.
static int CLAUSE_INSTANTIATON
           
private  List<Keyword> clauseInstantiations
          A List of keywords in this graph which arise during clause instantiation.
(package private)  int counter
          A counter that ensures unique node label numbering.
(package private)  Hashtable<String,JokeGraphNode> nodes
          A Hashtable that stores all the JokeGraphNode s in this JokeGraph.
static int SCHEMA_INSTANTIATON
           
private  List<Keyword> schemaInstantiations
          A List of keywords in this graph which arise during schema instantiation.
 
Constructor Summary
JokeGraph(Hashtable<String,JokeGraphNode> nodes, Hashtable<String,List<JokeGraphEdge>> edges, List<Keyword> schemaInstantiations, List<Keyword> clauseInstantiations, int nodeCounter)
          This is the constructor used to build JokeGraphs from existing ones, e.g.
JokeGraph(Schema s, Bindings b)
          This is the constructor used to create a JokeGraph during the schema instantiation phase.
 
Method Summary
(package private)  void addEdge(String edgeLabel, JokeGraphNode from, JokeGraphNode to, SourceProcess sp, String sl)
           
private  void addLexNode(Bindings bindings, UnifiableVariable variable, SourceProcess sourceProcessCode, String sourceLabel)
          Given a UnifiableVariable that is bound to a Keyword, it creates a new JokeGraphNodeKeyword and replaces the binding of the variable to the node instead.
private  void addPrecondition(UnifiableCompound instantiatedPrecond, SourceProcess sp, String sl)
          Adds edges representing the given (instantiated) Precondition.
private  void addPreconditions(Bindings bindings, List<Precondition> preconditions, SourceProcess sourceProcess, String sourceLabel)
          Given a list of Preconditions, this method goes through them and adds representations of them to this JokeGraph.
(package private)  String addTemplateNode(String parentTemplateNodeID, String templateLabel, int childNumber)
          This method adds a node to the jokegraph that represents a template.
private  void addVars(Bindings b, UnifiableListVar vars, SourceProcess sourceProcessCode, String sourceLabel)
          This function adds a node to the jokegraph for a variable appearing in a lexical precondition, whether coming from a schema or a clause.
 JokeGraph copy()
          Returns a copy of this JokeGraph.
 boolean equals(Object obj)
           
 List<Keyword> getClauseInstantiations()
          Returns a List of Keywords that arise during clause instantiation.
 Iterator<JokeGraphEdge> getEdges(JokeGraphNode node)
          Returns the edges associated with the given JokeGraphNode as an Iterator<JokeGraphNode>.
private  int getNextCount()
           
 JokeGraphNode getNode(String nodeID)
          Returns the node in this graph with the given ID.
 Iterator<JokeGraphNode> getNodes()
          Returns the nodes in this JokeGraph as an Iterator<JokeGraphNode>.
 List<Keyword> getSchemaInstantiations()
          Returns a List of Keywords that arise during schema instantiation.
 int hashCode()
           
static JokeGraph readXML(Element e)
           
 String toString()
           
 void update(Clause c, Bindings b)
          Updates this JokeGraph with nodes and edges arising from this output specification function clause instantiation
 void writeXML(Writer out, String indent)
          This method writes the necessary information contained within an instance to an XML file.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

nodes

Hashtable<String,JokeGraphNode> nodes
A Hashtable that stores all the JokeGraphNode s in this JokeGraph. The keys are the node labels, the values are the JokeGraphNode s themselves.


adjacency

Hashtable<String,List<JokeGraphEdge>> adjacency
A Hashtable that stores all the JokeGraphEdge s in this JokeGraph. The keys are the 'originating' node labels (note that these are directed edges), and the values are the lists of JokeGraphEdge s themselves.


counter

int counter
A counter that ensures unique node label numbering.


schemaInstantiations

private List<Keyword> schemaInstantiations
A List of keywords in this graph which arise during schema instantiation. Strictly speaking this is a redundant field that ought to be computable from the graph itself (although the _order_ they appear in this list is useful for checking against the SQL database).


clauseInstantiations

private List<Keyword> clauseInstantiations
A List of keywords in this graph which arise during clause instantiation. Strictly speaking this is a redundant field that ought to be computable from the graph itself (although the _order_ they appear in this list is useful for checking against the SQL database).


SCHEMA_INSTANTIATON

public static final int SCHEMA_INSTANTIATON
See Also:
Constant Field Values

CLAUSE_INSTANTIATON

public static final int CLAUSE_INSTANTIATON
See Also:
Constant Field Values
Constructor Detail

JokeGraph

JokeGraph(Hashtable<String,JokeGraphNode> nodes,
          Hashtable<String,List<JokeGraphEdge>> edges,
          List<Keyword> schemaInstantiations,
          List<Keyword> clauseInstantiations,
          int nodeCounter)
This is the constructor used to build JokeGraphs from existing ones, e.g. making copies of JokeGraphs, or reading in JokeGraphs from XML files. All fields are provided

Parameters:
nodes - Hashtable of nodes
edges - Hashtable of edges
schemaInstantiations - List of Keyword schema instantiations
clauseInstantiations - List of Keyword clause instantiations
nodeCounter - counter used to label new nodes

JokeGraph

public JokeGraph(Schema s,
                 Bindings b)
This is the constructor used to create a JokeGraph during the schema instantiation phase. It performs the task of the MakeJokeGraph function mentioned in Chapter 4, Algorithm 5 of the Technical Spec doc.

Parameters:
s - Schema being used for this JokeGraph
b - Bindings obtained by unifying the instantiated keywords with the schema variables.
Method Detail

getNode

public JokeGraphNode getNode(String nodeID)
Returns the node in this graph with the given ID.

Parameters:
nodeID -
Returns:

getNodes

public Iterator<JokeGraphNode> getNodes()
Returns the nodes in this JokeGraph as an Iterator<JokeGraphNode>.

Returns:

getEdges

public Iterator<JokeGraphEdge> getEdges(JokeGraphNode node)
Returns the edges associated with the given JokeGraphNode as an Iterator<JokeGraphNode>.

Returns:

getSchemaInstantiations

public List<Keyword> getSchemaInstantiations()
Returns a List of Keywords that arise during schema instantiation. The order of elements in this list matches the order of variables in Schema.getVariables() -- this is used, for example, in setting up the schema exclusion tables.

Returns:

getClauseInstantiations

public List<Keyword> getClauseInstantiations()
Returns a List of Keywords that arise during clause instantiation. The

Returns:

getNextCount

private int getNextCount()
Returns:

copy

public JokeGraph copy()
Returns a copy of this JokeGraph.

Returns:

update

public void update(Clause c,
                   Bindings b)
Updates this JokeGraph with nodes and edges arising from this output specification function clause instantiation

Parameters:
c - The chosen OSF clause
b - The bindings of the instantiation

addPreconditions

private void addPreconditions(Bindings bindings,
                              List<Precondition> preconditions,
                              SourceProcess sourceProcess,
                              String sourceLabel)
Given a list of Preconditions, this method goes through them and adds representations of them to this JokeGraph. It constructs new nodes for previously unseed lexical elements, and adds appropriate edges.

Parameters:
bindings -
preconditions -

addVars

private void addVars(Bindings b,
                     UnifiableListVar vars,
                     SourceProcess sourceProcessCode,
                     String sourceLabel)
This function adds a node to the jokegraph for a variable appearing in a lexical precondition, whether coming from a schema or a clause. it also stores the Lexeme/WordForm bound to that variable under the node.

Parameters:
b -
vars -

addLexNode

private void addLexNode(Bindings bindings,
                        UnifiableVariable variable,
                        SourceProcess sourceProcessCode,
                        String sourceLabel)
Given a UnifiableVariable that is bound to a Keyword, it creates a new JokeGraphNodeKeyword and replaces the binding of the variable to the node instead.


addPrecondition

private void addPrecondition(UnifiableCompound instantiatedPrecond,
                             SourceProcess sp,
                             String sl)
Adds edges representing the given (instantiated) Precondition. Assumes that all argument variables have been bound to JokeGraphNodes already1

Parameters:
instantiatedPrecond -

addEdge

void addEdge(String edgeLabel,
             JokeGraphNode from,
             JokeGraphNode to,
             SourceProcess sp,
             String sl)

addTemplateNode

String addTemplateNode(String parentTemplateNodeID,
                       String templateLabel,
                       int childNumber)
This method adds a node to the jokegraph that represents a template.


writeXML

public void writeXML(Writer out,
                     String indent)
              throws IOException,
                     XMLException
Description copied from interface: XMLizable
This method writes the necessary information contained within an instance to an XML file.

Specified by:
writeXML in interface XMLizable
Parameters:
out - The output stream for the XML file, which is assumed to be already opened and writable.
indent - A string to be prepended before every line written by this method. If passed appropriate white space, e.g. XMLUtils.xmlIndent, it can be used to control indentation.
Throws:
IOException
XMLException

readXML

public static JokeGraph readXML(Element e)
                         throws XMLException
Throws:
XMLException

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object