Class RetePatternMatcher

    • Field Detail

      • posMapping

        protected java.util.Map<java.lang.String,​java.lang.Integer> posMapping
      • taggedChildren

        protected java.util.Map<java.lang.Object,​Receiver> taggedChildren
      • connected

        protected boolean connected
    • Constructor Detail

      • RetePatternMatcher

        public RetePatternMatcher​(ReteEngine engine,
                                  RecipeTraceInfo productionNodeTrace)
        Parameters:
        productionNode - a production node that matches this pattern without any parameter bindings
    • Method Detail

      • getProductionNode

        public ProductionNode getProductionNode()
        Since:
        1.6
      • matchOneRandomly

        public Tuple matchOneRandomly​(java.lang.Object[] inputMapping,
                                      boolean[] fixed)
      • matchAll

        public java.util.stream.Stream<Tuple> matchAll​(java.lang.Object[] inputMapping,
                                                       boolean[] fixed)
        Since:
        2.0
      • matchAll

        public java.util.stream.Stream<Tuple> matchAll​(TupleMask mask,
                                                       ITuple inputSignature)
        Since:
        2.0
      • matchOne

        public java.util.Optional<Tuple> matchOne​(java.lang.Object[] inputMapping,
                                                  boolean[] fixed)
        Since:
        2.0
      • matchOne

        public java.util.Optional<Tuple> matchOne​(TupleMask mask,
                                                  ITuple inputSignature)
        Since:
        2.0
      • count

        public int count​(java.lang.Object[] inputMapping,
                         boolean[] fixed)
        Counts the number of occurrences of the pattern that match inputMapping on positions where fixed is true.
        Returns:
        the number of occurrences
      • count

        public int count​(TupleMask mask,
                         ITuple inputSignature)
        Counts the number of occurrences of the pattern that match inputMapping on positions where fixed is true.
        Returns:
        the number of occurrences
        Since:
        1.7
      • projectionSize

        public int projectionSize​(TupleMask groupMask)
        Counts the number of distinct tuples attainable from the match set by projecting match tuples according to the given mask.
        Returns:
        the size of the projection
        Since:
        2.1
      • connect

        public void connect​(Receiver receiver,
                            boolean synchronize)
        Connects a new external receiver that will receive update notifications from now on. The receiver will practically connect to the production node, the added value is unwrapping the updates for external use.
        Parameters:
        synchronize - if true, the contents of the production node will be inserted into the receiver after the connection is established.
      • connect

        public void connect​(Receiver receiver,
                            java.lang.Object tag,
                            boolean synchronize)
        Connects a new external receiver that will receive update notifications from now on. The receiver will practically connect to the production node, the added value is unwrapping the updates for external use. The external receiver will be disconnectable later based on its tag.
        Parameters:
        tag - an identifier to recognize the child node by.
        synchronize - if true, the contents of the production node will be inserted into the receiver after the connection is established.
      • disconnect

        public void disconnect​(Receiver receiver)
        Disconnects a child node.
      • disconnectByTag

        public boolean disconnectByTag​(java.lang.Object tag)
        Disconnects the child node that was connected by specifying the given tag.
        Returns:
        if a child node was found registered with this tag.
      • hasMatch

        public boolean hasMatch​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Decides whether there are any matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        hasMatch in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
      • hasMatch

        public boolean hasMatch​(TupleMask parameterSeedMask,
                                ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Decides whether there are any matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        hasMatch in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
      • countMatches

        public int countMatches​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        countMatches in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
        Returns:
        the number of pattern matches found.
      • countMatches

        public int countMatches​(TupleMask parameterSeedMask,
                                ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        countMatches in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
        Returns:
        the number of pattern matches found.
      • estimateCardinality

        public java.util.Optional<java.lang.Long> estimateCardinality​(TupleMask groupMask,
                                                                      Accuracy requiredAccuracy)
        Description copied from interface: IQueryResultProvider
        Gives an estimate of the number of different groups the matches are projected into by the given mask (e.g. for an identity mask, this means the full match set size). The estimate must meet the required accuracy.

        If there is insufficient information to provide an answer up to the required precision, Optional.empty() may be returned. In other words, query backends may deny an answer, or do their best to give an estimate without actually determining the match set of the query. However, caching backends are expected to simply return the indexed (projection) size, initialized on-demand if necessary.

        PRE: TupleMask.isNonrepeating() must hold for the group mask.

        Specified by:
        estimateCardinality in interface IQueryResultProvider
        Returns:
        if available, an estimate of the cardinality of the projection of the match set, with the desired accuracy.
      • getOneArbitraryMatch

        public java.util.Optional<Tuple> getOneArbitraryMatch​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.
        Specified by:
        getOneArbitraryMatch in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
        Returns:
        a match represented in the internal Tuple representation.
      • getOneArbitraryMatch

        public java.util.Optional<Tuple> getOneArbitraryMatch​(TupleMask parameterSeedMask,
                                                              ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.
        Specified by:
        getOneArbitraryMatch in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
        parameters - the tuple of fixed values restricting the match set to be considered, in the same order as given in parameterSeedMask, so that for each considered match tuple, projectedParameterSeed.equals(parameterSeedMask.transform(match)) should hold
        Returns:
        a match represented in the internal Tuple representation.
      • getAllMatches

        public java.util.stream.Stream<Tuple> getAllMatches​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        getAllMatches in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
        Returns:
        matches represented in the internal Tuple representation.
      • getAllMatches

        public java.util.stream.Stream<Tuple> getAllMatches​(TupleMask parameterSeedMask,
                                                            ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        getAllMatches in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
        parameters - the tuple of fixed values restricting the match set to be considered, in the same order as given in parameterSeedMask, so that for each considered match tuple, projectedParameterSeed.equals(parameterSeedMask.transform(match)) should hold
        Returns:
        matches represented in the internal Tuple representation.
      • addUpdateListener

        public void addUpdateListener​(IUpdateable listener,
                                      java.lang.Object listenerTag,
                                      boolean fireNow)
        Description copied from interface: IQueryResultProvider
        Internal method that registers low-level callbacks for match appearance and disappearance.

        Caution: This is a low-level callback that is invoked when the pattern matcher is not necessarily in a consistent state yet. Importantly, no model modification permitted during the callback.

        The callback can be unregistered via invoking IQueryResultProvider.removeUpdateListener(Object) with the same tag.

        Specified by:
        addUpdateListener in interface IQueryResultProvider
        Parameters:
        listener - the listener that will be notified of each new match that appears or disappears, starting from now.
        listenerTag - a tag by which to identify the listener for later removal by IQueryResultProvider.removeUpdateListener(Object).
        fireNow - if true, the insertion update allback will be immediately invoked on all current matches as a one-time effect.