Class Describer
java.lang.Object
edu.uky.cs.nil.tt.world.Describer
A tool for generating English descriptions of certain objects based on
natural language templates. A describer has basic rules for conjugating verbs
and replacing parts of sentences with the names or descriptions of objects.
It is designed to be easy to serialize.
A template is a string, but with certain key phrases wrapped in curly braces
that will be replaced with values. When the name of a key appears
in curly braces, it will be replaced with the description of the value of
that key. When the base form of a verb appears in curly
braces, the verb will be replaced with the third person
form of the verb, unless the word "you" followed by a space appears
immediately before the verb, in which case the verb will be replaced by the
second person form of the verb.
Here are some recommendations for how objects should be described:
Actions should be described as turns that succeed.- Turns that
succeedshould be described in third person present tense to thegame masterand second person present tense to theplayer. - Turns that
proposean action should be described in present tense as a character under the control of the proposer trying or offering to do something. - Turns the
failshould be described in present tense as the proposing character attempting to do the action but failing or as a character until the control of the other role refusing an offer.
- Author:
- Stephen G. Ware
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe names of elements which can be replaced in description templatesstatic classAdescriberrule has two parts: a context that defines when to apply it and a natural language template to use when this rule is applied.static classA verb is an object used in the templates of adescriber. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Describer.Rule rule) Adds a rule to the end of the list of rules that this describer can apply when describing an object.voidadd(Describer.Verb verb) Adds a verb to this describer, or replaces an existing verb with the same base, if one exists.Applies this describer's rules to generate a natural language description of the given object for a session'sgame master.Applies this describer's rules to generate a natural language description of the given object for a given role.getRule(Map<Describer.Key, Object> context) Returns the first rule from this describer thatmatchesa given context.getRules()Returns an unmodifiable list of all the rules used by this describer, in the order they will be checked to see if they apply.getSentence(Object object) Applies this describer's rules to generate a natural language description of the given object for a session'sgame master, with the first letter capitalized and ending in a period.getSentence(Object object, Role to) Applies this describer's rules to generate a natural language description of the given object for a given role, with the first letter capitalized and ending in a period.Returns the verb with the givenbase.getVerbs()Returns all the verbs used by this describer.toString()
-
Constructor Details
-
Describer
public Describer()Constructs an empty describer with no verbs or rules.
-
-
Method Details
-
toString
-
getVerbs
Returns all the verbs used by this describer.- Returns:
- this describer's verbs
-
getVerb
Returns the verb with the givenbase.- Parameters:
base- the base of the desired verb- Returns:
- the verb with that base, or null if this describer has no verb with that base
-
add
Adds a verb to this describer, or replaces an existing verb with the same base, if one exists.- Parameters:
verb- the new verb to add to this describer
-
getRules
Returns an unmodifiable list of all the rules used by this describer, in the order they will be checked to see if they apply.- Returns:
- this describer's rules
-
getRule
Returns the first rule from this describer thatmatchesa given context.- Parameters:
context- a map of keys to the value that describe an object to be described- Returns:
- the first rule which would be used to describe an object with the given context
-
add
Adds a rule to the end of the list of rules that this describer can apply when describing an object.- Parameters:
rule- the new rule to be added
-
getPhrase
Applies this describer's rules to generate a natural language description of the given object for a given role. Eachruleis checked in order until one is found thatmatchesthe values of the given object. Then that rule's natural language template is applied to create the object's description.- Parameters:
object- the object to be describedto- the role for whom the description is being generated, and the value that will be assigned toDescriber.Key.TO- Returns:
- a description of the object suitable for the given role
-
getPhrase
Applies this describer's rules to generate a natural language description of the given object for a session'sgame master.- Parameters:
object- the object to be described- Returns:
- a description of the object
- See Also:
-
getSentence
Applies this describer's rules to generate a natural language description of the given object for a given role, with the first letter capitalized and ending in a period. If the string given is empty, an empty string is returned.- Parameters:
object- the object to be describedto- the role for whom the description is being generated, and the value that will be assigned toDescriber.Key.TO- Returns:
- a description of the object suitable for the given role as a sentence with a capitalized first letter and ending with a period, or an empty string if an empty string was given
- See Also:
-
getSentence
Applies this describer's rules to generate a natural language description of the given object for a session'sgame master, with the first letter capitalized and ending in a period.- Parameters:
object- the object to be described- Returns:
- a description of the object as a sentence with a capitalized first letter and ending with a period
- See Also:
-