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); }
public ISessionFactory Compile(IEnumerable <IRuleDefinition> ruleDefinitions) { var rules = new List <ICompiledRule>(); var reteBuilder = new ReteBuilder(); foreach (var ruleDefinition in ruleDefinitions) { var context = new ReteBuilderContext(); ITerminalNode terminalNode = reteBuilder.AddRule(context, ruleDefinition); ICompiledRule compiledRule = CompileRule(context, ruleDefinition); BuildRuleNode(compiledRule, terminalNode); rules.Add(compiledRule); } INetwork network = reteBuilder.GetNetwork(); var factory = new SessionFactory(network); return(factory); }
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); }
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); }