Class Describer.Rule
java.lang.Object
edu.uky.cs.nil.tt.world.Describer.Rule
- Enclosing class:
Describer
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a new rule identical to this one, except thatDescriber.Key.ACTIONmust have the given value.Returns a new rule identical to this one, except thatDescriber.Key.ENDINGmust have the given value.Returns a new rule identical to this one, except thatDescriber.Key.ENTITYmust have the given value.booleanmatches(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.Returns a new rule identical to this one, except thatDescriber.Key.NAMEmust have the given value.Returns a new rule identical to this one, except thatDescriber.Key.ROLEmust have the given value.Returns a new rule identical to this one, except thatDescriber.Key.TOmust have the given value.toString()Returns a new rule identical to this one, except thatDescriber.Key.TURN_TYPEmust have the given value.Returns a new rule identical to this one, except thatDescriber.Key.TYPEmust have the given value.Returns a new rule identical to this one, except thatDescriber.Key.VALUEmust have the given value.variableIs(Variable variable) Returns a new rule identical to this one, except thatDescriber.Key.VARIABLEmust have the given value.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.Returns a new rule identical to this one, except that itsnatural language templatewill be the given value.
-
Field Details
-
template
The natural language template to be used when this rule is applied
-
-
Constructor Details
-
Rule
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 ruletemplate- a natural language template to use when this rule is applied
-
Rule
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 towrite(String)to set the template.
-
-
Method Details
-
toString
-
matches
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
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 constrainedvalue- the value that key must have for this rule to be applied- Returns:
- a new rule reflecting the updated context
-
typeIs
Returns a new rule identical to this one, except thatDescriber.Key.TYPEmust have the given value. SeeDescriber.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
Returns a new rule identical to this one, except thatDescriber.Key.ROLEmust 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
Returns a new rule identical to this one, except thatDescriber.Key.TURN_TYPEmust 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
Returns a new rule identical to this one, except thatDescriber.Key.ENTITYmust 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
Returns a new rule identical to this one, except thatDescriber.Key.VARIABLEmust 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
Returns a new rule identical to this one, except thatDescriber.Key.ACTIONmust 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
Returns a new rule identical to this one, except thatDescriber.Key.ENDINGmust 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
Returns a new rule identical to this one, except thatDescriber.Key.NAMEmust 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
Returns a new rule identical to this one, except thatDescriber.Key.VALUEmust 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
Returns a new rule identical to this one, except thatDescriber.Key.TOmust 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
Returns a new rule identical to this one, except that itsnatural language templatewill 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
-