Class Describer

java.lang.Object
edu.uky.cs.nil.tt.world.Describer

public class Describer extends Object
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 succeed should be described in third person present tense to the game master and second person present tense to the player.
  • Turns that propose an action should be described in present tense as a character under the control of the proposer trying or offering to do something.
  • Turns the fail should 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 Classes
    Modifier and Type
    Class
    Description
    static enum 
    The names of elements which can be replaced in description templates
    static class 
    A describer rule has two parts: a context that defines when to apply it and a natural language template to use when this rule is applied.
    static class 
    A verb is an object used in the templates of a describer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty describer with no verbs or rules.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a rule to the end of the list of rules that this describer can apply when describing an object.
    void
    Adds a verb to this describer, or replaces an existing verb with the same base, if one exists.
    getPhrase(Object object)
    Applies this describer's rules to generate a natural language description of the given object for a session's game master.
    getPhrase(Object object, Role to)
    Applies this describer's rules to generate a natural language description of the given object for a given role.
    Returns the first rule from this describer that matches a given context.
    Returns an unmodifiable list of all the rules used by this describer, in the order they will be checked to see if they apply.
    Applies this describer's rules to generate a natural language description of the given object for a session's game 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 given base.
    Returns all the verbs used by this describer.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Describer

      public Describer()
      Constructs an empty describer with no verbs or rules.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getVerbs

      public Iterable<Describer.Verb> getVerbs()
      Returns all the verbs used by this describer.
      Returns:
      this describer's verbs
    • getVerb

      public Describer.Verb getVerb(String base)
      Returns the verb with the given base.
      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

      public void add(Describer.Verb verb)
      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

      public Iterable<Describer.Rule> 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

      public Describer.Rule getRule(Map<Describer.Key, Object> context)
      Returns the first rule from this describer that matches a 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

      public void add(Describer.Rule rule)
      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

      public String getPhrase(Object object, Role to)
      Applies this describer's rules to generate a natural language description of the given object for a given role. Each rule is checked in order until one is found that matches the 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 described
      to - the role for whom the description is being generated, and the value that will be assigned to Describer.Key.TO
      Returns:
      a description of the object suitable for the given role
    • getPhrase

      public String getPhrase(Object object)
      Applies this describer's rules to generate a natural language description of the given object for a session's game master.
      Parameters:
      object - the object to be described
      Returns:
      a description of the object
      See Also:
    • getSentence

      public String 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. If the string given is empty, an empty string is returned.
      Parameters:
      object - the object to be described
      to - the role for whom the description is being generated, and the value that will be assigned to Describer.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

      public String getSentence(Object object)
      Applies this describer's rules to generate a natural language description of the given object for a session's game 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: