Class Describer.Rule

java.lang.Object
edu.uky.cs.nil.tt.world.Describer.Rule
Enclosing class:
Describer

public static class Describer.Rule extends Object
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.

Rules can be constructed directly using Rule(Map, String). Alternatively, they can be constructed without a context using Rule(String) or Rule(), and then the context can be built up by calling a sequence of methods to add to the context, such as when(Key, Object).

Author:
Stephen G. Ware
  • Field Details

    • template

      public final String template
      The natural language template to be used when this rule is applied
  • Constructor Details

    • Rule

      protected Rule(Map<Describer.Key, String> context, String template)
      Constructs a new rule from a context map and a natural language template.
      Parameters:
      context - a map of keys to values which defines when to apply this rule
      template - a natural language template to use when this rule is applied
    • Rule

      public Rule(String template)
      Constructs a new rule with a template and no context. A rule with no context is typically revised by a series of calls to the methods that add to its context.
      Parameters:
      template - a natural language template to use when this rule is applied
    • Rule

      public Rule()
      Constructs a new empty rule with no template and no context. A rule with no context is typically revised by a series of calls to the methods that add to its context and a call to write(String) to set the template.
  • Method Details

    • toString

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

      public boolean matches(Map<Describer.Key, Object> context)
      Tests whether the context of this rule matches the context of the object a describer is currently trying to describe. A rule is applied when the values of all the keys in the rule's context match the values of those keys for the object being described. The rule context does not need to be an exact match to the object's context--only the keys defined in the rule's context are checked. Keys that have values in the object's context but are not defined in the rule's context are not checked and do not prevent a rule from being applied.
      Parameters:
      context - the context of the object being described
      Returns:
      true if all of the keys defined in this rule's context match the values of those keys in the given context
    • when

      public Describer.Rule when(Describer.Key key, Object value)
      Returns a new rule that is identical to this rule, except with the requirement that the given key must have the given value for this rule to be applied by a describer.
      Parameters:
      key - the key whose value will be constrained
      value - the value that key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • typeIs

      public Describer.Rule typeIs(Class<?> type)
      Returns a new rule identical to this one, except that Describer.Key.TYPE must have the given value. See Describer.Key.TYPE.
      Parameters:
      type - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • roleIs

      public Describer.Rule roleIs(Role role)
      Returns a new rule identical to this one, except that Describer.Key.ROLE must have the given value.
      Parameters:
      role - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • turnIs

      public Describer.Rule turnIs(Turn.Type type)
      Returns a new rule identical to this one, except that Describer.Key.TURN_TYPE must have the given value.
      Parameters:
      type - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • entityIs

      public Describer.Rule entityIs(Entity entity)
      Returns a new rule identical to this one, except that Describer.Key.ENTITY must have the given value.
      Parameters:
      entity - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • variableIs

      public Describer.Rule variableIs(Variable variable)
      Returns a new rule identical to this one, except that Describer.Key.VARIABLE must have the given value.
      Parameters:
      variable - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • actionIs

      public Describer.Rule actionIs(Action action)
      Returns a new rule identical to this one, except that Describer.Key.ACTION must have the given value.
      Parameters:
      action - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • endingIs

      public Describer.Rule endingIs(Ending ending)
      Returns a new rule identical to this one, except that Describer.Key.ENDING must have the given value.
      Parameters:
      ending - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • nameIs

      public Describer.Rule nameIs(String name)
      Returns a new rule identical to this one, except that Describer.Key.NAME must have the given value.
      Parameters:
      name - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • valueIs

      public Describer.Rule valueIs(Value value)
      Returns a new rule identical to this one, except that Describer.Key.VALUE must have the given value.
      Parameters:
      value - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • to

      public Describer.Rule to(Role role)
      Returns a new rule identical to this one, except that Describer.Key.TO must have the given value.
      Parameters:
      role - the value the key must have for this rule to be applied
      Returns:
      a new rule reflecting the updated context
    • write

      public Describer.Rule write(String template)
      Returns a new rule identical to this one, except that its natural language template will be the given value.
      Parameters:
      template - the natural language template the new rule will have
      Returns:
      a new rule using the given natural language template