|PREV PACKAGE NEXT PACKAGE||FRAMES NO FRAMES|
|InstantiationConstraint||An InstantiationConstraint represents a constraint on the keyword instantiations of a JokeStructure.|
|Backend||The main class through which joke generation and related functionality should be accessed.|
|BackendJokeSetOnly||A subclass of
|BackendJokeSetSQL||A subclass of
|BackendSQL||A subclass of
|Clause||An output specification function clause.|
|Generator||The main class that handles joke generation.|
|JokeGraphEdge||An edge in a
|JokeGraphNode||A node in a
|JokeGraphNodeKeyword||A node in a
|JokeGraphNodeTemplate||A node in a
|JokeSet||This class represents a set of
|JokeStructure||A generated joke, with all its underlying data structures.|
|JokeType||A type of joke as defined in the technical specification document.|
|JokeTypeSet||A set of
|OptionsGUIJokeGeneration||A Swing-based GUI for editing the various joke generation options.|
|Schema||This class implements a schema as defined in the technical specification.|
|SchemaTemplatePair||Defines a combination of suitable schemas and templates for joke generation.|
|SQLQuerySchema||Represents a query on a schema instantiation table.|
|AllowableAmbiguity||Possible values for
|JokeCacheBehaviour||Possible values for
|SourceProcess||An object indicating when an element in a
|GeneratorException||A very simple subclass of Exception that is specifically for Exceptions arising from within the standup.joke package.|
This package provides joke generation functionality and all its related data structures.
The main class to use is the
Backend, which handles requests for joke generation and records a user's log of generated jokes in a
ProfileJokeGeneration. Actual joke generation is handled by the
Generator class, which implements the joke generation and surface generation processes described in chapters ? and ? of the STANDUP backend technical specification document.
An arbitrary number of
JokeConstraints can be imposed to control specific aspects of the jokes that are to be generated or retrieved, e.g. ensuring jokes use specific keywords, or use a particular type of question form, or satisfy a minimum threshold of phonetic similarity, etc.
A joke is represented as an instance of a
JokeStructure, which contains a
JokeGraph, a graph data structure that records all choices made by the
Generator during the joke generation process.
This section provides a very quick introduction to using the
standup.joke package. More details are provided in the subsequent sections.
Backend(note that the
Backendclass itself is abstract). If you have installed the PostgreSQL-based lexical database, you can choose to instantiate a
BackendJokeSetSQL. Otherwise, instantiate a
BackendJokeSetOnly-- which we use in the following example:
import standup.joke.*; import standup.profiling.ProfileManager; Backend myBackend = new BackendJokeSetOnly();
Backendclass provides functionality of saving user-specific option settings and personal history. Creation and manipulation of these profiles is handled through the
ProfileManagerclass (see the
standup.profilingpackage documentation for more details).
ProfileManager.initialize(); ProfileManager.createUser("username",myBackend); ProfileManager.useProfile("username",myBackend);
getNewJokemethods provided by the
Backendclass. Here we use the default
Backend.getNewJoke()and print the question and answer to the console, before finally adding it to the user profile's favourite jokes collection:
JokeStructure myJoke = myBackend.getNewJoke(); System.out.println(myJoke.getQuestion()); System.out.println(myJoke.getAnswer()); myBackend.addToFavourites(myJoke);
Backend class performs joke generation in a manner that is aware of a user's profile in two ways:
OptionsJokeGenerationfor details), and
It implements the
Profileable interface, which provides the user profiling functionality. The user profile related to joke generation is implemented in the
Backend class itself is
abstract, so when instantiating it, one of the following must be chosen:
BackendJokeSetSQL: the default implementation of
Backendused by the STANDUP system. It can be configured to generate novel jokes by consulting the SQL database or to retrieve existing jokes from a given
BackendJokeSetOnly: the implementation of
Backendused by the 'demo' version of STANDUP. It does not attempt to establish a connection to the SQL server, and can thus be run on machines where there is no access to PostgreSQL.
BackendSQL: an implementation that always generates new jokes using the SQL database. Note that this is actually subsumed by
BackendJokeSetSQLusing a appropriate
JokeCacheBehaviouruser option, but is included for historical reasons.
Backend.getNewJokemethods, for reasons described above.
|Generates a random joke|
|Generates a random joke of a given |
|Generates a random joke that uses a particular |
|Generates a random joke that uses at least one |
|Generates a random joke that uses at least one |
The above methods are all 'syntactic sugar' methods which actually call the
standup.joke.#getNewJoke(JokeConstraints) method. Using this method directly allows the specification of much more complex combinations of constraints, e.g. generating a joke of a particular
JokeType, using a particular
Lexeme, and about a given
Topic, etc. However, the
getNewJoke(JokeConstraints) method does not automatically include the constraints imposed by the current user profile. To obtain this, use the
standup.joke.#buildUserProfileConstraints() method, and add to the resulting
JokeConstraints as required.
Finally, when the above methods need to generate a new joke (i.e. not simply to retrieve one from an existing 'cache' of pre-generated jokes), they all call
Generator.generateJoke(String,JokeConstraints), which really performs joke generation. If you don't care about user profiling, you can bypass the
Backend completely and call this method directly.
The various joke generating methods described above all return a
JokeStructure, which contains all information relating to how the joke was constructed.
The simplest way of obtaining the joke is through the
JokeStructure.getAnswer() methods, which return
String representations of the question and answer of the joke respectively.
To obtain a more detailed view of the joke, use the
JokeStructure.getAnswerStruct() methods, which return
WordStruct representations of the question and answer of the joke respectively. A
WordStruct allows one to distinguish between the 'canned' text of a joke and the
Keywords of a joke, i.e. lexical elements that instantiate
Clauses (see below for details).
JokeStructure also provides various
boolean-returning methods for testing various aspects, e.g.:
|Test whether a joke is of a given type.|
|Test whether a joke satisfies an arbitrary collection of constraints.|
|Test whether a joke uses a given lexeme.|
|Test whether a joke uses at least one lexeme from a given set.|
|Test whether all lexemes in a joke belong to a given set.|
|Test whether a joke uses at least one lexeme about a given topic.|
However, the most detailed data structure relating to a joke is the
JokeGraph, which can be obtained from a
JokeStructure by calling
JokeGraph records all the internal structure of a joke, allowing us to inspect all the choices made by
Generator during the various stages of joke generation,
i.e. schema instantiation, output specification function clause
instantiation, and template filling (see the STANDUP backend technical specification for details).
JokeGraph consists of a set of
JokeGraphNodes, which may be connected through (directed)
JokeGraphEdges. A node can either correspond to a keyword, in which case it will be a
standup.joke.JokeGraphNodeLex, or to a piece of 'canned' text from a template, in which case it will be a
JokeGraphNodeTemplate. Where a
JokeGraphNode corresponds to a span of text in either the question or answer
WordStruct, they will share the same label.
JokeConstraint represents a constraint on a particular aspect of a joke.
All of them support a generate-and-test form of validation through the
JokeConstraint.validate(JokeStructure) method, which returns
true if a given joke satisfies that constraint, and
false otherwise. Additionally, most of them provide some other way of imposing themselves on the joke generation process. An
InstantiationConstraint is a
JokeConstraint that can modify an SQL query when obtaining either
Clause instantiations through the
InstantiationConstraint.getSQLConstraint(Clause, List) methods, respectively.
JokeConstraints object simply represents a collection of constraints.
|A joke must use one of a given set of Schemas.|
|A joke must be of a given type.|
|A joke must satisfy a minimum AllowableAmbiguity.|
|All keywords in a joke must have an F-score equal to or above a given threshold.|
|A joke must use a given keyword (variants for Schema or Clause).|
|A joke must use at least one keyword from a given set (variants for Schema or Clause).|
|All keywords in a joke must belong to a given set (variants for Schema or Clause).|
|A joke must not have been previously generated (w.r.t user profile's history).|
|All homophone relations in a joke must have a phonetic similarity rating equal to or above a given threshold|
JokeSetrepresents a collection of jokes. It provides various methods for retrieving and manipulating jokes, e.g.:
add: adding a single joke or a set of jokes.
remove: removing a single joke or a set of jokes.
getRandom/removeRandom: randomly getting or removing a single joke.
getJokes(JokeConstraints: getting a subset of jokes that satisfy a collection of constraints.
Generator class handles the actual joke generation process. It requires access to various joke resources, i.e.:
Schema: defines a configuration of keywords that leads to the construction of the answer of a joke.
Clause: defines a configuration of keywords that leads to the construction of the question of a joke.
Template: defines a structure of 'canned' text that, when combined with an instantiated and , yields a joke.
JokeType: defines a class of jokes based on a combination of
The STANDUP backend technical specification document provides more details on these objects.
When instantiating a
Generator using the default
Generator.Generator() constructor, it loads all necessary joke resources from definitions found within the
/standup/resources/xml/ subdirectory of the STANDUP
.jar file. Alternatively, the
Generator.Generator(URL) constructor will instantiate a
Generator using a set of joke resources defined elsewhere.
Generator.generateJokeStructure(String, Schema, List, List, List, double, JokeConstraints) methods implements the joke generation process (more specifically, they implement schema instantiation and clause instantiation respectively), whereas the
Generator.surfaceGenerate(List, String, JokeGraph, JokeConstraints) method implements the surface generation process. All of this is described in detail in the technical specification document. All these methods gradually build up a
JokeGraph and enclosing
JokeStructure as they proceed.
|PREV PACKAGE NEXT PACKAGE||FRAMES NO FRAMES|