public class IlrDTExpressionManager
extends java.lang.Object
implements java.io.Serializable
IlrDTExpressionManager is a companion class to the DT
controller, it is used to manipulate DT model expressions.
ExpressionHelper class also provides
helper methods for DT expression manipulation.
There are two kinds of expression in the DT functionality:
ExpressionDefinition -
used with DT definitions. They specify the expressions that define a DT
column or a condition node. An expression definition has one or more
placeholders and serves as a template for condition and action expressions.
ExpressionInstance -
used for condition and action expressions. An ExpressionInstance
is an ExpressionDefinition instance. It provides parameters
for the definition placeholders.
ExpressionInstance objects are used with DT conditions or
actions that are represented as cells in a decision table or as a condition
link in a decision tree.
An ExpressionInstance instance references an
ExpressionDefinition object. This ExpressionDefinition
is the template for the ExpressionInstance. It provides one
parameter for each definition placeholder.
Expressions can be syntactically invalid. They are parsed against the DT environment associated with this expression manager. Syntactic or semantic errors are collected in an error manager.
The following code example shows how to build the decision table structure and load data in Rule Team Server.
public IlrDTController buildDecisionTable(IlrDecisionTable dt, IlrDTDataProvider provider) throws IlrObjectNotFoundException, IlrInvalidElementException, IlrKnownUUIDException, IlrObjectLockedException, IlrFolderLockedException, IlrPermissionException {
// use the locale of display in Rule Team Server
IlrDTController controller = IlrSessionHelper.getDTController(session, dt, Locale.ENGLISH);
IlrDTModel dtModel = controller.getDTModel();
lrDTExpressionManager expressionManager = dtModel.getExpressionManager();
dtModel.clear();
// Example of how to add a precondition to the decision table. Not used in the sample.
// IlrDTHelper.setPreconditionsText(dtModel, "definitions set 'the spouse' to the spouse of 'the borrower' ; if the age of 'the spouse' is ... ");
IlrDTPartition rootPartition = dtModel.getRoot();
// Add a condition
IlrDTExpressionDefinition ageExpressionDefinition = expressionManager.newExpressionDefinition("the age of 'the borrower' is between <a number> and <a number>", null);
IlrDTPartitionDefinition agePartitionDefinition = dtModel.newPartitionDefinition(ageExpressionDefinition) ;
IlrDTPropertyHelper.setDefinitionTitle(agePartitionDefinition, "Borrower age");
dtModel.addPartitionDefinition(0, agePartitionDefinition);
// Add another condition
IlrDTExpressionDefinition zipExpressionDefinition = expressionManager.newExpressionDefinition("the zip code of the address of 'the borrower' is <an object>", null);
IlrDTPartitionDefinition zipConditionDefinition = dtModel.newPartitionDefinition(zipExpressionDefinition);
IlrDTPropertyHelper.setDefinitionTitle(zipConditionDefinition, "Zip Code");
dtModel.addPartitionDefinition(dtModel.getPartitionDefinitionCount(), zipConditionDefinition);
// Add an action
IlrDTExpressionDefinition setInsuranceExpressionDefinition = expressionManager.newExpressionDefinition("set insurance required in 'the loan report' to <a boolean>");
IlrDTActionDefinition setInsuranceActionDefinition = dtModel.newActionDefinition(setInsuranceExpressionDefinition);
IlrDTPropertyHelper.setDefinitionTitle(setInsuranceActionDefinition, "Set Insurance");
dtModel.addActionDefinition(dtModel.getActionDefinitionCount(), setInsuranceActionDefinition);
// Add another action
IlrDTExpressionDefinition addMessageExpressionDefinition = expressionManager.newExpressionDefinition("in 'the loan report' , add the message <a string>");
IlrDTActionDefinition addMessageActionDefinition = dtModel.newActionDefinition(addMessageExpressionDefinition);
IlrDTPropertyHelper.setDefinitionTitle(addMessageActionDefinition, "Add Message");
dtModel.addActionDefinition(dtModel.getActionDefinitionCount(), addMessageActionDefinition);
// Load its data
controller.populate(provider);
return controller;
}
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CACHE_PREDICTIONS
To disable the prediction cache, set this property to a DT Model.
|
static java.lang.String |
EXPRESSION_OPTIMIZED_KEEP_AST_NOT_OPTIMIZABLE
Allows to retain or to recreate ASTs for expressions that cannot be optimized (unparseable values,
complex expressions and the like), useful only if memory optimization is turned on.
|
static java.lang.String |
EXPRESSION_OPTIMIZED_MEMORY
To enable expression optimized memory, set this property to a DT Model.
|
static java.lang.String |
EXPRESSION_OPTIMIZED_PARSING
To disable expression optimized parsing, set this property to a DT Model.
|
| Constructor and Description |
|---|
IlrDTExpressionManager(IlrDTContext dtContext)
Creates an expression manager dedicated to the dtContext.
|
IlrDTExpressionManager(IlrDTContext dtContext,
java.lang.String preconditionText)
Creates an expression manager dedicated to the
dtContext. |
| Modifier and Type | Method and Description |
|---|---|
IlrDTSentenceContext |
getAssignSentenceContext()
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
java.util.Set |
getCategoryFilter()
Returns the category filter associated with the DT model.
|
IlrDTSentenceContext |
getDoesNotEqualsSentenceContext()
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
IlrDTContext |
getDTContext()
Returns the dt context attached to the expression manager.
|
IlrDTSentenceContext |
getEqualsSentenceContext()
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
IlrDTSentenceContext |
getIsNotOneOfSentenceContext()
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
IlrDTSentenceContext |
getIsOneOfSentenceContext()
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
IlrDTSentenceContext |
getNumberDoesNotEqualsSentenceContext()
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
IlrDTSentenceContext |
getNumberEqualsSentenceContext()
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
IlrDTExpressionInstance |
getOtherwiseExpression()
Returns the expression instance that represent an otherwise in a partition.
|
IlrSyntaxTree |
getPreconditionsTree()
Returns the syntax tree corresponding to the interpretation of the DT
preconditions.
|
IlrDTSentenceContext |
getSentenceContext(java.lang.String textSentence,
int sentenceType)
Deprecated.
use an appropriate IlrDTExpressionDefinition
|
IlrBRLMutableParserInput |
initActionParserInput(java.lang.String text,
IlrBRLMutableParserInput input)
Initializes a parser input so that it can be used to parse the text of an
action expression.
|
IlrBRLMutableParserInput |
initConditionParserInput(java.lang.String text,
IlrBRLMutableParserInput input)
Initializes a parser input so that can be used to parse the text of a
condition expression.
|
IlrBRLMutableParserConfiguration |
initExpressionParserConfiguration(IlrDTExpression expr,
IlrBRLMutableParserConfiguration config)
Initializes a parser configuration so it can be used to parse the text of a
condition or an action expression.
|
IlrBRLMutableParserConfiguration |
initPreconditionParserConfiguration(IlrBRLMutableParserConfiguration config)
Creates or initializes a parser configuration designed to parse a
precondition.
|
IlrBRLMutableParserInput |
initPreconditionParserInput(java.lang.String text,
IlrBRLMutableParserInput input)
Creates or initializes a parser input designed to parse the precondition
text parameter.
|
IlrBRLMutableParserConfiguration |
initValueParserConfiguration(IlrDTExpression expr,
IlrConcept type,
IlrBRLMutableParserConfiguration config)
Initializes or creates a parser configuration setup that is used to
parse the value of a given type.
|
IlrBRLMutableParserInput |
initValueParserInput(java.lang.String text,
IlrCardinality cardinality,
IlrBRLMutableParserInput input)
Initializes or creates a parser input that is used to parse the value
represented by a text string with a specific cardinality.
|
IlrBRLMutablePredictionConfiguration |
initValuePredictionConfiguration(IlrDTExpressionParameter param,
boolean valuesOnly,
IlrBRLMutablePredictionConfiguration config)
Initializes or creates a prediction configuration that is set to
predict possible values for a given expression parameter.
|
boolean |
isOtherwiseExpression(IlrDTExpression e)
Tests if a given expression is an otherwise expression.
|
IlrDTExpressionSentence |
newActionExpressionSentence(java.lang.String text)
Deprecated.
use newExpressionDefinition() or newExpressionInstance() API.
|
IlrDTExpressionSentence |
newConditionExpressionSentence(java.lang.String text)
Deprecated.
use newExpressionDefinition() or newExpressionInstance() API.
|
ExpressionDefinition |
newExpressionDefinition(java.lang.String expressionText)
Creates an expression definition.
|
ExpressionDefinition |
newExpressionDefinition(java.lang.String expressionText,
java.util.List<java.lang.String> defaultValues)
Creates a new expression definition.
|
IlrDTExpressionElse |
newExpressionElse()
Deprecated.
use getOtherwiseExpression()
|
ExpressionInstance |
newExpressionInstance(IlrDTExpressionDefinition definition)
Creates an expression instance from a given expression definition.
|
ExpressionInstance |
newExpressionInstance(IlrDTExpressionDefinition definition,
java.util.List<java.lang.String> params)
Creates an expression instance from a given expression definition.
|
protected IlrDTExpressionSentence |
newExpressionSentence(int sentenceType,
java.lang.String text)
Deprecated.
use newExpressionDefinition() or newExpressionInstance() API.
|
IlrDTExpressionSentence |
newExpressionSentence(java.lang.String holderRoleText,
IlrDTSentenceContext sentenceContext)
Deprecated.
use newExpressionDefinition() or newExpressionInstance() API.
|
IlrDTExpressionInstance |
newOverriddenExpressionInstance(java.lang.String overriddenText,
java.util.List<java.lang.String> parameters,
IlrDTExpressionDefinition referenceDefinition)
Creates a new expression instance that overrides the expression definition
passed as argument.
|
IlrSyntaxTree |
parse(IlrDTExpressionText expression,
IlrDTErrorManager errorManager)
Parses an expression and reports errors to a
DTErrorManager instance. |
IlrSyntaxTree |
parse(java.lang.String text,
IlrDTErrorManager errorManager,
IlrDTExpression expressionContext)
Parses a given text string and reports errors to a
DTErrorManager instance. |
java.lang.Object |
parseValue(java.lang.String text,
IlrConcept concept)
Deprecated.
use BRL API to parse values
|
java.util.Set |
predictParameter(IlrDTExpressionParameter param,
boolean valuesOnly)
Predicts the content of a given expression instance.
|
java.lang.String |
unparseValue(java.lang.Object value,
IlrConcept concept)
Deprecated.
use BRL API to create text representation of values.
|
boolean |
usePredictionCache()
Checks if the prediction cache is enabled for this expression
manager.
|
void |
usePredictionCache(boolean flag)
Enables or disables the prediction cache for the current expression manager.
|
public static final java.lang.String CACHE_PREDICTIONS
true, the prediction cache is enabled.public static final java.lang.String EXPRESSION_OPTIMIZED_PARSING
true, expression optimized parsing is enabled.public static final java.lang.String EXPRESSION_OPTIMIZED_KEEP_AST_NOT_OPTIMIZABLE
true, ASTs will be kept for expressions that cannot be optimized. This way,
those expressions will only be parsed once (more heap, less CPU).
When false, ASTs will not be kept, and will not retain heap space. On the other hand,
the expression will be parsed again each time it is needed (less heap, more CPU).
Defaults to false : ASTs for non optimizable expressions are garbaged.public static final java.lang.String EXPRESSION_OPTIMIZED_MEMORY
false, expression optimized memory is disabled.public IlrDTExpressionManager(IlrDTContext dtContext, java.lang.String preconditionText)
dtContext.dtContext - A DT Context.preconditionText - The precondition text if necessary.public IlrDTExpressionManager(IlrDTContext dtContext)
dtContext - a DT Contextpublic IlrDTContext getDTContext()
public java.util.Set getCategoryFilter()
public IlrSyntaxTree parse(IlrDTExpressionText expression, IlrDTErrorManager errorManager)
DTErrorManager instance.expression - The expression to parse.errorManager - The object to report errors to.public IlrSyntaxTree parse(java.lang.String text, IlrDTErrorManager errorManager, IlrDTExpression expressionContext)
DTErrorManager instance.text - The string to parse.errorManager - The object to report errors to.expressionContext - The expression that is used for processing when
this method is called. This argument can be null.public IlrBRLMutableParserInput initValueParserInput(java.lang.String text, IlrCardinality cardinality, IlrBRLMutableParserInput input)
text - The string to parse.cardinality - The cardinality.input - An existing parser input or null.public IlrBRLMutableParserConfiguration initValueParserConfiguration(IlrDTExpression expr, IlrConcept type, IlrBRLMutableParserConfiguration config)
NotSUperTypeOf error if
the value is not the appropriate type.expr - The expression in the context this value is parsed. This
parameter can be set to null.type - The type of the value to parse.config - An existing parser configuration or null.public IlrBRLMutablePredictionConfiguration initValuePredictionConfiguration(IlrDTExpressionParameter param, boolean valuesOnly, IlrBRLMutablePredictionConfiguration config)
param - The expression parameter the prediction is requested for.valuesOnly - Set to true to predict constants and values only.config - An existing configuration.param or a new one.public void usePredictionCache(boolean flag)
CachePredictions property of the
corresponding DT model is set to false.
The prediction cache is enabled by default as it optimizes decision table and decision tree editing. Disable the cache if the content of a condition or an action depends on the content of a previous condition or action in the DT Model. Disabling this cache will ensure that predictions are accurate if the model has changed.
flag - Set to true to enable the prediction cache.public boolean usePredictionCache()
true is returned.public java.util.Set predictParameter(IlrDTExpressionParameter param, boolean valuesOnly)
param - The expression parameter.valuesOnly - If valuesOnly is set to true,
and the cardinality of param is multiple, elements of the
collection literal are predicted.null is returned.public IlrSyntaxTree getPreconditionsTree()
public IlrDTExpressionInstance getOtherwiseExpression()
public boolean isOtherwiseExpression(IlrDTExpression e)
e - The expression to test.true is returned.public IlrDTExpressionInstance newOverriddenExpressionInstance(java.lang.String overriddenText, java.util.List<java.lang.String> parameters, IlrDTExpressionDefinition referenceDefinition)
overriddenText is the new definition given in canonical form.
For example, if the expression definition text is:
the amount of 'a loan' is between <min> and <max>
the overridden text should be:
<a number> is less than <a number>
The newly created expression instance inherits its holder role from
referenceDefinition. It will have an expression definition
that represents the given canonical expression.
Note that these kinds of expression are used to override the predicate
of a condition definition in a DT model.
To create an expression instance that does not overrides its definition,
call
newExpressionInstance(IlrDTExpressionDefinition, List).
overriddenText - The definition text that overrides
referenceDefinition. This definitino must be in
canonical form and be syntactically correct in the context of
this expression manager.parameters - The list of parameters. The size of this list corresponds to
the number of argument placeholders given in
overriddenText. Usually, the holder role is also
represented as a placeholder but it is not assigned any
parameter.referenceDefinition - The reference expression definition.public ExpressionDefinition newExpressionDefinition(java.lang.String expressionText)
expressionText - The text of the expression in the locale associated
to this expression manager. This argument cannot be
null.public ExpressionDefinition newExpressionDefinition(java.lang.String expressionText, java.util.List<java.lang.String> defaultValues)
expressionText.
Optionally, a list of values can be passed as the default values for their corresponding placeholders. Note that default values are only supported for an action definition in a DT Model.
expressionText - The text of the expression in the locale associated
to this expression manager instance. This argument cannot be
null.defaultValues - A list of default values for the placeholders of the expression
text. This list must have as many elements as there are
placeholders in the definition. The elements in this list must
have the same order as the placeholders in the text.
This argument can be set to null.public ExpressionInstance newExpressionInstance(IlrDTExpressionDefinition definition, java.util.List<java.lang.String> params)
definition - The referenced expression definition.params - The list of parameters used to populate this expression.
This list must have an element for each placeholder in the definition.
However, it can be set to null.public ExpressionInstance newExpressionInstance(IlrDTExpressionDefinition definition)
definition - The referenced expression definition.definition has placeholders.public IlrBRLMutableParserInput initPreconditionParserInput(java.lang.String text, IlrBRLMutableParserInput input)
text - The precondition text to parse.input - An existing input to be initialized. Set to
null to create a new input.public IlrBRLMutableParserConfiguration initPreconditionParserConfiguration(IlrBRLMutableParserConfiguration config)
config - An existing configuration to be initialized. Set to
null to create a new condition.public IlrBRLMutableParserInput initConditionParserInput(java.lang.String text, IlrBRLMutableParserInput input)
text - The text of the condition expression.input - An existing parser input. Set to null
to create a new input.input object configured to parse a conditional
expression. If input was null, a new
parser input is returned.public IlrBRLMutableParserInput initActionParserInput(java.lang.String text, IlrBRLMutableParserInput input)
text - The action expression text.input - An existing parser input. Set to null
to create a new input.input object configured to parse an action
expression. If input was null, a new
parser input is returned.public IlrBRLMutableParserConfiguration initExpressionParserConfiguration(IlrDTExpression expr, IlrBRLMutableParserConfiguration config)
expr - The DT expression.config - An existing parser configuration. Set to null
to create a new configuration.config object configured to parse an
expression. If config was null, a new
parser input is returned.public IlrDTSentenceContext getAssignSentenceContext()
IlrDTExpressionSentencepublic IlrDTSentenceContext getEqualsSentenceContext()
IlrDTExpressionSentencepublic IlrDTSentenceContext getDoesNotEqualsSentenceContext()
IlrDTExpressionSentencepublic IlrDTSentenceContext getIsNotOneOfSentenceContext()
IlrDTExpressionSentencepublic IlrDTSentenceContext getIsOneOfSentenceContext()
IlrDTExpressionSentencepublic IlrDTSentenceContext getNumberEqualsSentenceContext()
IlrDTExpressionSentencepublic IlrDTSentenceContext getNumberDoesNotEqualsSentenceContext()
IlrDTExpressionSentencepublic IlrDTSentenceContext getSentenceContext(java.lang.String textSentence, int sentenceType)
textSentence - The template text of the sentence, such
<a number;> is between <a number;> and <a number;>sentenceType - IlrDTSentenceContext.CONDITION_SENTENCE_TYPE or
IlrDTSentenceContext.ACTION_SENTENCE_TYPEpublic IlrDTExpressionSentence newActionExpressionSentence(java.lang.String text)
text - The text of the expression.public IlrDTExpressionSentence newConditionExpressionSentence(java.lang.String text)
text - The text of the expression.public IlrDTExpressionElse newExpressionElse()
protected IlrDTExpressionSentence newExpressionSentence(int sentenceType, java.lang.String text)
sentenceType - IlrDTSentenceContext.CONDITION_SENTENCE_TYPE or
IlrDTSentenceContext.ACTION_SENTENCE_TYPEtext - The text of the expression.public IlrDTExpressionSentence newExpressionSentence(java.lang.String holderRoleText, IlrDTSentenceContext sentenceContext)
holderRoleText - sentenceContext - public java.lang.Object parseValue(java.lang.String text,
IlrConcept concept)
text - the text to be parsed.concept - The concept used for parsing.public java.lang.String unparseValue(java.lang.Object value,
IlrConcept concept)
© Copyright IBM Corp. 1987, 2017