public override void compileSingleCE(Rule.IRule rule) { ICondition[] conds = rule.Conditions; ObjectCondition oc = (ObjectCondition)conds[0]; if (oc.Negated) { // the ObjectCondition is negated, so we need to // handle it appropriate. This means we need to // Add a LIANode to _IntialFact and attach a NOTNode // to the LIANode. ObjectTypeNode otn = (ObjectTypeNode)ruleCompiler.Inputnodes.Get(ruleCompiler.Engine.InitFact); LIANode lianode = ruleCompiler.findLIANode(otn); NotJoin njoin = new NotJoin(ruleCompiler.Engine.nextNodeId()); njoin.Bindings = new Binding[0]; lianode.addSuccessorNode(njoin, ruleCompiler.Engine, ruleCompiler.Memory); // Add the join to the rule object rule.addJoinNode(njoin); oc.LastNode.addSuccessorNode(njoin, ruleCompiler.Engine, ruleCompiler.Memory); } else if (oc.Nodes.Count == 0) { // this means the rule has a binding, but no conditions ObjectTypeNode otn = ruleCompiler.findObjectTypeNode(oc.TemplateName); LIANode lianode = new LIANode(ruleCompiler.Engine.nextNodeId()); otn.addSuccessorNode(lianode, ruleCompiler.Engine, ruleCompiler.Memory); rule.Conditions[0].addNode(lianode); } }
public override void compileSingleCE(Rule.IRule rule) { ICondition[] conds = rule.Conditions; ICondition condition = conds[0]; ExistCondition cond = (ExistCondition)condition; BaseNode base_Renamed = cond.LastNode; BaseJoin bjoin = new ExistJoinFrst(ruleCompiler.Engine.nextNodeId()); if (base_Renamed != null) { if (base_Renamed is BaseAlpha) { ((BaseAlpha)base_Renamed).addSuccessorNode(bjoin, ruleCompiler.Engine, ruleCompiler.Memory); } else if (base_Renamed is BaseJoin) { ((BaseJoin)base_Renamed).addSuccessorNode(bjoin, ruleCompiler.Engine, ruleCompiler.Memory); } } else { // the rule doesn't have a literal constraint so we need to Add // ExistJoinFrst as a child ObjectTypeNode otn = ruleCompiler.findObjectTypeNode(cond.TemplateName); otn.addSuccessorNode(bjoin, ruleCompiler.Engine, ruleCompiler.Memory); } // important, do not call this before ExistJoinFrst is added // if it's called first, the List<Object> will return index // out of bound, since there's nothing in the list cond.addNode(bjoin); rule.addJoinNode(bjoin); }
/// <summary> /// Compiles the joins. /// </summary> /// <param name="rule">The rule.</param> public virtual void compileJoins(Rule.IRule rule) { ICondition[] conds = rule.Conditions; BaseJoin prevJoinNode = null; BaseJoin joinNode = null; ICondition prevCE = null; // only if there's more than 1 condition do we attempt to // create the join nodes. A rule with just 1 condition has // no joins if (conds.Length > 1) { // previous Condition prevCE = conds[0]; //this.compileFirstJoin(engine, memory); moved to the ConditionCompiler.compileFirstJoin method prevCE.getCompiler(this).compileFirstJoin(prevCE, rule); // now compile the remaining conditions for (int idx = 1; idx < conds.Length; idx++) { ICondition cdt = conds[idx]; joinNode = cdt.getCompiler(this).compileJoin(cdt, idx, rule); cdt.getCompiler(this).connectJoinNode(prevCE, cdt, prevJoinNode, joinNode); // now we set the previous node to current prevCE = cdt; prevJoinNode = joinNode; rule.addJoinNode(joinNode); } } else if (conds.Length == 1) { conds[0].getCompiler(this).compileSingleCE(rule); } }