/// <summary> Method will compile exists quantifier
        /// </summary>
        public override void compile(ICondition condition, int position, Rule.IRule util, bool alphaMemory)
        {
            ExistCondition  cond = (ExistCondition)condition;
            ObjectCondition oc   = (ObjectCondition)cond;

            conditionCompiler.compile(oc, position, util, alphaMemory);
        }
Example #2
0
        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);
        }
Example #4
0
        /// <summary>
        /// </summary>
        /// <param name="">util
        ///
        /// </param>
        public virtual void compileBinding(Rule.IRule util)
        {
            List <object> list = new List <Object>();

            for (int idx = 0; idx < slots.Length; idx++)
            {
                if (slots[idx].Value is BoundParam)
                {
                    hasBinding_Renamed_Field = true;
                    list.Add(slots[idx]);
                    BoundParam bp = (BoundParam)slots[idx].Value;
                    Binding    bd = util.getBinding(bp.VariableName);
                    if (bd != null)
                    {
                        bp.rowId  = bd.LeftRow;
                        bp.column = bd.LeftIndex;
                    }
                }
            }
            if (list.Count > 0)
            {
                Slot[] ary = new Slot[list.Count];
                list.CopyTo(ary, 0);
                boundSlots = ary;
            }
        }
 /// <summary>
 /// The method is responsible for compiling the string form of the
 /// actions to the equivalent functions.
 /// </summary>
 /// <param name="rule">The rule.</param>
 /// <param name="acts">The acts.</param>
 protected internal virtual void compileActions(Rule.IRule rule, IAction[] acts)
 {
     for (int idx = 0; idx < acts.Length; idx++)
     {
         IAction atn = acts[idx];
         atn.configure(engine, rule);
     }
 }
Example #6
0
        public override void compileFirstJoin(ICondition condition, Rule.IRule rule)
        {
            ObjectCondition cond = (ObjectCondition)condition;
            ObjectTypeNode  otn  = ruleCompiler.findObjectTypeNode(cond.TemplateName);
            // the LeftInputAdapterNode is the first node to propogate to
            // the first joinNode of the rule
            LIANode node = new LIANode(ruleCompiler.Engine.nextNodeId());

            // if the condition doesn't have any nodes, we want to Add it to
            // the objectType node if one doesn't already exist.
            // otherwise we Add it to the last AlphaNode
            if (cond.Nodes.Count == 0)
            {
                // try to find the existing LIANode for the given ObjectTypeNode
                // if we don't do this, we end up with multiple LIANodes
                // descending directly from the ObjectTypeNode
                LIANode existingLIANode = ruleCompiler.findLIANode(otn);
                if (existingLIANode == null)
                {
                    otn.addSuccessorNode(node, ruleCompiler.Engine, ruleCompiler.Memory);
                    cond.addNode(node);
                }
                else
                {
                    existingLIANode.incrementUseCount();
                    cond.addNode(existingLIANode);
                }
            }
            else
            {
                // Add the LeftInputAdapterNode to the last alphaNode
                // In the case of node sharing, the LIANode could be the last
                // alphaNode, so we have to check and only Add the node to
                // the condition if it isn't a LIANode
                BaseAlpha old = (BaseAlpha)cond.LastNode;
                //if the last node of condition has a LIANode successor,
                //the LIANode should be shared with the new CE followed by another CE.
                // Houzhanbin,10/16/2007
                BaseNode[] successors = (BaseNode[])old.SuccessorNodes;
                for (int i = 0; i < successors.Length; i++)
                {
                    if (successors[i] is LIANode)
                    {
                        cond.addNode(successors[i]);
                        return;
                    }
                }

                if (!(old is LIANode))
                {
                    old.addSuccessorNode(node, ruleCompiler.Engine, ruleCompiler.Memory);
                    cond.addNode(node);
                }
            }
        }
        /// <summary> method compiles ObjectConditions, which include NOTCE
        /// </summary>
        public override BaseJoin compileJoin(ICondition condition, int position, Rule.IRule rule)
        {
            Binding[]       binds    = getBindings(condition, rule, position);
            ObjectCondition oc       = (ObjectCondition)condition;
            BaseJoin        joinNode = null;

            //deal with the CE which is not NOT CE.
            if (!oc.Negated)
            {
                if (binds.Length > 0 && oc.HasPredicateJoin)
                {
                    joinNode = new PredicateBNode(ruleCompiler.Engine.nextNodeId());
                }
                else if (binds.Length > 0 && oc.HasNotEqual)
                {
                    joinNode = new HashedNotEqBNode(ruleCompiler.Engine.nextNodeId());
                }
                else if (binds.Length > 0)
                {
                    joinNode = new HashedEqBNode(ruleCompiler.Engine.nextNodeId());
                }
                else if (binds.Length == 0)
                {
                    joinNode = new ZJBetaNode(ruleCompiler.Engine.nextNodeId());
                }
            }

            //deal with the CE which is NOT CE.
            if (oc.Negated)
            {
                if (binds.Length > 0 && oc.HasPredicateJoin)
                {
                    joinNode = new NotJoin(ruleCompiler.Engine.nextNodeId());
                }
                else if (oc.HasNotEqual)
                {
                    joinNode = new HashedNotEqNJoin(ruleCompiler.Engine.nextNodeId());
                }
                else
                {
                    joinNode = new HashedEqNJoin(ruleCompiler.Engine.nextNodeId());
                }
            }

            if (joinNode != null)
            {
                joinNode.Bindings = binds;
            }
            return(joinNode);
        }
Example #8
0
        public override BaseJoin compileJoin(ICondition condition, int position, Rule.IRule rule)
        {
            Binding[]         binds    = getBindings(condition, rule, position);
            TemporalCondition tc       = (TemporalCondition)condition;
            TemporalEqNode    joinNode = null;

            //deal with the CE which is not NOT CE.
            if (!tc.Negated)
            {
                if (binds.Length > 0 && tc.HasPredicateJoin)
                {
                    joinNode = new TemporalEqNode(ruleCompiler.Engine.nextNodeId());
                }
                else if (binds.Length > 0 && tc.HasNotEqual)
                {
                    joinNode = new TemporalEqNode(ruleCompiler.Engine.nextNodeId());
                }
                else if (binds.Length > 0)
                {
                    joinNode = new TemporalEqNode(ruleCompiler.Engine.nextNodeId());
                }
            }

            //deal with the CE which is NOT CE.
            if (tc.Negated)
            {
                if (binds.Length > 0 && tc.HasPredicateJoin)
                {
                    joinNode = new TemporalEqNode(ruleCompiler.Engine.nextNodeId());
                }
                else if (tc.HasNotEqual)
                {
                    joinNode = new TemporalEqNode(ruleCompiler.Engine.nextNodeId());
                }
                else
                {
                    joinNode = new TemporalEqNode(ruleCompiler.Engine.nextNodeId());
                }
            }
            joinNode.Bindings         = binds;
            joinNode.RightElapsedTime = tc.RelativeTime * 1000;
            return(joinNode);
        }
 /// <summary>
 /// The method is responsible for creating the right terminal node based on the
 /// settings for the rule.
 /// </summary>
 /// <param name="rl">The rl.</param>
 /// <returns></returns>
 protected internal virtual TerminalNode createTerminalNode(Rule.IRule rl)
 {
     if (rl.NoAgenda && rl.ExpirationDate == 0)
     {
         return(new NoAgendaTNode(engine.nextNodeId(), rl));
     }
     else if (rl.NoAgenda && rl.ExpirationDate > 0)
     {
         return(new NoAgendaTNode2(engine.nextNodeId(), rl));
     }
     else if (rl.ExpirationDate > 0)
     {
         return(new TerminalNode3(engine.nextNodeId(), rl));
     }
     else
     {
         return(new TerminalNode2(engine.nextNodeId(), rl));
     }
 }
Example #10
0
        /// <summary>
        /// Printout the memory for the given rule.
        /// </summary>
        /// <param name="rule">The rule.</param>
        public virtual void printWorkingMemory(Rule.IRule rule)
        {
            engine.writeMessage("Memories for " + rule.Name);
            ICondition[] conds    = rule.Conditions;
            int          memTotal = 0;

            for (int idx = 0; idx < conds.Length; idx++)
            {
                ICondition  c   = conds[idx];
                IList       l   = c.Nodes;
                IEnumerator itr = l.GetEnumerator();
                while (itr.MoveNext())
                {
                    BaseNode     key = (BaseNode)itr.Current;
                    IAlphaMemory am  = (IAlphaMemory)alphaMemories.Get(key);
                    engine.writeMessage(key.toPPString() + " count=" + am.size() + Constants.LINEBREAK);
                    memTotal += am.size();
                }
            }
        }
        /// <summary> method compiles ExistCE to an exist node. It does not include rules that
        /// start with Exist for the first CE.
        /// </summary>
        public override BaseJoin compileJoin(ICondition condition, int position, Rule.IRule rule)
        {
            ExistCondition exc = (ExistCondition)condition;

            Binding[] binds    = getBindings(exc, rule, position);
            BaseJoin  joinNode = null;

            if (exc.HasPredicateJoin)
            {
                joinNode = new ExistPredJoin(ruleCompiler.Engine.nextNodeId());
            }
            else if (exc.HasNotEqual)
            {
                joinNode = new ExistNeqJoin(ruleCompiler.Engine.nextNodeId());
            }
            else
            {
                joinNode = new ExistJoin(ruleCompiler.Engine.nextNodeId());
            }
            joinNode.Bindings = binds;
            return(joinNode);
        }
Example #12
0
        /// <summary> the method is responsible for compiling a TestCE pattern to a testjoin node.
        /// It uses the globally declared prevCE and prevJoinNode
        /// </summary>
        public virtual BaseJoin compileJoin(ICondition condition, int position, Rule.IRule rule)
        {
            TestCondition tc = (TestCondition)condition;
            ShellFunction fn = (ShellFunction)tc.Function;

            fn.lookUpFunction(ruleCompiler.Engine);
            IParameter[] oldpm = fn.Parameters;
            IParameter[] pms   = new IParameter[oldpm.Length];
            for (int ipm = 0; ipm < pms.Length; ipm++)
            {
                if (oldpm[ipm] is ValueParam)
                {
                    pms[ipm] = ((ValueParam)oldpm[ipm]).cloneParameter();
                }
                else if (oldpm[ipm] is BoundParam)
                {
                    BoundParam bpm = (BoundParam)oldpm[ipm];
                    // now we need to resolve and setup the BoundParam
                    Binding    b     = rule.getBinding(bpm.VariableName);
                    BoundParam newpm = new BoundParam(b.LeftRow, b.LeftIndex, 9, bpm.ObjectBinding);
                    newpm.VariableName = bpm.VariableName;
                    pms[ipm]           = newpm;
                }
            }
            BaseJoin joinNode = null;

            if (tc.Negated)
            {
                joinNode = new NTestNode(ruleCompiler.Engine.nextNodeId(), fn.Function, pms);
            }
            else
            {
                joinNode = new TestNode(ruleCompiler.Engine.nextNodeId(), fn.Function, pms);
            }
            ((TestNode)joinNode).lookUpFunction(ruleCompiler.Engine);
            return(joinNode);
        }
        /// <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);
            }
        }
Example #14
0
        /// <summary> Remove a rule from this module
        /// </summary>
        public virtual void removeRule(Rule.IRule rl, Rete engine, IWorkingMemory mem)
        {
            rules.Remove(rl.Name);
            // we should iterate over the nodes of the rule and Remove
            // them if they are not shared
            ICondition[] cnds = rl.Conditions;
            // first Remove the alpha nodes
            for (int idx = 0; idx < cnds.Length; idx++)
            {
                ICondition cnd = cnds[idx];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc    = (ObjectCondition)cnd;
                    String          templ = oc.TemplateName;
                    Deftemplate     temp  = (Deftemplate)deftemplates.Get(templ);
                    ObjectTypeNode  otn   = mem.RuleCompiler.getObjectTypeNode(temp);
                    removeAlphaNodes(oc.Nodes, otn);
                }
            }
            // now Remove the betaNodes, since the engine currently
            // doesn't share the betaNodes, we can just Remove it
            IList bjl = rl.Joins;

            for (int idx = 0; idx < bjl.Count; idx++)
            {
                BaseJoin   bjoin = (BaseJoin)bjl[idx];
                ICondition cnd   = cnds[idx + 1];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc    = (ObjectCondition)cnd;
                    String          templ = oc.TemplateName;
                    Deftemplate     temp  = (Deftemplate)deftemplates.Get(templ);
                    ObjectTypeNode  otn   = mem.RuleCompiler.getObjectTypeNode(temp);
                    otn.removeNode(bjoin);
                }
            }
        }
Example #15
0
 public virtual void configure(Rete engine, Rule.IRule util)
 {
     if (this.engine == null)
     {
         this.engine = engine;
     }
     for (int idx = 0; idx < params_Renamed.Length; idx++)
     {
         if (params_Renamed[idx] is BoundParam)
         {
             // we need to set the row value if the binding is a slot or fact
             BoundParam bp = (BoundParam)params_Renamed[idx];
             Binding    b1 = util.getBinding(bp.VariableName);
             if (b1 != null)
             {
                 bp.Row = b1.LeftRow;
                 if (b1.LeftIndex == -1)
                 {
                     bp.setObjectBinding(true);
                 }
             }
         }
     }
 }
 public abstract void compileSingleCE(Rule.IRule rule);
Example #17
0
 /// <param name="">id
 ///
 /// </param>
 public NoAgendaTNode2(int id, Rule.IRule rl)
     : base(id, rl)
 {
     theRule = rl;
 }
        /// <summary>
        /// method compiles OrLiteralConstraint into alpha nodes
        /// </summary>
        /// <param name="cnstr">The CNSTR.</param>
        /// <param name="templ">The templ.</param>
        /// <param name="rule">The rule.</param>
        /// <returns></returns>
        public virtual BaseAlpha2 compileConstraint(OrLiteralConstraint cnstr, ITemplate templ, Rule.IRule rule)
        {
            BaseAlpha2 current = null;

            if (templ.getSlot(cnstr.Name) != null)
            {
                Slot2 sl = new Slot2(cnstr.Name);
                sl.Id = templ.getColumnIndex(cnstr.Name);
                Object sval = cnstr.Value;
                sl.Value = sval;
                if (rule.RememberMatch)
                {
                    current = new AlphaNodeOr(engine.nextNodeId());
                }
                else
                {
                    current = new NoMemOr(engine.nextNodeId());
                }
                current.Slot = sl;
                current.incrementUseCount();
                // we increment the node use count when when create a new
                // AlphaNode for the LiteralConstraint
                templ.getSlot(sl.Id).incrementNodeCount();
            }
            return(current);
        }
        /// <summary>
        /// method creates Bindings from the bound constraint and adds them to
        /// the Rule.
        /// </summary>
        /// <param name="cnstr">The CNSTR.</param>
        /// <param name="templ">The templ.</param>
        /// <param name="rule">The rule.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        public virtual BaseAlpha2 compileConstraint(BoundConstraint cnstr, ITemplate templ, Rule.IRule rule, int position)
        {
            BaseAlpha2 current = null;

            if (rule.getBinding(cnstr.VariableName) == null)
            {
                // if the HashMap doesn't already contain the binding, we create
                // a new one
                if (cnstr.IsObjectBinding)
                {
                    Binding bind = new Binding();
                    bind.VarName     = cnstr.VariableName;
                    bind.LeftRow     = position;
                    bind.LeftIndex   = -1;
                    bind.IsObjectVar = true;
                    rule.addBinding(cnstr.VariableName, bind);
                }
                else
                {
                    Binding bind = new Binding();
                    bind.VarName           = cnstr.VariableName;
                    bind.LeftRow           = position;
                    bind.LeftIndex         = templ.getSlot(cnstr.Name).Id;
                    bind.RowDeclared       = position;
                    cnstr.FirstDeclaration = true;
                    rule.addBinding(cnstr.VariableName, bind);
                }
            }
            return(current);
        }
Example #20
0
 /// <param name="">id
 /// </param>
 /// <param name="">rl
 ///
 /// </param>
 public TemporalTNode(int id, Rule.IRule rl)
     : base(id, rl)
 {
 }
Example #21
0
 public virtual void compile(ICondition condition, int position, Rule.IRule util, bool alphaMemory)
 {
     // TODO Auto-generated method stub
 }
        /// <summary>
        /// Compiles the constraint.
        /// </summary>
        /// <param name="cnstr">The CNSTR.</param>
        /// <param name="templ">The templ.</param>
        /// <param name="rule">The rule.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        public virtual BaseAlpha2 compileConstraint(PredicateConstraint cnstr, ITemplate templ, Rule.IRule rule, int position)
        {
            BaseAlpha2 current = null;

            // for now we expect the user to write the predicate in this
            // way (> ?bind value), where the binding is first. this
            // needs to be updated so that we look at the order of the
            // parameters and set the node appropriately

            // we only create an AlphaNode if the predicate isn't
            // joining 2 bindings.
            if (!cnstr.PredicateJoin)
            {
                if (ConversionUtils.isPredicateOperatorCode(cnstr.FunctionName))
                {
                    int    oprCode = ConversionUtils.getOperatorCode(cnstr.FunctionName);
                    Slot   sl      = (Slot)templ.getSlot(cnstr.Name).Clone();
                    Object sval    = ConversionUtils.convert(sl.ValueType, cnstr.Value);
                    sl.Value = sval;
                    // create the alphaNode
                    if (rule.RememberMatch)
                    {
                        current = new AlphaNode(engine.nextNodeId());
                    }
                    else
                    {
                        current = new NoMemANode(engine.nextNodeId());
                    }
                    current.Slot     = sl;
                    current.Operator = oprCode;
                    current.incrementUseCount();
                    // we increment the node use count when when create a new
                    // AlphaNode for the LiteralConstraint
                    templ.getSlot(sl.Id).incrementNodeCount();
                }
                else
                {
                    // the function isn't a built in predicate function that
                    // returns boolean true/false. We look up the function
                    IFunction f = engine.findFunction(cnstr.FunctionName);
                    if (f != null)
                    {
                        // we create the alphaNode if a function is found and
                        // the return type is either boolean primitive or object
                        if (f.ReturnType == Constants.BOOLEAN_PRIM_TYPE || f.ReturnType != Constants.BOOLEAN_OBJECT)
                        {
                            // TODO - need to implement it
                        }
                        else
                        {
                            // the function doesn't return boolean, so we have to notify
                            // the listeners the condition is not valid
                            CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.FUNCTION_INVALID);
                            ce.Message = INVALID_FUNCTION + " " + f.ReturnType; //$NON-NLS-1$
                            notifyListener(ce);
                        }
                    }
                    else
                    {
                        // we need to notify listeners the function wasn't found
                        CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.FUNCTION_NOT_FOUND);
                        ce.Message = FUNCTION_NOT_FOUND + " " + cnstr.FunctionName;
                        notifyListener(ce);
                    }
                }
            }
            Binding bind = new Binding();

            bind.VarName     = cnstr.VariableName;
            bind.LeftRow     = position;
            bind.LeftIndex   = templ.getSlot(cnstr.Name).Id;
            bind.RowDeclared = position;
            // we only Add the binding to the map if it doesn't already exist
            if (rule.getBinding(cnstr.VariableName) == null)
            {
                rule.addBinding(cnstr.VariableName, bind);
            }
            return(current);
        }
Example #23
0
        /// <summary> Compile a single ObjectCondition and create the alphaNodes and/or Bindings
        /// </summary>
        public override void compile(ICondition condition, int position, Rule.IRule rule, bool alphaMemory)
        {
            TemporalCondition cond = (TemporalCondition)condition;
            ObjectTypeNode    otn  = ruleCompiler.findObjectTypeNode(cond.TemplateName);
            // we set remember match to false, since the rule is temporal
            bool switchMatch = false;

            if (rule.RememberMatch)
            {
                rule.RememberMatch = false;
                switchMatch        = true;
            }
            if (otn != null)
            {
                BaseAlpha2 first    = null;
                BaseAlpha2 previous = null;
                BaseAlpha2 current  = null;
                ITemplate  templ    = cond.Deftemplate;

                IConstraint[] constrs = cond.Constraints;
                for (int idx = 0; idx < constrs.Length; idx++)
                {
                    IConstraint cnstr = constrs[idx];
                    if (cnstr is LiteralConstraint)
                    {
                        current = ruleCompiler.compileConstraint((LiteralConstraint)cnstr, templ, rule);
                    }
                    else if (cnstr is AndLiteralConstraint)
                    {
                        current = ruleCompiler.compileConstraint((AndLiteralConstraint)cnstr, templ, rule);
                    }
                    else if (cnstr is OrLiteralConstraint)
                    {
                        current = ruleCompiler.compileConstraint((OrLiteralConstraint)cnstr, templ, rule);
                    }
                    else if (cnstr is BoundConstraint)
                    {
                        ruleCompiler.compileConstraint((BoundConstraint)cnstr, templ, rule, position);
                    }
                    else if (cnstr is PredicateConstraint)
                    {
                        current = ruleCompiler.compileConstraint((PredicateConstraint)cnstr, templ, rule, position);
                    }
                    // we Add the node to the previous
                    if (first == null)
                    {
                        first    = current;
                        previous = current;
                    }
                    else if (current != previous)
                    {
                        try
                        {
                            previous.addSuccessorNode(current, ruleCompiler.Engine, ruleCompiler.Memory);
                            // now set the previous to current
                            previous = current;
                        }
                        catch (AssertException e)
                        {
                            // send an event
                        }
                    }
                }
                if (first != null)
                {
                    attachAlphaNode(otn, first, cond);
                }
            }

            if (!cond.Negated)
            {
                position++;
            }
            if (switchMatch)
            {
                rule.RememberMatch = true;
            }
        }
Example #24
0
 public virtual void compileFirstJoin(ICondition condition, Rule.IRule rule)
 {
     // TODO Auto-generated method stub
 }
Example #25
0
 public virtual void compileSingleCE(Rule.IRule rule)
 {
     // TODO Auto-generated method stub
 }
 public abstract void compile(ICondition condition, int position, Rule.IRule util, bool alphaMemory);
 public abstract void compileFirstJoin(ICondition condition, Rule.IRule rule);
 public abstract BaseJoin compileJoin(ICondition condition, int position, Rule.IRule rule);
Example #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TerminalNode"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="rl">The rl.</param>
 public TerminalNode(int id, Rule.IRule rl)
     : base(id)
 {
     theRule = rl;
 }
Example #30
0
 /// <param name="">id
 ///
 /// </param>
 public TerminalNode3(int id, Rule.IRule rl) : base(id, rl)
 {
     theRule = rl;
 }
        /// <summary> the paramList should be clean and
        /// other codes surrounding this method in subclass may be removed into this method.
        /// Houzhanbin 10/16/2007
        /// </summary>
        /// <param name="">condition
        /// </param>
        /// <param name="">rule
        /// </param>
        /// <param name="">Constraints
        /// </param>
        /// <param name="">position
        /// </param>
        /// <param name="">hasNotEqual
        /// </param>
        /// <param name="">hasPredicateJoin
        /// </param>
        /// <returns>
        ///
        /// </returns>
        internal Binding[] getBindings(ICondition condition, Rule.IRule rule, int position)
        {
            ObjectCondition oc          = getObjectCondition(condition);
            IList           Constraints = oc.BindConstraints;
            Deftemplate     tmpl        = oc.Deftemplate;

            Binding[] binds = new Binding[Constraints.Count];
            for (int idz = 0; idz < Constraints.Count; idz++)
            {
                Object cst = Constraints[idz];
                if (cst is BoundConstraint)
                {
                    BoundConstraint bc  = (BoundConstraint)cst;
                    Binding         cpy = rule.copyBinding(bc.VariableName);
                    if (cpy.LeftRow >= position)
                    {
                        binds = new Binding[0];
                        break;
                    }
                    else
                    {
                        binds[idz] = cpy;
                        int rinx = tmpl.getColumnIndex(bc.Name);
                        // we increment the count to make sure the
                        // template isn't removed if it is being used
                        tmpl.incrementColumnUseCount(bc.Name);
                        binds[idz].RightIndex = rinx;
                        binds[idz].Negated    = bc.Negated;
                        if (bc.Negated)
                        {
                            oc.HasNotEqual = true;
                        }
                    }
                }
                else if (cst is PredicateConstraint)
                {
                    PredicateConstraint pc = (PredicateConstraint)cst;
                    if (pc.Value is BoundParam)
                    {
                        oc.HasPredicateJoin = true;
                        BoundParam bpm = (BoundParam)pc.Value;
                        String     var = bpm.VariableName;
                        int        op  = ConversionUtils.getOperatorCode(pc.FunctionName);
                        // check and make sure the function isn't user defined
                        if (op != Constants.USERDEFINED)
                        {
                            // if the first binding in the function is from the object type
                            // we reverse the operator
                            if (pc.Parameters[0] != bpm)
                            {
                                op = ConversionUtils.getOppositeOperatorCode(op);
                            }
                            binds[idz] = rule.copyPredicateBinding(var, op);
                            ((Binding2)binds[idz]).RightVariable = pc.VariableName;
                        }
                        else
                        {
                            binds[idz] = rule.copyPredicateBinding(var, op);
                        }
                        binds[idz].PredJoin = true;
                        int rinx = tmpl.getColumnIndex(pc.Name);
                        // we increment the count to make sure the
                        // template isn't removed if it is being used
                        tmpl.incrementColumnUseCount(pc.Name);
                        binds[idz].RightIndex = rinx;
                    }
                    else if (pc.Value is FunctionParam)
                    {
                        // this means there is a nested function
                    }
                }
            }
            return(binds);
        }