|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstandup.joke.Generator
public class Generator
The main class that handles joke generation. It implements the algorithms
described in Chapters 4 and 5 of the Technical Specification doc (i.e. Joke
Generation and Surface Generation). It provides access to this engine through
the generateJoke(String, JokeConstraints)
method. This method should
typically not be called directly -- Instead, the Backend.getNewJoke()
method should be used, as it accounts for the user profile's constraints, and
updates the user's generated joke log.
Field Summary | |
---|---|
private List<Clause> |
clauses
A List of all output specification function Clause s
accessible to this Generator . |
private Hashtable<String,Boolean> |
exclusionTableSetupFlag
|
private String |
masterType
The label for the special 'master' JokeType . |
private Hashtable<String,Schema> |
schemas
A Hashtable containing all Schema s accessible to this
Generator . |
private List<Template> |
templates
A List of all Template s accessible to this
Generator . |
private JokeTypeSet |
types
A JokeTypeSet representing all available JokeType s. |
Constructor Summary | |
---|---|
Generator()
Default constructor that uses the various XML joke resource files specified under the /standup/resources/xml directory (i.e. |
|
Generator(URL url)
Constructor that uses the various joke resources specified by the given URL . |
Method Summary | |
---|---|
void |
doSTPFiltering(Schema ss)
Experimenting with question-driven generation! |
void |
doSTPFiltering(Schema ss,
float minimumSchemaFScoreThreshold,
float maximumSchemaFScoreThreshold)
This method computes the 'minmaxmin' FScore value of clause instantiations given a schema instantiation and a minimum and maximum FScore threshold for schema instantiations. |
private WordStruct |
elaborateBody(UnifiableList templateBody,
String parentTemplateNodeID,
int childNumber,
String templateLabel,
JokeGraph jokeGraph)
The main template filling algorithm. |
private StructElement |
elaborateTemplateItem(String parentTemplateNodeID,
int childNumber,
String templateLabel,
JokeGraphNodeKeyword nodeLex,
JokeGraph g)
Elaborates a lexical element, i.e. |
private StructElement |
elaborateTemplateItem(String parentTemplateNodeID,
int childNumber,
UnifiableCompound b,
JokeGraph g)
Recursively performs template filling on a template item that specifies another template |
private StructElement |
elaborateTemplateItem(UnifiableConstant bString,
Unifiable bsuccNODE,
JokeGraph g)
|
(package private) float |
findMaxMinFScoreValue(List<List<Keyword>> instantiations)
|
private float |
findMinMaxMinFScoreValueForOSF2(UnifiableCompound osf)
An alternative implementation that builds one long SQL query using the SQL UNION operator. |
JokeStructure |
generateJoke(String newJokeID,
JokeConstraints constraints)
Generates a new JokeStructure that satisfies the
constraints arguments, with the ID specified by
newJokeID . |
private JokeStructure |
generateJokeStructure(String newJokeID,
Schema schema,
List<Keyword> lex,
List<String> templatesQuestion,
List<String> templatesAnswer,
double phonSimValue,
JokeConstraints constraints)
This is the core algorithm which instantiates a schema's lexical preconditions with suitable lexemes, binds the output specification function clauses, builds the initial JokeGraph, and passes it on to surface generation. |
private float |
getClauseFScore(Schema s,
List<Keyword> lex)
|
List<Clause> |
getCompatibleClauses(Unifiable func,
int arity)
Returns a list of Clause s that are 'compatible' with the given
functor and arity, i.e they share the same functor and arity. |
private List<Template> |
getCompatibleTemplates(UnifiableCompound templateSpecifier)
Given a (dereferenced) template specifier, this method returns a list of compatible templates. |
private String |
getExclusionStatement(String schemaTableName,
UnifiableListVar lexemeVars,
List<Keyword> instantiations)
Returns an SQL statement string that updates the exclusion table |
private static String[] |
getIDs(List<Keyword> instantiations)
Returns an array of the lexeme IDs (enclosed in single quotes). |
JokeTypeSet |
getJokeTypes()
Returns a JokeTypeSet of all JokeType s accessible
to this Generator . |
JokeType |
getMasterJokeType()
Returns the 'master' JokeType , i.e. |
Schema |
getSchema(String label)
Returns the Schema specified by the label
argument, or null if no Schema exists with
the specified label. |
Set<String> |
getSchemaLabels()
Returns a Set of all schema labels accessible to this
Generator . |
private void |
initResources(URL url)
Sets up the various joke resources required for generation, i.e. |
private UnifiableCompound |
obtainTemplateSpecifier(UnifiableCompound osf,
JokeGraph jokeGraph,
JokeConstraints constraints)
Given an output specification function, this method finds an appropriate clause, instantiates it with values that satisfy the given JokeConstraints , updates the jokegraph, and returns the
resulting template specifier. |
private List<UnifiableCompound> |
obtainTemplateSpecifiers(List<UnifiableCompound> osfs,
JokeGraph jokeGraph,
JokeConstraints constraints)
Performs clause instantiation. |
(package private) static JokeTypeSet |
peekAtJokeTypes()
|
(package private) static String[] |
peekAtSchemaLabels()
|
private static List<Clause> |
readClauses(String filename)
Reads the output specification function clauses definitions from the given file and returns the resulting list<Clause> . |
private static JokeTypeSet |
readJokeTypes(String filename)
Reads the joke type definitions from the given file and returns the resulting JokeTypeSet . |
private static Hashtable<String,Schema> |
readSchemas(String filename)
Reads the schema definitions from the given file and returns a Hashtable<String,Schema> , where the keys are the schema labels,
and the values are the Schema s themselves. |
private static List<Template> |
readTemplates(String filename)
Reads the template definitions from the given file and returns the resulting List<Template> . |
void |
resetExclusionTableSetupFlags()
|
void |
setupExclusionTable(JokeSet jokelog,
String schemaLabel)
|
void |
setupExclusionTables(JokeSet jokelog)
|
private WordStruct |
surfaceGenerate(List<UnifiableCompound> outputSpecificationFunction,
String template,
JokeGraph jokeGraph,
JokeConstraints constraints)
Takes an output specification function, instantiated with nodes in the given JokeGraph, and generates a WordStruct using the given
template and satisfying the given JokeConstraints. |
private WordStruct |
templateFill(UnifiableCompound templateSpecifier,
String parentTemplateNodeID,
int childNumber,
JokeGraph jokeGraph)
Performs template filling, i.e. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private JokeTypeSet types
JokeTypeSet
representing all available JokeType
s.
private String masterType
JokeType
. The actual
JokeType
itself can be obtained using
getMasterJokeType()
.
private Hashtable<String,Schema> schemas
Hashtable
containing all Schema
s accessible to this
Generator
. The keys are the schema labels.
private List<Template> templates
List
of all Template
s accessible to this
Generator
.
private List<Clause> clauses
List
of all output specification function Clause
s
accessible to this Generator
.
private Hashtable<String,Boolean> exclusionTableSetupFlag
Constructor Detail |
---|
public Generator() throws GeneratorException
GeneratorException
public Generator(URL url) throws GeneratorException
URL
.
url
- a URL
that specifies the various joke resources
GeneratorException
Method Detail |
---|
private void initResources(URL url) throws GeneratorException
url
argument.
url
- a URL
that specifies the various joke resources
GeneratorException
static JokeTypeSet peekAtJokeTypes()
static String[] peekAtSchemaLabels()
private static List<Clause> readClauses(String filename)
list<Clause>
.
filename
- The name of the file containing the clause definitions
(currently assumed to be in /standup/xml/resources
).
Clause
s.private static JokeTypeSet readJokeTypes(String filename)
JokeTypeSet
.
filename
- The name of the file containing the joke type definitions
(currently assumed to be in /standup/xml/resources
).
private static List<Template> readTemplates(String filename)
List<Template>
.
filename
- The name of the file containing the template definitions
(currently assumed to be in /standup/xml/resources
).
Template
s.private static Hashtable<String,Schema> readSchemas(String filename) throws GeneratorException
Hashtable<String,Schema>
, where the keys are the schema labels,
and the values are the Schema
s themselves.
filename
- The name of the file containing the schema definitions
(currently assumed to be in /standup/xml/resources
).
GeneratorException
public Schema getSchema(String label)
Schema
specified by the label
argument, or null
if no Schema
exists with
the specified label.
label
- label of the desired schema.
Schema
with the given label, or null
if none exists.public Set<String> getSchemaLabels()
Set
of all schema labels accessible to this
Generator
.
Set
of all schema labelspublic JokeTypeSet getJokeTypes()
JokeTypeSet
of all JokeType
s accessible
to this Generator
.
JokeTypeSet
of all JokeType
spublic JokeType getMasterJokeType()
JokeType
, i.e. the JokeType
that consists of all implemented SchemaTemplatePair
s.
JokeType
public JokeStructure generateJoke(String newJokeID, JokeConstraints constraints)
JokeStructure
that satisfies the
constraints
arguments, with the ID specified by
newJokeID
.
This is the method that starts the joke generation process. We can impose arbitrary numbers of constraints (as long as the SQL server can accept the length of the query string!).
newJokeID
- the unique ID to be assigned to the resulting
JokeStructure
constraints
- the various JokeConstraint
s that the resulting
JokeStructure
must satisfy
private JokeStructure generateJokeStructure(String newJokeID, Schema schema, List<Keyword> lex, List<String> templatesQuestion, List<String> templatesAnswer, double phonSimValue, JokeConstraints constraints)
newJokeID
- The unique ID assigned to the newly created jokeschema
- The Schema to be usedlex
- The Schema instantiationstemplatesQuestion
- A List of valid question template labels to be usedtemplatesAnswer
- A List of valid answer template labels to be usedphonSimValues
- A List of the phonetic similarity values of the instantiations
in lexconstraints
- The JokeConstraints used to generate this joke (still needed
for clause instantiation)private WordStruct surfaceGenerate(List<UnifiableCompound> outputSpecificationFunction, String template, JokeGraph jokeGraph, JokeConstraints constraints)
WordStruct
using the given
template and satisfying the given JokeConstraints. Also updates the
JokeGraph.
outputSpecificationFunction
- the output specification function to be generatedtemplate
- the template header(?) to be generatedjokeGraph
- the joke graph being constructedconstraints
- the constraints to be satisfied
private List<UnifiableCompound> obtainTemplateSpecifiers(List<UnifiableCompound> osfs, JokeGraph jokeGraph, JokeConstraints constraints)
Performs clause instantiation. Given a list of output specification functions, a set of joke constraints, and the currently built joke graph, this method finds an appropriate clause and instantiates it -- updating the jokegraph in the process. It returns a list of template specifiers where the variables have been bound to corresponding JokeGraphNodeLexs in the graph.
osfs
- list of output specification functionsjokeGraph
- the intermediate joke graphconstraints
- all constraints to be satisfied
private UnifiableCompound obtainTemplateSpecifier(UnifiableCompound osf, JokeGraph jokeGraph, JokeConstraints constraints)
JokeConstraints
, updates the jokegraph, and returns the
resulting template specifier.
osf must be dereferenced to the joke graph nodes built so far, so that we
don't end up building new nodes for the same (schema instantiated)
lexemes/wordforms.
Likewise, the returned template specifier also has its variables bound to
nodes in the joke graph.
osf
- this should be a dereferenced OSF, where the arguments are
bound to JokeGraphNodeLex
s...jokeGraph
- constraints
-
public List<Clause> getCompatibleClauses(Unifiable func, int arity)
Clause
s that are 'compatible' with the given
functor and arity, i.e they share the same functor and arity.
This is made public only because JokeHandcrafter needs it, and is
currently in a different package.
func
- arity
-
private WordStruct templateFill(UnifiableCompound templateSpecifier, String parentTemplateNodeID, int childNumber, JokeGraph jokeGraph)
parentTemplateNodeID
- the ID of the parent node of the resulting structchildNumber
- the newly created WordStruct will be the childNumber-th childtemplateSpecifier
- jokeGraph
-
private List<Template> getCompatibleTemplates(UnifiableCompound templateSpecifier)
templateSpecifier
-
private WordStruct elaborateBody(UnifiableList templateBody, String parentTemplateNodeID, int childNumber, String templateLabel, JokeGraph jokeGraph)
templateBody
- the template body to be processedparentTemplateNodeID
- the ID of the JokeGraphNode representing the parent WordStructchildNumber
- the index denoting this resulting WordStruct's position
relative to its siblingstemplateLabel
- the template's labeljokeGraph
- the joke graph being built
private StructElement elaborateTemplateItem(String parentTemplateNodeID, int childNumber, UnifiableCompound b, JokeGraph g)
parentTemplateNodeID
- childNumber
- b
- g
-
private StructElement elaborateTemplateItem(String parentTemplateNodeID, int childNumber, String templateLabel, JokeGraphNodeKeyword nodeLex, JokeGraph g)
parentTemplateNodeID
- childNumber
- templateLabel
- nodeLex
- g
-
private StructElement elaborateTemplateItem(UnifiableConstant bString, Unifiable bsuccNODE, JokeGraph g)
public void doSTPFiltering(Schema ss)
constraints
- public void doSTPFiltering(Schema ss, float minimumSchemaFScoreThreshold, float maximumSchemaFScoreThreshold)
ss
- minimumSchemaFScoreThreshold
- private float getClauseFScore(Schema s, List<Keyword> lex)
private float findMinMaxMinFScoreValueForOSF2(UnifiableCompound osf)
osf
-
float findMaxMinFScoreValue(List<List<Keyword>> instantiations)
public void setupExclusionTables(JokeSet jokelog)
public void resetExclusionTableSetupFlags()
public void setupExclusionTable(JokeSet jokelog, String schemaLabel)
private String getExclusionStatement(String schemaTableName, UnifiableListVar lexemeVars, List<Keyword> instantiations)
schemaTableName
- lexemeVars
- instantiations
-
private static String[] getIDs(List<Keyword> instantiations)
instantiations
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |