|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object standup.joke.Backend
public abstract class Backend
The main class through which joke generation and related functionality should be accessed.
A Backend
provides the following main functionality:
getNewJoke
methods.
getOldJokes
methods.
Field Summary | |
---|---|
protected Generator |
generator
|
private LexicalComponents |
lexicalComponents
|
private ProfileJokeGeneration |
profileJokeGeneration
|
Constructor Summary | |
---|---|
Backend()
Default constructor that instantiates a default Generator and a
default LexicalComponents , which will eventually be configured
when a user profile is set. |
Method Summary | |
---|---|
void |
addToFavourites(JokeStructure j)
Adds the given JokeStructure to the current user's favourite
jokes collection. |
JokeConstraints |
buildUserProfileConstraints()
Builds and returns a JokeConstraints that represents the various
parameters and choices in the current ProfileJokeGeneration . |
boolean |
createProfile(File directory)
Creates a default profile in the given directory. |
(package private) abstract JokeStructure |
generateNewJoke(String newJokeID,
JokeConstraints jcs)
Attempts to generate a new joke that satisfies the given JokeConstraints and labels it with the given joke ID. |
JokeTypeSet |
getCurrentUserUsedJokeTypes()
Returns a JokeTypeSet containing the current user's used
JokeType s. |
JokeSet |
getFavouriteJokes()
Returns the subset of the current user's favourite jokes that satisfy the current user's joke constraints. |
Generator |
getGenerator()
Returns the Generator instance. |
LexicalComponents |
getLexicalComponents()
Returns the LexicalComponents instance. |
JokeStructure |
getNewJoke()
Attempts to generate a new joke that satisfies the current user profile's constraints. |
JokeStructure |
getNewJoke(JokeConstraints jcs)
Tries to generate a new joke that satisfies the given JokeConstraints . |
JokeStructure |
getNewJoke(JokeType t)
Attempts to generate a new joke that satisfies the current user profile's constraints and is of the given JokeType . |
JokeStructure |
getNewJoke(Lexeme k)
Attempts to generate a new joke that satisfies the current user profile's constraints and uses the given Lexeme in its answer. |
JokeStructure |
getNewJoke(LexemeSet lxs)
Attempts to generate a new joke that satisfies the current user profile's constraints and uses at least one Lexeme from the given
LexemeSet in its answer. |
JokeStructure |
getNewJoke(Topic t)
Attempts to generate a new joke that satisfies the current user profile's constraints and uses at least one Lexeme 'about' the given
Topic in its answer. |
private String |
getNextJokeID()
Returns a unique joke ID for the next joke to be generated. |
JokeSet |
getOldJokes()
Returns the subset of the current user's previously generated jokes that satisfy the current user profile's constraints. |
JokeSet |
getOldJokes(JokeConstraints constraints)
Returns the subset of the current user's previously generated jokes that satisfy the given JokeConstraints . |
JokeSet |
getOldJokes(JokeType t)
Returns the subset of the current user's previously generated jokes that satisfy the current user profile's constraints and is of the given JokeType . |
JokeSet |
getOldJokes(Lexeme k)
Returns the subset of the current user's previously generated jokes that satisfy the current user profile's constraints and use the given Lexeme in either their question or answer. |
JokeSet |
getOldJokes(LexemeSet lxs)
Returns the subset of the current user's previously generated jokes that satisfy the current user profile's constraints and use at least one Lexeme from the given LexemeSet in their question or
answer. |
JokeSet |
getOldJokes(Topic t)
Returns the subset of the current user's previously generated jokes that satisfy the current user profile's constraints and use at least one Lexeme 'about' the given Topic in their question or
answer. |
ProfileJokeGeneration |
getProfile()
Returns the ProfileJokeGeneration currently being used by this
Backend . |
String |
getProfileFilename()
Returns the filename for joke generation profiles. |
Topic |
getRootTopic()
Currently returns the first found root topic as specified by LexicalComponents#getRootTopicLabels() . |
ProfileJokeGeneration |
loadProfile(File directory)
Loads the joke generation profile from the specified directory and returns it. |
boolean |
setProfile(Profile profile,
boolean repeat)
Sets this Backend to use the specified joke generation profile. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Generator generator
private ProfileJokeGeneration profileJokeGeneration
private final LexicalComponents lexicalComponents
Constructor Detail |
---|
public Backend() throws GeneratorException
Generator
and a
default LexicalComponents
, which will eventually be configured
when a user profile is set.
GeneratorException
Method Detail |
---|
public JokeConstraints buildUserProfileConstraints()
JokeConstraints
that represents the various
parameters and choices in the current ProfileJokeGeneration
.
JokeConstraints
representing the current user profile's
settings.ProfileJokeGeneration#addUserConstraints(JokeConstraints,
JokeTypeSet)
private String getNextJokeID()
joke_
+ current user name + joke_
+ next joke counter
For example, if current user "ruli" has previously generated 10 jokes,
this method will return "joke_ruli_10"
.
ProfileJokeGeneration.getNextJokeCounter()
public JokeStructure getNewJoke(JokeConstraints jcs)
JokeConstraints
. If successful, adds it to the current user
profile's generated joke log and returns it. Otherwise, returns
null
.
In practice, this method calls on
generateNewJoke(String, JokeConstraints)
, whose implementation
is specific to the subclass of Backend
.
jcs
- the constraints on the joke to be generated
jcs
, or null
if none
could be generatedabstract JokeStructure generateNewJoke(String newJokeID, JokeConstraints jcs)
JokeConstraints
and labels it with the given joke ID. This should
never be called directly -- use getNewJoke(JokeConstraints)
instead.
newJokeID
- the joke ID for the generated jokejcs
- the constraints on the joke to be generated
jcs
, or null
if none
could be generatedpublic JokeStructure getNewJoke()
null
otherwise.buildUserProfileConstraints()
public JokeStructure getNewJoke(JokeType t)
JokeType
.
t
- the type of joke requested
null
otherwise.buildUserProfileConstraints()
,
JokeConstraintType
public JokeStructure getNewJoke(Lexeme k)
Lexeme
in its answer.
Currently this does not support generating a joke where the
Lexeme
appears in the question of the joke.
k
- the lexeme to appear in the joke's answer
null
otherwise.buildUserProfileConstraints()
,
InstantiationConstraintLexemeSchema
public JokeStructure getNewJoke(LexemeSet lxs)
Lexeme
from the given
LexemeSet
in its answer.
Currently this does not support generating a joke where the
Lexeme
appears in the question of the joke.
lxs
- the set of which at least one member Lexeme
appears in
the joke's answer
null
otherwise.buildUserProfileConstraints()
,
InstantiationConstraintLexiconSchema
public JokeStructure getNewJoke(Topic t)
Lexeme
'about' the given
Topic
in its answer. A Lexeme
is considered to be about a
given Topic
if it appears in the Topic
's set of
Lexeme
s or any of its subTopic
s' set of Lexeme
s.
Currently this does not support generating a joke where the
Lexeme
appears in the question of the joke.
t
- the Topic
that at least one Lexeme
appearing
in the joke's answer should be about
null
otherwise.buildUserProfileConstraints()
,
InstantiationConstraintLexiconSchema
,
Topic.getAllKeywords()
public JokeSet getOldJokes(JokeConstraints constraints)
JokeConstraints
.
constraints
- the constraints that the returned jokes must satisfy
JokeSet
of previously generated jokes that satisfy
constraints
ProfileJokeGeneration.getGeneratedJokeLog()
,
JokeSet.getJokes(JokeConstraints)
public JokeSet getOldJokes()
To get the entire generated joke log, regardless of the user's
constraints, call Backend.getProfile().getGeneratedJokeLog()
instead.
JokeSet
of previously generated jokes that satisfy the
current user profile's constraintsbuildUserProfileConstraints()
,
ProfileJokeGeneration.getGeneratedJokeLog()
public JokeSet getOldJokes(JokeType t)
JokeType
.
t
- the type of joke requested
JokeSet
of previously generated jokes that satisfies
the conditions abovebuildUserProfileConstraints()
,
JokeConstraintType
public JokeSet getOldJokes(Lexeme k)
Lexeme
in either their question or answer.
Note the current asymmetry with getNewJoke(Lexeme)
, which only
generates a joke where the Lexeme
appears in the answer.
k
- the Lexeme
to appear in the jokes
JokeSet
of previously generated jokes that satisfies
the conditions abovebuildUserProfileConstraints()
,
InstantiationConstraintLexeme
public JokeSet getOldJokes(LexemeSet lxs)
Lexeme
from the given LexemeSet
in their question or
answer.
Note the current asymmetry with getNewJoke(LexemeSet)
, which
only generates a joke where a member Lexeme
appears in the
answer.
lxs
- the set of which at least one member Lexeme
appears in
the jokes
JokeSet
of previously generated jokes that satisfies
the conditions abovebuildUserProfileConstraints()
,
InstantiationConstraintLexicon
public JokeSet getOldJokes(Topic t)
Lexeme
'about' the given Topic
in their question or
answer. A Lexeme
is considered to be about a given Topic
if it appears in the Topic
's set of Lexeme
s or any of
its subTopic
s' set of Lexeme
s.
Note the current asymmetry with getNewJoke(Topic)
, which only
generates a joke where a relevant Lexeme
appears in the answer.
t
- the Topic
that at least one Lexeme
appearing
in the joke should be about
JokeSet
of previously generated jokes that satisfies
the conditions abovebuildUserProfileConstraints()
,
InstantiationConstraintLexicon
,
Topic.getAllKeywords()
public JokeSet getFavouriteJokes()
To get the entire favourite jokes, regardless of the user's constraints,
call Backend.getProfile().getFavourites()
instead.
buildUserProfileConstraints()
,
ProfileJokeGeneration.getFavourites()
public void addToFavourites(JokeStructure j)
JokeStructure
to the current user's favourite
jokes collection.
j
- the joke to be addedpublic Generator getGenerator()
Generator
instance.
public LexicalComponents getLexicalComponents()
LexicalComponents
instance.
public JokeTypeSet getCurrentUserUsedJokeTypes()
JokeTypeSet
containing the current user's used
JokeType
s.
OptionsJokeGeneration.getUsedJokeTypes(JokeTypeSet)
public Topic getRootTopic()
LexicalComponents#getRootTopicLabels()
.
public boolean createProfile(File directory)
OptionsJokeGeneration
contained within the OptionsPackage
returned by ProfileManager.getDefaultOptionsPackage()
.
createProfile
in interface Profileable
directory
- the directory where the profile is to be created
true
if the profile was successfully created,
false
otherwisepublic ProfileJokeGeneration getProfile()
ProfileJokeGeneration
currently being used by this
Backend
.
getProfile
in interface Profileable
ProfileJokeGeneration
public String getProfileFilename()
'jokegeneration.profile'
.
getProfileFilename
in interface Profileable
"jokegeneration.profile"
public ProfileJokeGeneration loadProfile(File directory)
loadProfile
in interface Profileable
directory
- The directory containing the joke generation profile
ProfileJokeGeneration
public boolean setProfile(Profile profile, boolean repeat)
Backend
to use the specified joke generation profile.
setProfile
in interface Profileable
profile
- the Profile
to be usedrepeat
- whether this is the first time a profile is being set for the
current user during this session
true
if successful, false
otherwise (e.g. if the
given profile was not an instance of
ProfileJokeGeneration
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |