public abstract class NLGElement extends Object
NLGElement is the base class that all elements extend from. This
is abstract and cannot therefore be instantiated itself. The additional
element classes should be used to correctly identify the type of element
required.
Realisation in SimpleNLG revolves around a tree structure. Each node in the
tree is represented by a NLGElement, which in turn may have
child nodes. The job of the processors is to replace various types of
elements with other elements. The eventual goal, once all the processors have
been run, is to produce a single string element representing the final
realisation.
The features are stored in a Map of String (the
feature name) and Object (the value of the feature).
| Modifier and Type | Field and Description |
|---|---|
protected HashMap<String,Object> |
features
The features of this element.
|
| Constructor and Description |
|---|
NLGElement() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearAllFeatures()
Deletes all the features in the map.
|
boolean |
equals(Object o)
An NLG element is equal to some object if the object is an NLGElement,
they have the same category and the same features.
|
boolean |
equals(String elementRealisation)
Determines if this element has its realisation equal to the given string.
|
Set<String> |
getAllFeatureNames()
Retrieves the set of features currently contained in the feature map.
|
Map<String,Object> |
getAllFeatures()
Retrieves the map containing all the features for this element.
|
ElementCategory |
getCategory()
Retrieves the category for this element.
|
abstract List<NLGElement> |
getChildren()
Retrieves the children for this element.
|
NLGFactory |
getFactory() |
Object |
getFeature(String featureName)
Retrieves the value of the feature.
|
Boolean |
getFeatureAsBoolean(String featureName)
Retrieves the value of the feature as a
Boolean. |
Double |
getFeatureAsDouble(String featureName)
Retrieves the value of the feature as a
Double. |
NLGElement |
getFeatureAsElement(String featureName)
Retrieves the value of the feature as a
NLGElement. |
List<NLGElement> |
getFeatureAsElementList(String featureName)
Retrieves the value of the feature as a list of elements.
|
Float |
getFeatureAsFloat(String featureName)
Retrieves the value of the feature as a
Float. |
Integer |
getFeatureAsInteger(String featureName)
Retrieves the value of the feature as an
Integer. |
List<Object> |
getFeatureAsList(String featureName)
Retrieves the value of the feature as a list of java objects.
|
Long |
getFeatureAsLong(String featureName)
Retrieves the value of the feature as a
Long. |
String |
getFeatureAsString(String featureName)
Retrieves the value of the feature as a string.
|
List<String> |
getFeatureAsStringList(String featureName)
Retrieves the value of the feature as a list of strings.
|
NLGElement |
getParent()
Retrieves the parent of this element.
|
String |
getRealisation()
Retrieves the final realisation of this element.
|
Tense |
getTense()
Deprecated.
|
boolean |
hasFeature(String featureName)
Checks the feature map to see if the named feature is present in the map.
|
boolean |
isA(ElementCategory checkCategory) |
boolean |
isNegated()
Deprecated.
|
boolean |
isPlural()
Determines if this element is to be treated as a plural.
|
String |
printTree(String indent) |
void |
removeFeature(String featureName)
Deletes the named feature from the map.
|
void |
setCategory(ElementCategory newCategory)
Sets the category of this element.
|
void |
setFactory(NLGFactory factory) |
void |
setFeature(String featureName,
boolean featureValue)
A convenience method for setting boolean features.
|
void |
setFeature(String featureName,
double featureValue)
A convenience method for setting double precision floating point number
features.
|
void |
setFeature(String featureName,
float featureValue)
A convenience method for setting floating point number features.
|
void |
setFeature(String featureName,
int featureValue)
A convenience method for setting integer features.
|
void |
setFeature(String featureName,
long featureValue)
A convenience method for setting long integer features.
|
void |
setFeature(String featureName,
Object featureValue)
Adds a feature to the feature map.
|
void |
setNegated(boolean isNegated)
Deprecated.
|
void |
setParent(NLGElement newParent)
Sets the parent element of this element.
|
void |
setPlural(boolean isPlural)
Sets the number agreement on this element.
|
void |
setRealisation(String realised)
Sets the realisation of this element.
|
void |
setTense(Tense newTense)
Deprecated.
|
String |
toString() |
public void setCategory(ElementCategory newCategory)
newCategory - the new ElementCategory for this element.public ElementCategory getCategory()
ElementCategory.public void setFeature(String featureName, Object featureValue)
null the
feature is removed from the map.featureName - the name of the feature.featureValue - the new value of the feature or null if the
feature is to be removed.public void setFeature(String featureName, boolean featureValue)
featureName - the name of the feature.featureValue - the boolean value of the feature.public void setFeature(String featureName, int featureValue)
featureName - the name of the feature.featureValue - the int value of the feature.public void setFeature(String featureName, long featureValue)
featureName - the name of the feature.featureValue - the long value of the feature.public void setFeature(String featureName, float featureValue)
featureName - the name of the feature.featureValue - the float value of the feature.public void setFeature(String featureName, double featureValue)
featureName - the name of the feature.featureValue - the double value of the feature.public Object getFeature(String featureName)
featureName - the name of the feature.Object value of the feature.public String getFeatureAsString(String featureName)
null is returned.featureName - the name of the feature.String representation of the value. This is
taken by calling the object's toString() method.public List<NLGElement> getFeatureAsElementList(String featureName)
Retrieves the value of the feature as a list of elements. If the feature
is a single NLGElement then it is wrapped in a list. If the
feature is a Collection then each object in the collection
is checked and only NLGElements are returned in the list.
If the feature does not exist then an empty list is returned.
featureName - the name of the feature.List of NLGElementspublic List<Object> getFeatureAsList(String featureName)
Retrieves the value of the feature as a list of java objects. If the feature
is a single element, the list contains only this element.
If the feature is a Collection each object in the collection is
returned in the list.
If the feature does not exist then an empty list is returned.
featureName - the name of the feature.List of Objectspublic List<String> getFeatureAsStringList(String featureName)
Retrieves the value of the feature as a list of strings. If the feature
is a single element, then its toString() value is wrapped in
a list. If the feature is a Collection then the
toString() value of each object in the collection is
returned in the list.
If the feature does not exist then an empty list is returned.
featureName - the name of the feature.List of Stringspublic Integer getFeatureAsInteger(String featureName)
Integer. If the
feature does not exist or cannot be converted to an integer then
null is returned.featureName - the name of the feature.Integer representation of the value. Numbers are
converted to integers while Strings are parsed for integer
values. Any other type will return null.public Long getFeatureAsLong(String featureName)
Long. If the feature
does not exist or cannot be converted to a long then null is
returned.featureName - the name of the feature.Long representation of the value. Numbers are
converted to longs while Strings are parsed for long values. Any
other type will return null.public Float getFeatureAsFloat(String featureName)
Float. If the
feature does not exist or cannot be converted to a float then
null is returned.featureName - the name of the feature.Float representation of the value. Numbers are
converted to floats while Strings are parsed for float values.
Any other type will return null.public Double getFeatureAsDouble(String featureName)
Double. If the
feature does not exist or cannot be converted to a double then
null is returned.featureName - the name of the feature.Double representation of the value. Numbers are
converted to doubles while Strings are parsed for double values.
Any other type will return null.public Boolean getFeatureAsBoolean(String featureName)
Boolean. If the
feature does not exist or is not a boolean then
Boolean.FALSE is returned.featureName - the name of the feature.Boolean representation of the value. Any
non-Boolean type will return Boolean.FALSE.public NLGElement getFeatureAsElement(String featureName)
NLGElement. If the
value is a string then it is wrapped in a StringElement. If
the feature does not exist or is of any other type then null
is returned.featureName - the name of the feature.NLGElement.public Map<String,Object> getAllFeatures()
Map of String, Object.public boolean hasFeature(String featureName)
featureName - the name of the feature to look for.true if the feature exists, false
otherwise.public void removeFeature(String featureName)
featureName - the name of the feature to be removed.public void clearAllFeatures()
public void setParent(NLGElement newParent)
newParent - the NLGElement that is the parent of this
element.public NLGElement getParent()
NLGElement that is the parent of this element.public void setRealisation(String realised)
realised - the String representing the final realisation for
this element.public String getRealisation()
String representing the final realisation for
this element.public boolean isA(ElementCategory checkCategory)
public abstract List<NLGElement> getChildren()
List of NLGElements representing the
children of this element.public Set<String> getAllFeatureNames()
Set of Strings representing the
feature names. The set is unordered.public boolean equals(String elementRealisation)
elementRealisation - the string to check against.true if the string matches the element's
realisation, false otherwise.public void setPlural(boolean isPlural)
setFeature(Feature.NUMBER, NumberAgreement.PLURAL) for plurals or
setFeature(Feature.NUMBER, NumberAgreement.SINGULAR) for the
singular.isPlural - true if this element is to be treated as a
plural, false otherwise.public boolean isPlural()
true if the Feature.NUMBER feature has
the value NumberAgreement.PLURAL, false
otherwise.@Deprecated public Tense getTense()
getFeature(Feature.TENSE) and casting the result as
Tense.
*
WARNING: You should use getFeature(Feature.TENSE)
getTense will be dropped from simplenlg at some pointTense of this element.@Deprecated public void setTense(Tense newTense)
setFeature(Feature.TENSE, newTense).
WARNING: You should use setTense(Feature.TENSE, tense) setTense will be dropped from simplenlg at some point
newTense - the new tense for this element.@Deprecated public void setNegated(boolean isNegated)
setFeature(Feature.NEGATED, isNegated).
WARNING: You should use setFeature(Feature.NEGATED, isNegated) setNegated will be dropped from simplenlg at some point
isNegated - true if the element is to be negated,
false otherwise.@Deprecated public boolean isNegated()
WARNING: You should use getFeature(Feature.NEGATED) getNegated will be dropped from simplenlg at some point
true if the Feature.NEGATED feature
exists and has the value Boolean.TRUE,
false is returned otherwise.public NLGFactory getFactory()
public void setFactory(NLGFactory factory)
factory - the NLG factory to setCopyright © 2020. All Rights Reserved.