Ejemplo n.º 1
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((CompiledRule.GetHashCode() * 397) ^ Tuple.GetHashCode());
     }
 }
Ejemplo n.º 2
0
        private void CompileRule(IReteBuilder reteBuilder, IRuleDefinition ruleDefinition)
        {
            var transformation   = new RuleTransformation();
            var transformedRule  = transformation.Transform(ruleDefinition);
            var ruleDeclarations = transformedRule.LeftHandSide.Declarations.ToList();
            var ruleDependencies = transformedRule.DependencyGroup.Dependencies.Select(x => x.Declaration).ToList();

            IEnumerable <IRuleDependency> dependencies = CompileDependencies(transformedRule);
            IEnumerable <ITerminalNode>   terminals    = reteBuilder.AddRule(transformedRule);

            var rightHandSide = transformedRule.RightHandSide;
            var actions       = new List <IRuleAction>();

            foreach (var action in rightHandSide.Actions)
            {
                var factIndexMap       = IndexMap.CreateMap(action.References, ruleDeclarations);
                var dependencyIndexMap = IndexMap.CreateMap(action.References, ruleDependencies);
                var ruleAction         = new RuleAction(action.Expression, factIndexMap, dependencyIndexMap);
                actions.Add(ruleAction);
            }

            var rule = new CompiledRule(ruleDefinition, ruleDeclarations, actions, dependencies);

            BuildRuleNode(rule, terminals);
        }
Ejemplo n.º 3
0
        private IEnumerable <ICompiledRule> CompileRule(IReteBuilder reteBuilder, IRuleDefinition ruleDefinition)
        {
            var rules = new List <ICompiledRule>();

            var transformation   = new RuleTransformation();
            var transformedRule  = transformation.Transform(ruleDefinition);
            var ruleDeclarations = transformedRule.LeftHandSide.Exports.ToList();

            var dependencies = transformedRule.DependencyGroup.Dependencies.ToList();
            var terminals    = reteBuilder.AddRule(transformedRule);

            foreach (var terminal in terminals)
            {
                IRuleFilter filter = CompileFilters(transformedRule, ruleDeclarations, terminal.FactMap);

                var rightHandSide = transformedRule.RightHandSide;
                var actions       = new List <IRuleAction>();
                foreach (var action in rightHandSide.Actions)
                {
                    var ruleAction = ExpressionCompiler.CompileAction(action, ruleDeclarations, dependencies, terminal.FactMap);
                    actions.Add(ruleAction);
                }

                var rule = new CompiledRule(ruleDefinition, ruleDeclarations, actions, filter, terminal.FactMap);
                BuildRuleNode(rule, terminal);
                rules.Add(rule);
            }

            return(rules);
        }
Ejemplo n.º 4
0
        private ICompiledRule CompileRule(IReteBuilder reteBuilder, IRuleDefinition ruleDefinition)
        {
            var transformation   = new RuleTransformation();
            var transformedRule  = transformation.Transform(ruleDefinition);
            var ruleDeclarations = transformedRule.LeftHandSide.Declarations.ToList();
            var ruleDependencies = transformedRule.DependencyGroup.Dependencies.Select(x => x.Declaration).ToList();

            IEnumerable <IRuleDependency> dependencies = CompileDependencies(transformedRule);
            IEnumerable <ITerminalNode>   terminals    = reteBuilder.AddRule(transformedRule);

            IRuleFilter filter = CompileFilters(transformedRule, ruleDeclarations);

            var rightHandSide = transformedRule.RightHandSide;
            var actions       = new List <IRuleAction>();

            foreach (var action in rightHandSide.Actions)
            {
                var ruleAction = ExpressionCompiler.CompileAction(action, ruleDeclarations, ruleDependencies);
                actions.Add(ruleAction);
            }

            var rule = new CompiledRule(ruleDefinition, ruleDeclarations, actions, dependencies, filter);

            BuildRuleNode(rule, terminals);

            return(rule);
        }
Ejemplo n.º 5
0
        private ICompiledRule CompileRule(ReteBuilderContext context, IRuleDefinition ruleDefinition)
        {
            var rightHandSide = ruleDefinition.RightHandSide;
            var actions       = new List <IRuleAction>();

            foreach (var action in rightHandSide.Actions)
            {
                var mask       = context.GetTupleMask(action.Declarations);
                var ruleAction = new RuleAction(action.Expression, mask.ToArray());
                actions.Add(ruleAction);
            }
            var rule = new CompiledRule(ruleDefinition, actions);

            return(rule);
        }
Ejemplo n.º 6
0
        private ICompiledRule CompileRule(ReteBuilder reteBuilder, IRuleDefinition ruleDefinition)
        {
            var transformation   = new RuleTransformation();
            var transformedRule  = transformation.Transform(ruleDefinition);
            var ruleDeclarations = transformedRule.LeftHandSide.Declarations.ToList();

            IEnumerable <ITerminalNode> terminals = reteBuilder.AddRule(transformedRule);
            var rightHandSide = transformedRule.RightHandSide;
            var actions       = new List <IRuleAction>();

            foreach (var action in rightHandSide.Actions)
            {
                var factIndexMap = FactIndexMap.CreateMap(action.References, ruleDeclarations);
                var ruleAction   = new RuleAction(action.Expression, factIndexMap);
                actions.Add(ruleAction);
            }

            var rule = new CompiledRule(ruleDefinition, actions);

            BuildRuleNode(rule, terminals);
            return(rule);
        }
Ejemplo n.º 7
0
        private void CompileRule(ReteBuilder reteBuilder, IRuleDefinition ruleDefinition)
        {
            var transformation = new RuleTransformation();
            var transformedRule = transformation.Transform(ruleDefinition);
            var ruleDeclarations = transformedRule.LeftHandSide.Declarations.ToList();
            var ruleDependencies = transformedRule.DependencyGroup.Dependencies.Select(x => x.Declaration).ToList();

            IEnumerable<IRuleDependency> dependencies = CompileDependencies(transformedRule);
            IEnumerable<ITerminalNode> terminals = reteBuilder.AddRule(transformedRule);

            var rightHandSide = transformedRule.RightHandSide;
            var actions = new List<IRuleAction>();
            foreach (var action in rightHandSide.Actions)
            {
                var factIndexMap = IndexMap.CreateMap(action.References, ruleDeclarations);
                var dependencyIndexMap = IndexMap.CreateMap(action.References, ruleDependencies);
                var ruleAction = new RuleAction(action.Expression, factIndexMap, dependencyIndexMap);
                actions.Add(ruleAction);
            }

            var rule = new CompiledRule(ruleDefinition, actions, dependencies);
            BuildRuleNode(rule, terminals);
        }