ilog.rules.brl.syntaxtree

Class IlrSyntaxTreeHelper

  • java.lang.Object
    • ilog.rules.brl.syntaxtree.IlrSyntaxTreeHelper


  • public class IlrSyntaxTreeHelper
    extends java.lang.Object
    This class is a helper class that provides API to manipulate a syntax tree. Note that the class IlrBRL also provides helper API to retrieve information about the syntax tree nodes.
    • Constructor Detail

      • IlrSyntaxTreeHelper

        public IlrSyntaxTreeHelper()
    • Method Detail

      • findVocabularyElement

        public static IlrVocabularyElement findVocabularyElement(IlrSyntaxTree.Node node,
                                                 IlrVocabulary vocabulary)
        This helper method provides a look-up for a vocabulary element from the given syntax node. Some nodes in a syntax tree may reference a vocabulary element, such as a concept, a sentence, or a concept instance.
        Parameters:
        node - The syntax tree node from which look-up starts.
        vocabulary - The vocabulary that should contain the vocabulary element found, if any.
        Returns:
        A vocabulary element referenced by the given node, if any, or null if none is found.
      • getConcept

        public static IlrConcept getConcept(IlrSyntaxTree.Node conceptNode,
                            IlrVocabulary voc)
        Retrieves a concept from a target node.
        Parameters:
        conceptNode - The Abstract Syntax Tree node.
        voc - The vocabulary.
        Returns:
        The concept found in the vocabulary, or null.
      • getTypeInfo

        public static IlrTypeInfo getTypeInfo(IlrSyntaxTree.Node conceptNode,
                              IlrVocabulary voc)
        Gets the type information from this node.
        Parameters:
        conceptNode - The node of type T-voc-concept.
        voc - The vocabulary.
        Returns:
        The IlrTypeInfo corresponding to this concept node.
      • getConceptInstance

        public static IlrConceptInstance getConceptInstance(IlrSyntaxTree.Node valueNode,
                                            IlrVocabulary voc)
        Retrieves a concept instance from a T-voc-value Abstract Syntax Tree node.
        Parameters:
        valueNode - The node of type T-voc-value.
        voc - The vocabulary.
        Returns:
        The concept instance found in the vocabulary, or null.
      • findRoleNode

        public static IlrSyntaxTree.Node findRoleNode(IlrSyntaxTree.Node sentenceNode,
                                      int synRoleIndex)
        This method returns the syntactic node corresponding to the roleIndex in the sentence node.
        Parameters:
        sentenceNode - The sentence node, holding role nodes.
        synRoleIndex - The index of the looked-up role node (syntactic role).
        Returns:
        The syntactic node corresponding to the role node, or null if none is found.
      • getRoleNode

        public static IlrSyntaxTree.Node getRoleNode(IlrSyntaxTree.Node roleNode)
        This method retrieves a look-up in the syntax tree for a role node.
        Parameters:
        roleNode - The node from which the look-up starts.
        Returns:
        The node corresponding to a sentence role, or null if none is found.
      • getRoleIndex

        public static int getRoleIndex(IlrSyntaxTree.Node roleNode)
        This method, applied on a syntax node representing a role in a sentence, returns the index of the role in the sentence. It is the index of the syntactic role.
        Parameters:
        roleNode -
        Returns:
        The index of the syntactic role in the sentence of -1 if the node does not correspond to a role node, or if the info is not found on the node.
      • getConstrainedRoleValue

        public static java.lang.Object getConstrainedRoleValue(IlrSyntaxTree.Node node)
        This method returns the value attached to the syntax tree corresponding to a role that is constrained by a constraint relationship exising on the role given as argument.
        Parameters:
        node - The syntax tree node corresponding to a role of a sentence. This role is assumed to be constrained by having declared a constraint using the property constraint=xx, where xx is the parameter index of the target role.
        Returns:
        The value stored in the syntax tree for the node corresponding to the role referenced by the constraint. Return null if:
        • the node does not correspond to the role of a sentence
        • no constraint exists on the role
        • the referenced role does not exist, or is not a value
        • the stored value is null
      • hasErrorRecovery

        public static boolean hasErrorRecovery(IlrSyntaxTree ast)
        Returns:
        true if the syntax tree as at least one syntax node in error recovery, otherwise return false.
      • hasErrorRecovery

        public static boolean hasErrorRecovery(IlrSyntaxTree.Node node)
        This method returns true if the given node is in error recovery
        Parameters:
        node - the syntax node, must not be null
        Returns:
        true if the node is in error recovery and false otherwise
      • isEmpty

        public static boolean isEmpty(IlrSyntaxTree tree)
        Tests if the syntax tree is empty. An empty syntax tree is the result of parsing an empty text string.
        Since:
        JRules 7.0
        Returns:
        If the syntax tree is empty, that is if it contains a single root node with no contents or subnodes, true is returned.
      • getTemplateInfo

        public static java.util.List getTemplateInfo(IlrSyntaxTree tree)
        This method retrieves the template information stored on the syntax tree.
        Parameters:
        tree - The syntax tree from which to retrieve the template information.
        Returns:
        A list of IlrBRLTemplateInfo, or null if no template information is stored on the syntax tree.
      • setTemplateInfo

        public static java.util.List setTemplateInfo(java.util.List templateInfo,
                                     IlrSyntaxTree tree)
        This method applies the template information on the syntax tree. It tries to apply as much template information as it can and return a list of template information that has not been applied.
        Parameters:
        templateInfo - A list of BRLTemplateInfo describing the template information.
        tree - The syntax tree on which to apply the template information.
        Returns:
        A list of template information that has not been applied, or null if all has been applied.
      • hasPlaceHolders

        public static boolean hasPlaceHolders(IlrSyntaxTree.Node node)
        This method returns true if the node or one of its children has a placeholder. Placeholder information is stored on each incomplete syntax node. For example, a value node that has not yet been filled.
        Parameters:
        node - the root syntax node
        Returns:
        true if at least one node in the tree, starting at the node passed to the method, has a placeholder.
        See Also:
        IlrSyntaxTree.hasPlaceHolders()
      • getAndNode

        public static IlrSyntaxTree.Node getAndNode(IlrSyntaxTree.Node node,
                                    int direction)
        This method returns the 1st And node found in the given syntax tree starting from the given node following the given direction (specified using IlrSyntaxTree.UP or IlrSyntaxTree.DOWN
        Parameters:
        node -
        direction -
        Returns:
        the 1st And node found in the tree
      • getOrNode

        public static IlrSyntaxTree.Node getOrNode(IlrSyntaxTree.Node node,
                                   int direction)
        This method returns the 1st Or node found in the given syntax tree starting from the given node following the given direction (specified using IlrSyntaxTree.UP or IlrSyntaxTree.DOWN
        Parameters:
        node -
        direction -
        Returns:
        the 1st And node found in the tree
      • findEnclosingSentence

        public static IlrSentence findEnclosingSentence(IlrSyntaxTree.Node node)
        This method looks-up from the given node to find the first enclosing sentence ignoring operators.
        Parameters:
        node -
        Returns:
        the first enclosing sentence or null if none is found up to the root
      • isRulesetParameter

        public static boolean isRulesetParameter(IlrSyntaxTree.Node variableNode)
        Tests if the variable node is a ruleset parameter.
        Parameters:
        variableNode - The node of type T-voc-variable.
        Returns:
        true if the variable node is a parameter.
      • isRulesetVariable

        public static boolean isRulesetVariable(IlrSyntaxTree.Node variableNode)
        Tests if the variable node is a ruleset variable.
        Parameters:
        variableNode - The node of type T-voc-variable.
        Returns:
        true if the variable node is a ruleset variable.
      • isExternalVariable

        public static boolean isExternalVariable(IlrSyntaxTree.Node variableNode)
        Tests if the variable node is a ruleset variable or parameter.
        Parameters:
        variableNode - The node of type T-voc-variable.
        Returns:
        true if the variable node is a ruleset variable or parameter.
      • isRuleVariable

        public static boolean isRuleVariable(IlrSyntaxTree.Node node)
        Tests if a node is the automatic variable "the rule" used in the Select ruleflow.
        Parameters:
        node - The node to check.
        Returns:
        If node is the automatic variable, true is returned.
      • getVocabularyElements

        public static java.util.Collection<IlrVocabularyElement> getVocabularyElements(IlrSyntaxTree syntaxTree,
                                                                       java.util.Collection<IlrBRLMarker> errors)
        Adds all the vocabulary elements referenced by a syntax tree to a Collection. The syntaxTree parameter should not be in error recovery. If it is, the information returned by this method is not correct. Nodes with errors in syntaxTree are not taken into account.
        Parameters:
        syntaxTree - A non-null syntax tree to explore.
        errors - A collection of errors generated by the parser that created this syntax tree. This collection may be null.
        Returns:
        The collection of IlrVocabularyElement objects referenced in this syntax tree.

© Copyright IBM Corp. 1987, 2017