public interface IlrDTModel extends DTModel, IlrDTContext, ilog.rules.dt.model.IlrDTProperties
IlrDTModel defines a decision table or a decision tree model.
This interface provides the API to do the following for the decision table or decision tree model:
The DT model is a hierarchical structure where a path represents a conjunction of conditions, and the leaf node represents a set of actions to be executed if the conjunction of conditions is satisfied.
The following example shows how to populate a decision tree model. Note that an empty decision tree is not really empty. It contains a partition, a partition item, an action set and an empty action.
// create a DT Controller from a DTRuleElement and a DTEnvironment.
// DTRuleElement provides the name, the locale and other properties of the DT element to which this controller is
// associated.
// DTEnvironment provides access to the environment in which this controller is used. This environment includes
// the vocabulary, the BRL parser, the Variable Provider etc... used to interpret this DT.
// The empty model created here contains a root partition with an attached partition definition, a partition item and an action set with an empty action.
IlrDTController dtController = IlrDTHelper.createDTController(dtRuleElement, dtEnvironment);
IlrDTModel dtModel = dtController.getDTModel();
IlrDTExpressionManager expressionManager = dtModel.getExpressionManager();
// set a precondition
IlrDTHelper.setPreconditionsText(dtModel, "definitions set 'my customer' to a customer;");
IlrDTPartition rootPartition = dtModel.getRoot();
// create the expression definition to be assigned to the Condition Definition of the root partition
IlrDTExpressionDefinition rootPartitionExpression = expressionManager.newExpressionDefinition("the age of 'my customer' is between <a number> and <a number>");
// assign the created expression to the Condition Definition of the root partition
dtModel.setDefinitionExpression(rootPartition.getPartitionDefinition(), rootPartitionExpression);
// set a Title to the Condition Definition of the root partition
IlrDTPropertyHelper.setDefinitionTitle(rootPartition.getPartitionDefinition(), "Customer age");
// the root node of an empty tree contains at least a partition item
IlrDTPartitionItem rootCondition = rootPartition.getPartitionItem(0);
// create the expression instance to be assigned to the 1st Condition of the root partition
ArrayList parameters = new ArrayList();
parameters.add("20");
parameters.add("30");
IlrDTExpressionInstance conditionExpression = expressionManager.newExpressionInstance(rootPartitionExpression, parameters);
// assign the newly created expression to the root condition
dtModel.setExpression(rootCondition, conditionExpression);
// create an expression instance to be assigned to the 2nd Condition of the root partition. Note that this expression overrides
// the expression definition of the column with a new predicate.
parameters.clear();
parameters.add("30");
IlrDTExpressionInstance overriddenConditionExpression = expressionManager.newOverriddenExpressionInstance("<a number> is more than <a number>", parameters, rootPartitionExpression);
// create a new Condition in the root partition and assign it the overriding expression instance.
IlrDTPartitionItem rootCondition2 = dtModel.addPartitionItem(rootPartition, rootPartition.getPartitionItemCount(), overriddenConditionExpression);
// create a second column: category
IlrDTExpressionDefinition categoryExpressionDefinition = expressionManager.newExpressionDefinition("the category of 'my customer' is <an object>");
IlrDTPartitionDefinition categoryConditionDefinition = dtModel.newPartitionDefinition(categoryExpressionDefinition);
IlrDTPropertyHelper.setDefinitionTitle(categoryConditionDefinition, "Customer category");
dtModel.addPartitionDefinition(dtModel.indexOfPartitionDefinition(rootPartition.getPartitionDefinition()) + 1, categoryConditionDefinition);
// we create the partition with a partition item with a new expression
parameters.clear();
parameters.add("Silver");
IlrDTExpressionInstance categoryExpression = expressionManager.newExpressionInstance(categoryExpressionDefinition, parameters);
IlrDTPartition categoryPartition = dtModel.addPartition(rootCondition, categoryExpression);
// this partition have 1 (default) partition item and the following node is by default an actionSet
IlrDTActionSet actionSet = (IlrDTActionSet) categoryPartition.getPartitionItem(0).getStatement();
// we get the default action and its related definition
IlrDTAction action = actionSet.getSetAction(0);
IlrDTActionDefinition actionDefinition = action.getActionDefinition();
// assign a new Expression Definition to the Action column with no default values
IlrDTExpressionDefinition setDiscountExpression = expressionManager.newExpressionDefinition("set the discount of the shopping cart of 'my customer' to <a percentage>", null);
dtModel.setDefinitionExpression(actionDefinition, setDiscountExpression);
// set a Title to the 1st Action Definition
IlrDTPropertyHelper.setDefinitionTitle(actionDefinition, "Discount");
// assign a value to the action
parameters.clear();
parameters.add("3 %");
IlrDTExpressionInstance discountActionExpression = expressionManager.newExpressionInstance(setDiscountExpression, parameters);
dtModel.setExpression(action, discountActionExpression);
// we create a new action definition, and we add it to the model
IlrDTActionDefinition otherActionDefinition = dtModel.newActionDefinition(expressionManager.newExpressionDefinition("set the message of the shopping cart of 'my customer' to <a string>"));
// set a Title to the 2nd Action Definition
IlrDTPropertyHelper.setDefinitionTitle(otherActionDefinition, "Message");
// add it to the DT Model
dtModel.addActionDefinition(dtModel.getActionDefinitionCount(), otherActionDefinition);
// create a new action expression
parameters.clear();
parameters.add("\"Thank you!\"");
IlrDTExpressionInstance messageActionExpression = expressionManager.newExpressionInstance(otherActionDefinition.getExpressionDefinition(), parameters);
// add a new action
dtModel.addAction(actionSet, actionSet.getSetActionCount(), otherActionDefinition, messageActionExpression);
Note that this interface and all interfaces related to the DT model are
not supposed to be implemented outside the DT framework.
INSTANCE, TRANSIENT, VOLATILE| Modifier and Type | Method and Description |
|---|---|
IlrDTAction |
addAction(IlrDTActionSet actionSet,
int index,
IlrDTActionDefinition definition,
IlrDTExpression expression)
Creates and adds an action in
actionSet at position index,
related to action definition definition, with expression expression. |
void |
addActionDefinition(int index,
IlrDTActionDefinition definition)
Adds a new action definition at the position index.
|
void |
addDTModelListener(DTModelListener l)
Adds a structure/content listener to the
IlrDTModel. |
void |
addDTModelPropertyChangeListener(DTModelPropertyChangeListener l)
Adds a property listener to the
IlrDTModel. |
IlrDTPartition |
addPartition(IlrDTPartitionItem item,
IlrDTExpression expression)
Inserts after the item a partition related to the definition containing a single empty item.
|
IlrDTPartition |
addPartition(IlrDTPartitionItem item,
IlrDTPartitionDefinition definition,
IlrDTExpression expression)
Inserts after the item a partition related to the definition with a single item containing
the expression.
|
void |
addPartitionDefinition(int index,
IlrDTPartitionDefinition definition)
Adds a new partition definition at the position index.
|
IlrDTPartitionItem |
addPartitionItem(IlrDTPartition partition,
int index,
IlrDTExpression expression)
Inserts an item in the partition with a given expression at the position index.
|
void |
clear()
Removes all definitions, actions, partitions, and items.
|
void |
clearContent()
Removes all partitions and items.
|
java.lang.Object |
clone()
Creates and returns a copy of this
IlrDTModel. |
void |
fireActionChanged(IlrDTAction action)
Notifies listeners that parameters of an action in the action set have been modified.
|
void |
fireActionDefinitionChanged(IlrDTActionDefinition definition)
Notifies listeners that the action definition has been modified.
|
void |
fireActionSetChanged(IlrDTActionSet actionSet)
Notifies listeners that an action set has been modified.
|
void |
fireActionSetChanged(int firstIndex,
int lastIndex)
Notifies listeners that a set of action sets from
firstIndex
to lastIndex have been modified. |
void |
fireDTModelChanged()
Notifies listeners that the model or its environment has changed and the model has to be
fully reinterpreted.
|
void |
fireObjectPropertyChanged(IlrDTModelElement element,
java.lang.Object property,
java.lang.Object oldValue,
java.lang.Object newValue)
Notifies listeners that a property of an element of the
IlrDTModel has been modified. |
void |
firePartitionChanged(IlrDTPartition partition)
Notifies listeners that the partition has changed.
|
void |
firePartitionDefinitionChanged(IlrDTPartitionDefinition definition)
Notifies listeners that the partition definition has been modified.
|
void |
firePartitionItemChanged(IlrDTPartitionItem item)
Notifies listeners that the partition item has been modified.
|
void |
firePropertyChanged(java.lang.Object property,
java.lang.Object oldValue,
java.lang.Object newValue)
Notifies listeners that a property of the
IlrDTModel has been modified. |
IlrDTActionDefinition |
getActionDefinition(int index)
Returns the action definition at the position index.
|
int |
getActionDefinitionCount()
Returns the cardinality of the action definitions list.
|
IlrDTActionSet |
getActionSet(int index)
Returns the action set at the position index.
|
int |
getActionSetCount()
Returns the cardinality of the action sets in the hierarchical structure.
|
java.util.List |
getActionSets()
Returns the list of action sets handled by this model.
|
IlrDTPartitionDefinition |
getPartitionDefinition(int index) |
int |
getPartitionDefinitionCount()
Returns the cardinality of the Partition Definitions list.
|
IlrDTPartition |
getRoot()
Returns the root partition.
|
int |
indexOfActionDefinition(IlrDTActionDefinition definition)
Returns the index of the action definition in the
IlrDTModel. |
int |
indexOfActionSet(IlrDTActionSet actionSet)
Returns the index of the action set in the
DTModel. |
int |
indexOfPartitionDefinition(IlrDTPartitionDefinition definition) |
boolean |
isActionAddedAutomatically()
Returns
true if actions are automatically added and ordered according to action definitions. |
boolean |
isAdjusting()
Returns the last value passed to
setAdjusting(boolean). |
IlrDTActionDefinition |
newActionDefinition(IlrDTExpressionDefinition expression)
Creates a new Action Definition.
|
IlrDTActionDefinition |
newActionDefinition(java.lang.String name,
IlrDTExpression expression)
Deprecated.
: replaced by newActionDefinition(expression)
|
IlrDTPartitionDefinition |
newPartitionDefinition(IlrDTExpressionDefinition expression)
Creates a new partition definition.
|
IlrDTPartitionDefinition |
newPartitionDefinition(java.lang.String name,
IlrDTExpression expression)
Deprecated.
: replaced by newPartitionDefinition(expression)
|
boolean |
removeAction(IlrDTAction action)
Removes an action of the
IlrDTModel. |
boolean |
removeActionDefinition(IlrDTActionDefinition definition)
Removes an action definition from the action definition list and all corresponding actions from all action sets.
|
boolean |
removeActionSet(IlrDTActionSet actionSet)
Removes the action set and the corresponding path of partition items and partition.
|
void |
removeDTModelListener(DTModelListener l)
Removes a structure/content listener from the
IlrDTModel. |
void |
removeDTModelPropertyChangeListener(DTModelPropertyChangeListener l)
Removes a property listener from the
IlrDTModel. |
boolean |
removePartition(IlrDTPartition partition)
Removes the partition and all its children, then replaces it with an empty action set.
|
boolean |
removePartitionDefinition(IlrDTPartitionDefinition definition)
Removes a partition definition and all related partitions.
|
boolean |
removePartitionItem(IlrDTPartitionItem item)
Removes the partition item and the underlying branch.
|
void |
reset()
Reinitializes all caches attached to the model.
|
boolean |
setAdjusting(boolean adjusting)
Notifies the
IlrDTModel that subsequent calls to
the editing methods should be treated as a single modification. |
void |
setDefinitionExpression(IlrDTDefinition definition,
IlrDTExpression expression)
Assigns the given expression to the given definition, and possibly to
the partition items or actions related to the definition.
|
void |
setExpression(IlrDTExpressionInstanceHandler expressionHandler,
IlrDTExpressionInstance expression)
Assigns the given expression to the given Expression Handler (a condition or an action,
It also generates appropriate events.
|
boolean |
setPartitionDefinition(IlrDTPartition partition,
IlrDTPartitionDefinition newDefinition)
Changes the definition of a partition.
|
void |
setPreconditionText(java.lang.String text)
This method set the preconditions of this model.
|
boolean |
shrinkPartition(IlrDTPartition partition)
Removes the partition and connects its parent item to the next statement of its only child item.
|
void |
sortPartition(IlrDTPartition partition,
boolean direct)
Sorts the partition items of the given partition.
|
void |
sortPartitions(IlrDTPartitionDefinition definition,
boolean direct)
Sorts all partitions of the given partition definition.
|
boolean |
swapActionDefinitions(IlrDTActionDefinition from,
IlrDTActionDefinition to)
Swaps two action definitions in the action definitions list and indirectly corresponding actions in all action sets.
|
boolean |
swapActions(IlrDTAction from,
IlrDTAction to)
Swaps the position of two actions within the same action set.
|
boolean |
swapPartitionItems(IlrDTPartitionItem from,
IlrDTPartitionItem to)
Swaps the position of two partition items from the same partition.
|
getActionDefinitionList, getActionSetList, getConditionDefinitionList, getDefinition, getPreconditionText, getRootPartitiongetDTEnvironment, getDTRuleElement, getExpressionManager, getVocabularyaddProperties, clearProperties, clearVolatileProperties, getProperties, getProperty, setPropertygetTimeStamp, setTimeStampjava.lang.Object clone()
throws java.lang.CloneNotSupportedException
IlrDTModel.
Note that listeners and IlrDecorableElement.INSTANCE properties are not cloned.
clone in interface IlrDecorableElementjava.lang.CloneNotSupportedExceptionIlrDecorableElement.INSTANCE are not copied.void addDTModelListener(DTModelListener l)
IlrDTModel.
This listener will be notified after notification of all previous registred listeners.l - The listener to be added.void removeDTModelListener(DTModelListener l)
IlrDTModel.l - The listener to be removed.void addDTModelPropertyChangeListener(DTModelPropertyChangeListener l)
IlrDTModel.
This listener will be notified after notification of all previous registred listeners.l - the listener to be addedvoid removeDTModelPropertyChangeListener(DTModelPropertyChangeListener l)
IlrDTModel.l - The listener to be removed.boolean isAdjusting()
setAdjusting(boolean).setAdjusting(boolean).boolean setAdjusting(boolean adjusting)
IlrDTModel that subsequent calls to
the editing methods should be treated as a single modification.adjusting - The flag value.void clear()
void clearContent()
void setPreconditionText(java.lang.String text)
text - the precondition textIlrDTPartitionDefinition newPartitionDefinition(java.lang.String name, IlrDTExpression expression)
name - The name of the Partition Definition to create.expression - The expression assigned to this definition.IlrDTPartitionDefinition newPartitionDefinition(IlrDTExpressionDefinition expression)
expression - The expression assigned to this definition. Can be null.void addPartitionDefinition(int index,
IlrDTPartitionDefinition definition)
index - The position of insertion.definition - The new definition.boolean removePartitionDefinition(IlrDTPartitionDefinition definition)
definition - The definition to be removed.true if removal was successful.IlrDTPartitionDefinition getPartitionDefinition(int index)
index - The index of the required partition definition.int indexOfPartitionDefinition(IlrDTPartitionDefinition definition)
definition - The definition whose index is looked up.IlrDTModel, -1 otherwise.int getPartitionDefinitionCount()
void setDefinitionExpression(IlrDTDefinition definition, IlrDTExpression expression)
definition - The definition to be assigned.expression - The expression to assign.void setExpression(IlrDTExpressionInstanceHandler expressionHandler, IlrDTExpressionInstance expression)
expressionHandler - The condition or action to be assigned.expression - The expression to assign.void firePartitionDefinitionChanged(IlrDTPartitionDefinition definition)
definition - The modified partition definition.IlrDTPartition getRoot()
void sortPartitions(IlrDTPartitionDefinition definition, boolean direct)
definition - The definition whose partitions must be sorted.direct - If true, sorts partitions in the direct order. If
false, sorts them in reverse order.void sortPartition(IlrDTPartition partition, boolean direct)
partition - The partition whose partition items must be sorted.direct - If true, sorts items in the direct order. If
false, sorts them in reverse order.IlrDTPartition addPartition(IlrDTPartitionItem item, IlrDTExpression expression)
item is null, this method inserts the partition as root.item - The parent item.expression - The expression used to create the item under the partition.IlrDTPartition addPartition(IlrDTPartitionItem item, IlrDTPartitionDefinition definition, IlrDTExpression expression)
item is null, this method inserts the partition as root.
Note that no check is made to see if the created partition is attached to the wrong definition. On a path of the model, the order of the partitions must follow the order of the definitions.
item - The parent item.definition - The related definition.expression - The expression used to create the item under the partition.boolean removePartition(IlrDTPartition partition)
partition - The partition to be removed.boolean shrinkPartition(IlrDTPartition partition)
false is returned.partition - The partition to be shrunk.boolean setPartitionDefinition(IlrDTPartition partition, IlrDTPartitionDefinition newDefinition)
partition - The partition whose definition has to be changed.newDefinition - The new definition.true if the change was successful, or false if the order of the partitions would not follow the order of
the partition definitions after the change.void firePartitionChanged(IlrDTPartition partition)
partition - The partition that changed.IlrDTPartitionItem addPartitionItem(IlrDTPartition partition, int index, IlrDTExpression expression)
partition - The parent partition.index - The position of insertion.expression - The expression attached to the partition item.boolean removePartitionItem(IlrDTPartitionItem item)
item - The partition item to be removed.true if removal was successful.boolean swapPartitionItems(IlrDTPartitionItem from, IlrDTPartitionItem to)
from - The source item.to - The target item.true if swapping was successful.void firePartitionItemChanged(IlrDTPartitionItem item)
item - The modified partition item.IlrDTActionDefinition newActionDefinition(java.lang.String name, IlrDTExpression expression)
name - The name of the new Action Definition.expression - The expression of the new Action Definition.IlrDTActionDefinition newActionDefinition(IlrDTExpressionDefinition expression)
expression - The expression definition of the new Action Definition.void addActionDefinition(int index,
IlrDTActionDefinition definition)
index - The position of insertion.definition - The new action definition.boolean removeActionDefinition(IlrDTActionDefinition definition)
definition - The action definition to be removed.true if removal was successful.boolean swapActionDefinitions(IlrDTActionDefinition from, IlrDTActionDefinition to)
isActionAddedAutomatically()
is true.from - The source action.to - The target action.true if swapping was successful.IlrDTActionDefinition getActionDefinition(int index)
index - The position of the required action definition.int indexOfActionDefinition(IlrDTActionDefinition definition)
IlrDTModel.definition - The action definition whose index is looked up.IlrDTModel.int getActionDefinitionCount()
void fireActionDefinitionChanged(IlrDTActionDefinition definition)
definition - The modified action definition.java.util.List getActionSets()
null and must not be modified.IlrDTActionSet getActionSet(int index)
index - The position of the action set in the hierarchical structure.int indexOfActionSet(IlrDTActionSet actionSet)
DTModel.int getActionSetCount()
boolean removeActionSet(IlrDTActionSet actionSet)
actionSet - The action set to be removed.true if removal was successful.void fireActionSetChanged(IlrDTActionSet actionSet)
actionSet - The modified action set.void fireActionSetChanged(int firstIndex,
int lastIndex)
firstIndex
to lastIndex have been modified.firstIndex - The index of the first modified action set.lastIndex - The index of the last modified action set.IlrDTAction addAction(IlrDTActionSet actionSet, int index, IlrDTActionDefinition definition, IlrDTExpression expression)
actionSet at position index,
related to action definition definition, with expression expression.
Note that if all parameters are null, a specific null action is created.
actionSet - The action set containing the created action.index - The position of the created action in the action set.definition - The definition referred to by the action.expression - The expression of the action.boolean removeAction(IlrDTAction action)
IlrDTModel.
Note that if isActionAddedAutomatically() is true, the action is not removed, but
its expression is cleared.action - The action to be removed/cleared.true if the operation is successful.boolean swapActions(IlrDTAction from, IlrDTAction to)
isActionAddedAutomatically() is true,
the swapping fails.from - The first action to be swapped.to - The second action to be swapped.true if the operation is successful.void fireActionChanged(IlrDTAction action)
action - The modified action.void fireDTModelChanged()
reset() of the IlrDTModelvoid firePropertyChanged(java.lang.Object property,
java.lang.Object oldValue,
java.lang.Object newValue)
IlrDTModel has been modified.property - The property of the IlrDTModel that was modified.oldValue - The value of the property before the modification.newValue - The value of the property after the modification.void fireObjectPropertyChanged(IlrDTModelElement element, java.lang.Object property, java.lang.Object oldValue, java.lang.Object newValue)
IlrDTModel has been modified.property - The property of the element of the IlrDTModel that was modified.oldValue - The value of the property before the modification.newValue - The value of the property after the modification.boolean isActionAddedAutomatically()
true if actions are automatically added and ordered according to action definitions.
Generally false in the case of a table graphic representation, and true in the case of a tree
graphic representation.true if actions are automatically added and ordered according to action definitions.void reset()
IlrDTModel changes and needs to be fully reinterpretted.reset in interface IlrDTContext© Copyright IBM Corp. 1987, 2017