예제 #1
0
        private static ExprNode HandlePreviousFunctions(
            ExprNode defineItemExpression,
            IOrderedDictionary<int, IList<ExprPreviousMatchRecognizeNode>> previousNodes)
        {
            var previousVisitor = new ExprNodePreviousVisitorWParent();
            defineItemExpression.Accept(previousVisitor);

            if (previousVisitor.Previous == null) {
                return defineItemExpression;
            }

            foreach (var previousNodePair in previousVisitor.Previous) {
                var previousNode = previousNodePair.Second;
                var matchRecogPrevNode = new ExprPreviousMatchRecognizeNode();

                if (previousNodePair.Second.ChildNodes.Length == 1) {
                    matchRecogPrevNode.AddChildNode(previousNode.ChildNodes[0]);
                    matchRecogPrevNode.AddChildNode(new ExprConstantNodeImpl(1));
                }
                else if (previousNodePair.Second.ChildNodes.Length == 2) {
                    var first = previousNode.ChildNodes[0];
                    var second = previousNode.ChildNodes[1];
                    if (first is ExprConstantNode && !(second is ExprConstantNode)) {
                        matchRecogPrevNode.AddChildNode(second);
                        matchRecogPrevNode.AddChildNode(first);
                    }
                    else if (!(first is ExprConstantNode) && second is ExprConstantNode) {
                        matchRecogPrevNode.AddChildNode(first);
                        matchRecogPrevNode.AddChildNode(second);
                    }
                    else {
                        throw new ExprValidationException("PREV operator requires a constant index");
                    }
                }

                if (previousNodePair.First == null) {
                    defineItemExpression = matchRecogPrevNode;
                }
                else {
                    ExprNodeUtilityModify.ReplaceChildNode(
                        previousNodePair.First,
                        previousNodePair.Second,
                        matchRecogPrevNode);
                }

                // store in a list per index such that we can consolidate this into a single buffer
                var index = matchRecogPrevNode.ConstantIndexNumber;
                var callbackList = previousNodes.Get(index);
                if (callbackList == null) {
                    callbackList = new List<ExprPreviousMatchRecognizeNode>();
                    previousNodes.Put(index, callbackList);
                }

                callbackList.Add(matchRecogPrevNode);
            }

            return defineItemExpression;
        }
예제 #2
0
        private ExprNode HandlePreviousFunctions(ExprNode defineItemExpression)
        {
            var previousVisitor = new ExprNodePreviousVisitorWParent();

            defineItemExpression.Accept(previousVisitor);

            if (previousVisitor.Previous == null)
            {
                return(defineItemExpression);
            }

            foreach (var previousNodePair in previousVisitor.Previous)
            {
                var previousNode       = previousNodePair.Second;
                var matchRecogPrevNode = new ExprPreviousMatchRecognizeNode();

                if (previousNodePair.Second.ChildNodes.Count == 1)
                {
                    matchRecogPrevNode.AddChildNode(previousNode.ChildNodes[0]);
                    matchRecogPrevNode.AddChildNode(new ExprConstantNodeImpl(1));
                }
                else if (previousNodePair.Second.ChildNodes.Count == 2)
                {
                    var first  = previousNode.ChildNodes[0];
                    var second = previousNode.ChildNodes[1];
                    if ((first.IsConstantResult) && (!second.IsConstantResult))
                    {
                        matchRecogPrevNode.AddChildNode(second);
                        matchRecogPrevNode.AddChildNode(first);
                    }
                    else if ((!first.IsConstantResult) && (second.IsConstantResult))
                    {
                        matchRecogPrevNode.AddChildNode(first);
                        matchRecogPrevNode.AddChildNode(second);
                    }
                    else
                    {
                        throw new ExprValidationException("PREV operator requires a constant index");
                    }
                }

                if (previousNodePair.First == null)
                {
                    defineItemExpression = matchRecogPrevNode;
                }
                else
                {
                    ExprNodeUtility.ReplaceChildNode(previousNodePair.First, previousNodePair.Second, matchRecogPrevNode);
                }

                // store in a list per index such that we can consolidate this into a single buffer
                var index        = matchRecogPrevNode.ConstantIndexNumber;
                var callbackList = _callbacksPerIndex.Get(index);
                if (callbackList == null)
                {
                    callbackList = new List <ExprPreviousMatchRecognizeNode>();
                    _callbacksPerIndex.Put(index, callbackList);
                }
                callbackList.Add(matchRecogPrevNode);
            }

            return(defineItemExpression);
        }