コード例 #1
0
ファイル: ReteBuilder.cs プロジェクト: zhjrate/NRules
        private void BuildJoinNode(ReteBuilderContext context, RuleElement element, List <ExpressionElement> conditions = null)
        {
            var expressionElements = conditions ?? new List <ExpressionElement>();
            var node = context.BetaSource
                       .Sinks.OfType <JoinNode>()
                       .FirstOrDefault(x =>
                                       x.RightSource == context.AlphaSource &&
                                       x.LeftSource == context.BetaSource &&
                                       ExpressionElementComparer.AreEqual(x.ExpressionElements, expressionElements));

            if (node == null)
            {
                var compiledExpressions = new List <ILhsExpression <bool> >(expressionElements.Count);
                foreach (var expressionElement in expressionElements)
                {
                    var compiledExpression = ExpressionCompiler.CompileLhsExpression <bool>(expressionElement, context.Declarations);
                    compiledExpressions.Add(compiledExpression);
                }
                node = new JoinNode(context.BetaSource, context.AlphaSource, expressionElements, compiledExpressions, context.HasSubnet);
            }
            node.NodeInfo.Add(context.Rule, element);
            BuildBetaMemoryNode(context, node);
            context.ResetAlphaSource();
        }