standup.joke
Class InstantiationConstraintLexicon

java.lang.Object
  extended by standup.joke.InstantiationConstraintLexicon
All Implemented Interfaces:
InstantiationConstraint, JokeConstraint
Direct Known Subclasses:
InstantiationConstraintLexiconAll, InstantiationConstraintLexiconClause, InstantiationConstraintLexiconNone, InstantiationConstraintLexiconSchema

public class InstantiationConstraintLexicon
extends Object
implements InstantiationConstraint

An InstantiationConstraint that constrains a joke to make use of at least one Lexeme in a given LexemeSet.

Currently, if used to actually generate a joke, it requires a member Lexeme to appear in both the schema and clause instantiations! Use either InstantiationConstraintLexiconSchema or InstantiationConstraintLexiconClause instead.

It works as expected for validate(JokeStructure), though.

Author:
Ruli Manurung

Field Summary
(package private)  LexemeSet lexicon
          The LexemeSet where at least one Lexeme is required to appear in the joke.
(package private)  String lxsTable
          The name of the (temporary) SQL table that has been created in the SQL database for querying purposes.
 
Constructor Summary
InstantiationConstraintLexicon(LexemeSet lexs)
          Constructor must provide the LexemeSet and the name for the SQL table.
 
Method Summary
protected  void finalize()
           
 String getSQLConstraint(Clause s, List<SQLSelectElement> taqlsses)
          Returns an SQL code snippet that is to be appended to the WHERE clause of the SQL query when instantiating the given Clause.
 void handleSchema(SQLQuerySchema schemaSQLQuery)
          Modifies the given SQLQuerySchema to reflect this constraint.
 String toString()
           
 boolean validate(JokeStructure j)
          Returns true if the given JokeStructure satisfies this constraint, and false if not.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lexicon

LexemeSet lexicon
The LexemeSet where at least one Lexeme is required to appear in the joke.


lxsTable

String lxsTable
The name of the (temporary) SQL table that has been created in the SQL database for querying purposes. This table must be created when the LexiconConstraint is created. -- should it be explicitly destroyed when this object is destroyed as well?

Constructor Detail

InstantiationConstraintLexicon

public InstantiationConstraintLexicon(LexemeSet lexs)
Constructor must provide the LexemeSet and the name for the SQL table. It then constructs the (temporary) SQL table.

Parameters:
lexs -
tableName -
Method Detail

handleSchema

public void handleSchema(SQLQuerySchema schemaSQLQuery)
Description copied from interface: InstantiationConstraint
Modifies the given SQLQuerySchema to reflect this constraint.

Specified by:
handleSchema in interface InstantiationConstraint

getSQLConstraint

public String getSQLConstraint(Clause s,
                               List<SQLSelectElement> taqlsses)
Description copied from interface: InstantiationConstraint
Returns an SQL code snippet that is to be appended to the WHERE clause of the SQL query when instantiating the given Clause.

Specified by:
getSQLConstraint in interface InstantiationConstraint
Parameters:
s - the Clause being instantiated.
Returns:
-- the String to be appended to the WHERE clause. As a contract, we require that it appear between parentheses, e.g. "(...)" for readability purposes.

validate

public boolean validate(JokeStructure j)
Description copied from interface: JokeConstraint
Returns true if the given JokeStructure satisfies this constraint, and false if not.

Specified by:
validate in interface JokeConstraint
Parameters:
j - the JokeStructure being validated
Returns:
-- true if j satisfies this constraint, false otherwise.

toString

public String toString()
Overrides:
toString in class Object

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable