ilog.rules.dt

Class IlrDTExpressionManager

  • java.lang.Object
    • ilog.rules.dt.IlrDTExpressionManager
  • All Implemented Interfaces:
    java.io.Serializable


    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.

    Overview

    This class provides methods used to create and edit new expressions. The 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.

    Code example

    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;
       }
     

    See Also:
    Serialized Form
    • Field Detail

      • CACHE_PREDICTIONS

        public static final java.lang.String CACHE_PREDICTIONS
        To disable the prediction cache, set this property to a DT Model. If this property is not set on the DT model, or if its value is set to true, the prediction cache is enabled.
        See Also:
        Constant Field Values
      • EXPRESSION_OPTIMIZED_PARSING

        public static final java.lang.String EXPRESSION_OPTIMIZED_PARSING
        To disable expression optimized parsing, set this property to a DT Model. If this property is not set on the DT model, or if its value is set to true, expression optimized parsing is enabled.
        See Also:
        Constant Field Values
      • EXPRESSION_OPTIMIZED_KEEP_AST_NOT_OPTIMIZABLE

        public static final 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. When 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.
        See Also:
        Constant Field Values
      • EXPRESSION_OPTIMIZED_MEMORY

        public static final java.lang.String EXPRESSION_OPTIMIZED_MEMORY
        To enable expression optimized memory, set this property to a DT Model. If this property is not set on the DT model, or if its value is set to false, expression optimized memory is disabled.
        See Also:
        Constant Field Values
    • Constructor Detail

      • IlrDTExpressionManager

        public IlrDTExpressionManager(IlrDTContext dtContext,
                              java.lang.String preconditionText)
        Creates an expression manager dedicated to the dtContext.
        Parameters:
        dtContext - A DT Context.
        preconditionText - The precondition text if necessary.
      • IlrDTExpressionManager

        public IlrDTExpressionManager(IlrDTContext dtContext)
        Creates an expression manager dedicated to the dtContext.
        Parameters:
        dtContext - a DT Context
    • Method Detail

      • getDTContext

        public IlrDTContext getDTContext()
        Returns the dt context attached to the expression manager.
        Returns:
        The dt context attached to the expression manager.
      • getCategoryFilter

        public java.util.Set getCategoryFilter()
        Returns the category filter associated with the DT model. This category filter contains the acceptable set of categories. Categories are attached to vocabulary elements.
        Returns:
        The category filter associated with the DT model.
      • parse

        public IlrSyntaxTree parse(IlrDTExpressionText expression,
                          IlrDTErrorManager errorManager)
        Parses an expression and reports errors to a DTErrorManager instance.
        Parameters:
        expression - The expression to parse.
        errorManager - The object to report errors to.
        Returns:
        The syntax tree.
      • parse

        public IlrSyntaxTree parse(java.lang.String text,
                          IlrDTErrorManager errorManager,
                          IlrDTExpression expressionContext)
        Parses a given text string and reports errors to a DTErrorManager instance.
        Parameters:
        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.
        Returns:
        The syntax tree.
      • initValueParserInput

        public 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.
        Parameters:
        text - The string to parse.
        cardinality - The cardinality.
        input - An existing parser input or null.
        Returns:
        The given parser configuration initialized correctly or a newly created one.
      • initValueParserConfiguration

        public 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. Parsing this value will generate a NotSUperTypeOf error if the value is not the appropriate type.
        Parameters:
        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.
        Returns:
        The given parser configuration initialized correctly or a newly created one.
      • initValuePredictionConfiguration

        public 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.
        Parameters:
        param - The expression parameter the prediction is requested for.
        valuesOnly - Set to true to predict constants and values only.
        config - An existing configuration.
        Returns:
        A properly initialized version of param or a new one.
      • usePredictionCache

        public void usePredictionCache(boolean flag)
        Enables or disables the prediction cache for the current expression manager. The cache is disabled if the 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.

        Parameters:
        flag - Set to true to enable the prediction cache.
      • usePredictionCache

        public boolean usePredictionCache()
        Checks if the prediction cache is enabled for this expression manager. By default the prediction cache is enabled.
        Returns:
        If the prediction cache is enabled, true is returned.
      • predictParameter

        public java.util.Set predictParameter(IlrDTExpressionParameter param,
                                     boolean valuesOnly)
        Predicts the content of a given expression instance.
        Parameters:
        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.
        Returns:
        A set of predictions. If the expression cannot be interpreted, null is returned.
      • getPreconditionsTree

        public IlrSyntaxTree getPreconditionsTree()
        Returns the syntax tree corresponding to the interpretation of the DT preconditions.
        Returns:
        A syntax tree.
      • getOtherwiseExpression

        public IlrDTExpressionInstance getOtherwiseExpression()
        Returns the expression instance that represent an otherwise in a partition.
        Returns:
        A dedicated expression instance used as an otherwise.
      • isOtherwiseExpression

        public boolean isOtherwiseExpression(IlrDTExpression e)
        Tests if a given expression is an otherwise expression.
        Parameters:
        e - The expression to test.
        Returns:
        If the given expression is an otherwise expression, true is returned.
      • newOverriddenExpressionInstance

        public 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. The 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).

        Parameters:
        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.
        Returns:
        A new expression instance with the appropriate expression definition.
      • newExpressionDefinition

        public ExpressionDefinition newExpressionDefinition(java.lang.String expressionText)
        Creates an expression definition. An expression definition contains a pattern built from the expression text. This text contains some placeholders.
        Parameters:
        expressionText - The text of the expression in the locale associated to this expression manager. This argument cannot be null.
        Returns:
        A new expression definition.
      • newExpressionDefinition

        public ExpressionDefinition newExpressionDefinition(java.lang.String expressionText,
                                                   java.util.List<java.lang.String> defaultValues)
        Creates a new expression definition. An expression definition contains a pattern that contains some placeholders built from 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.

        Parameters:
        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.
        Returns:
        A new expression definition.
      • newExpressionInstance

        public ExpressionInstance newExpressionInstance(IlrDTExpressionDefinition definition,
                                               java.util.List<java.lang.String> params)
        Creates an expression instance from a given expression definition.
        Parameters:
        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.
        Returns:
        A new expression instance.
      • newExpressionInstance

        public ExpressionInstance newExpressionInstance(IlrDTExpressionDefinition definition)
        Creates an expression instance from a given expression definition.
        Parameters:
        definition - The referenced expression definition.
        Returns:
        A new expression instance with as many parameters as definition has placeholders.
      • initPreconditionParserInput

        public IlrBRLMutableParserInput initPreconditionParserInput(java.lang.String text,
                                                           IlrBRLMutableParserInput input)
        Creates or initializes a parser input designed to parse the precondition text parameter.
        Parameters:
        text - The precondition text to parse.
        input - An existing input to be initialized. Set to null to create a new input.
        Returns:
        A parser input.
      • initPreconditionParserConfiguration

        public IlrBRLMutableParserConfiguration initPreconditionParserConfiguration(IlrBRLMutableParserConfiguration config)
        Creates or initializes a parser configuration designed to parse a precondition.
        Parameters:
        config - An existing configuration to be initialized. Set to null to create a new condition.
        Returns:
        A parser configuration.
      • initConditionParserInput

        public 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.
        Parameters:
        text - The text of the condition expression.
        input - An existing parser input. Set to null to create a new input.
        Returns:
        The input object configured to parse a conditional expression. If input was null, a new parser input is returned.
      • initActionParserInput

        public 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.
        Parameters:
        text - The action expression text.
        input - An existing parser input. Set to null to create a new input.
        Returns:
        The input object configured to parse an action expression. If input was null, a new parser input is returned.
      • initExpressionParserConfiguration

        public 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.
        Parameters:
        expr - The DT expression.
        config - An existing parser configuration. Set to null to create a new configuration.
        Returns:
        The config object configured to parse an expression. If config was null, a new parser input is returned.
      • getAssignSentenceContext

        public IlrDTSentenceContext getAssignSentenceContext()
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the assign sentence context. This sentence context is used to assign values or expressions to variables.
        Returns:
        The assign sentence context.
        See Also:
        IlrDTExpressionSentence
      • getEqualsSentenceContext

        public IlrDTSentenceContext getEqualsSentenceContext()
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the equals sentence context for any concept.
        Returns:
        The equals sentence context for any concept.
        See Also:
        IlrDTExpressionSentence
      • getDoesNotEqualsSentenceContext

        public IlrDTSentenceContext getDoesNotEqualsSentenceContext()
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the does not equal sentence context for any concept.
        Returns:
        The does not equal sentence context for any concept.
        See Also:
        IlrDTExpressionSentence
      • getIsNotOneOfSentenceContext

        public IlrDTSentenceContext getIsNotOneOfSentenceContext()
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the "is not one of" sentence context for any concept.
        Returns:
        The "is not one of" sentence context for any concept.
        See Also:
        IlrDTExpressionSentence
      • getIsOneOfSentenceContext

        public IlrDTSentenceContext getIsOneOfSentenceContext()
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the "is one of" sentence context for any concept.
        Returns:
        The "is one of" sentence context for any concept.
        See Also:
        IlrDTExpressionSentence
      • getNumberEqualsSentenceContext

        public IlrDTSentenceContext getNumberEqualsSentenceContext()
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the "equals" sentence context for the number concept.
        Returns:
        The "equals" sentence context for the number concept.
        See Also:
        IlrDTExpressionSentence
      • getNumberDoesNotEqualsSentenceContext

        public IlrDTSentenceContext getNumberDoesNotEqualsSentenceContext()
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the "does not equals" sentence context for the number concept.
        Returns:
        The "does not equals" sentence context for the number concept.
        See Also:
        IlrDTExpressionSentence
      • getSentenceContext

        public IlrDTSentenceContext getSentenceContext(java.lang.String textSentence,
                                              int sentenceType)
        Deprecated. use an appropriate IlrDTExpressionDefinition
        Returns the sentence context represented by the given template text.
        Parameters:
        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_TYPE
        Returns:
        The sentence context represented by the given template text.
      • newActionExpressionSentence

        public IlrDTExpressionSentence newActionExpressionSentence(java.lang.String text)
        Deprecated. use newExpressionDefinition() or newExpressionInstance() API.
        Creates and returns an expression used for actions in an DTModel.
        Parameters:
        text - The text of the expression.
        Returns:
        An instance of an expression sentence.
      • newConditionExpressionSentence

        public IlrDTExpressionSentence newConditionExpressionSentence(java.lang.String text)
        Deprecated. use newExpressionDefinition() or newExpressionInstance() API.
        Creates and returns an expression used for conditions in an DTModel.
        Parameters:
        text - The text of the expression.
        Returns:
        An instance of an expression sentence.
      • newExpressionElse

        public IlrDTExpressionElse newExpressionElse()
        Deprecated. use getOtherwiseExpression()
        Returns an instance of an Otherwise expression.
        Returns:
        An instance of an Otherwise expression.
      • newExpressionSentence

        public IlrDTExpressionSentence newExpressionSentence(java.lang.String holderRoleText,
                                                    IlrDTSentenceContext sentenceContext)
        Deprecated. use newExpressionDefinition() or newExpressionInstance() API.
        create a Compatibility Expression from the given holder role text and sentence context
        Parameters:
        holderRoleText -
        sentenceContext -
        Returns:
        a compatibility expression
      • parseValue

        public java.lang.Object parseValue(java.lang.String text,
                                  IlrConcept concept)
        Deprecated. use BRL API to parse values
        Converts text to an object representation according to a concept. Text is parsed with a value descriptor of the concept.
        Parameters:
        text - the text to be parsed.
        concept - The concept used for parsing.
        Returns:
        An object value built from its text representation according to a concept.
      • unparseValue

        public java.lang.String unparseValue(java.lang.Object value,
                                    IlrConcept concept)
        Deprecated. use BRL API to create text representation of values.
        Converts an object value to its text representation according to a concept. Values are converted to text with a value descriptor.
        Returns:
        text Representation of a value according to the concept.

© Copyright IBM Corp. 1987, 2017