Exemplo n.º 1
0
 /// <summary> Set the Current node in the sequence of 1-input nodes.
 /// The Current node can be an AlphaNode or a LIANode.
 /// </summary>
 /// <param name="">node
 ///
 /// </param>
 public override void addSuccessorNode(BaseNode node, Rete engine, IWorkingMemory mem)
 {
     if (addNode(node))
     {
         // if there are matches, we propogate the facts to
         // the new successor only
         IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);
         if (alpha.size() > 0)
         {
             IEnumerator itr = alpha.GetEnumerator();
             while (itr.MoveNext())
             {
                 if (node is BaseAlpha)
                 {
                     BaseAlpha next = (BaseAlpha)node;
                     next.assertFact((IFact)itr.Current, engine, mem);
                 }
                 else if (node is BaseJoin)
                 {
                     BaseJoin next = (BaseJoin)node;
                     next.assertRight((IFact)itr.Current, engine, mem);
                 }
                 else if (node is TerminalNode)
                 {
                     TerminalNode next = (TerminalNode)node;
                     Index        inx  = new Index(new IFact[] { (IFact)itr.Current });
                     next.assertFacts(inx, engine, mem);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Method is used to pass a fact to the successor nodes
        /// </summary>
        /// <param name="inx">The inx.</param>
        /// <param name="engine">The engine.</param>
        /// <param name="mem">The mem.</param>
        protected internal virtual void propogateAssert(Index inx, Rete engine, IWorkingMemory mem)
        {
            for (int idx = 0; idx < successorNodes.Length; idx++)
            {
                BaseJoin baseJoin = successorNodes[idx] as BaseJoin;
                if (baseJoin != null)
                {
                    baseJoin.assertLeft(inx, engine, mem);
                    return;
                }

                TerminalNode terminalNode = successorNodes[idx] as TerminalNode;
                if (terminalNode != null)
                {
                    terminalNode.assertFacts(inx, engine, mem);
                    return;
                }

                //BaseNode node = successorNodes[idx];
                //if (node is BaseJoin)
                //{
                //    ((BaseJoin) node).assertLeft(inx, engine, mem);
                //}
                //else if (node is TerminalNode)
                //{
                //    ((TerminalNode) node).assertFacts(inx, engine, mem);
                //}
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// method for propogating the retract
        /// </summary>
        /// <param name="inx">The inx.</param>
        /// <param name="engine">The engine.</param>
        /// <param name="mem">The mem.</param>
        protected internal virtual void propogateRetract(Index inx, Rete engine, IWorkingMemory mem)
        {
            for (int idx = 0; idx < successorNodes.Length; idx++)
            {
                BaseJoin node = successorNodes[idx] as BaseJoin;
                if (node != null)
                {
                    node.retractLeft(inx, engine, mem);
                }
                else
                {
                    TerminalNode tnode = successorNodes[idx] as TerminalNode;
                    if (tnode != null)
                    {
                        tnode.retractFacts(inx, engine, mem);
                    }
                }


                //BaseNode node = successorNodes[idx];
                //if (node is BaseJoin)
                //{
                //    ((BaseJoin) node).retractLeft(inx, engine, mem);
                //}
                //else if (node is TerminalNode)
                //{
                //    ((TerminalNode) node).retractFacts(inx, engine, mem);
                //}
            }
        }
Exemplo n.º 4
0
 /// <summary> Remove a successor node
 /// </summary>
 /// <param name="">node
 /// </param>
 /// <param name="">engine
 /// </param>
 /// <param name="">mem
 /// @throws AssertException
 ///
 /// </param>
 public virtual void removeSuccessorNode(BaseNode node, Rete engine, IWorkingMemory mem)
 {
     if (removeNode(node))
     {
         // we retract the memories first, before removing the node
         IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);
         if (alpha.size() > 0)
         {
             IEnumerator itr = alpha.GetEnumerator();
             while (itr.MoveNext())
             {
                 if (node is BaseAlpha)
                 {
                     BaseAlpha next = (BaseAlpha)node;
                     next.retractFact((IFact)itr.Current, engine, mem);
                 }
                 else if (node is BaseJoin)
                 {
                     BaseJoin next = (BaseJoin)node;
                     next.retractRight((IFact)itr.Current, engine, mem);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 /// <summary> Add a successor node
 /// </summary>
 public override void addSuccessorNode(BaseNode node, Rete engine, IWorkingMemory mem)
 {
     if (!containsNode(successorNodes, node) && !successor2.Contains(node))
     {
         if (node is BaseJoin || node is TerminalNode)
         {
             successor2.Add(node);
         }
         else
         {
             // we test to see if the operator is ==, nil, not nil
             // if the node isn't BaseJoin, it should be BaseAlpha
             BaseAlpha ba = (BaseAlpha)node;
             if (ba.Operator == Constants.LESS || ba.Operator == Constants.GREATER || ba.Operator == Constants.LESSEQUAL || ba.Operator == Constants.GREATEREQUAL || ba.Operator == Constants.NOTEQUAL || ba.Operator == Constants.NOTNILL)
             {
                 successor2.Add(node);
             }
             else
             {
                 addNode(node);
             }
         }
         if (gauranteeUnique && node is AlphaNode)
         {
             // now we use CompositeIndex instead of HashString
             AlphaNode anode = (AlphaNode)node;
             entries.Put(anode.HashIndex, node);
             // we increment the node count for the slot
             deftemplate.getSlot(anode.slot.Id).incrementNodeCount();
         }
         // if there are matches, we propogate the facts to
         // the new successor only
         IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);
         if (alpha.size() > 0)
         {
             IEnumerator itr = alpha.GetEnumerator();
             while (itr.MoveNext())
             {
                 IFact f = (IFact)itr.Current;
                 if (node is BaseAlpha)
                 {
                     BaseAlpha next = (BaseAlpha)node;
                     next.assertFact(f, engine, mem);
                 }
                 else if (node is BaseJoin)
                 {
                     BaseJoin next = (BaseJoin)node;
                     next.assertRight(f, engine, mem);
                 }
                 else if (node is TerminalNode)
                 {
                     TerminalNode t   = (TerminalNode)node;
                     Index        inx = new Index(new IFact[] { f });
                     t.assertFacts(inx, engine, mem);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Method will attach a new JoinNode to an ancestor node. An ancestor
 /// could be LIANode, AlphaNode or BetaNode.
 /// </summary>
 /// <param name="last">The last.</param>
 /// <param name="join">The join.</param>
 public virtual void attachJoinNode(BaseNode last, BaseJoin join)
 {
     if (last is BaseAlpha)
     {
         ((BaseAlpha)last).addSuccessorNode(join, engine, memory);
     }
     else if (last is BaseJoin)
     {
         ((BaseJoin)last).addSuccessorNode(join, engine, memory);
     }
 }
Exemplo n.º 7
0
        public virtual void printWorkingMemoryBetaRight()
        {
            StringBuilder buf = new StringBuilder();
            IEnumerator   itr = betaRightMemories.Keys.GetEnumerator();

            while (itr.MoveNext())
            {
                BaseJoin key = (BaseJoin)itr.Current;
                buf.Append(key.toPPString());
                Object        rmem = betaRightMemories.Get(key);
                StringBuilder buf2 = new StringBuilder();
                if (rmem is IGenericMap <Object, Object> )
                {
                    int         count = 0;
                    IEnumerator fitr  = ((IGenericMap <Object, Object>)rmem).Values.GetEnumerator();
                    buf2.Append(": ");
                    while (fitr.MoveNext())
                    {
                        IFact ft = (IFact)fitr.Current;
                        buf2.Append(ft.FactId + ",");
                        count++;
                    }
                    buf.Append("- total=" + count + " ");
                    buf.Append(buf2.ToString());
                    buf.Append(Constants.LINEBREAK);
                }
                else
                {
                    HashedAlphaMemoryImpl ham = (HashedAlphaMemoryImpl)rmem;
                    int      count            = 0;
                    Object[] fitr             = ham.iterateAll();
                    if (fitr != null)
                    {
                        for (int idz = 0; idz < fitr.Length; idz++)
                        {
                            IFact ft = (IFact)fitr[idz];
                            buf2.Append(ft.FactId + ",");
                            count++;
                        }
                    }
                    buf.Append("- total=" + count + " :");
                    buf.Append(buf2.ToString());
                    buf.Append(Constants.LINEBREAK);
                }
            }
            engine.writeMessage(buf.ToString());
        }
Exemplo n.º 8
0
 /// <summary> propogate the retract
 /// 
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 protected internal override void propogateRetract(IFact fact, Rete engine, IWorkingMemory mem)
 {
     for (int idx = 0; idx < successorNodes.Length; idx++)
     {
         BaseNode nNode = successorNodes[idx];
         if (nNode is BaseJoin)
         {
             BaseJoin next = (BaseJoin) nNode;
             IFact[] newf = new IFact[] {fact};
             next.retractLeft(new Index(newf), engine, mem);
         }
         else if (nNode is TerminalNode)
         {
             TerminalNode next = (TerminalNode) nNode;
             IFact[] newf = new IFact[] {fact};
             next.retractFacts(new Index(newf), engine, mem);
         }
     }
 }
Exemplo n.º 9
0
 /// <summary> Method is used to pass a fact to the successor nodes
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 protected internal virtual void propogateAssert(IFact fact, Rete engine, IWorkingMemory mem)
 {
     for (int idx = 0; idx < successorNodes.Length; idx++)
     {
         Object nNode = successorNodes[idx];
         if (nNode is BaseAlpha)
         {
             BaseAlpha next = (BaseAlpha)nNode;
             next.assertFact(fact, engine, mem);
         }
         else if (nNode is BaseJoin)
         {
             BaseJoin next = (BaseJoin)nNode;
             next.assertRight(fact, engine, mem);
         }
         else if (nNode is TerminalNode)
         {
             TerminalNode next = (TerminalNode)nNode;
             Index        inx  = new Index(new IFact[] { fact });
             next.assertFacts(inx, engine, mem);
         }
     }
 }
Exemplo n.º 10
0
        /// <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);
            }
        }
Exemplo n.º 11
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);
                }
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// When new Successor nodes are added, we propogate the facts that matched to
 /// the new join node.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="engine">The engine.</param>
 /// <param name="mem">The mem.</param>
 public virtual void addSuccessorNode(BaseJoin node, Rete engine, IWorkingMemory mem)
 {
     if (addNode(node))
     {
         // first, we Get the memory for this node
         IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);
         // now we iterate over the entry set
         IEnumerator itr = leftmem.GetEnumerator();
         while (itr.MoveNext())
         {
             IBetaMemory bmem = (IBetaMemory)itr.Current;
             Index       left = bmem.Index;
             // iterate over the matches
             IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this);
             IEnumerator ritr = rightmem.Keys.GetEnumerator();
             while (ritr.MoveNext())
             {
                 IFact rfcts = (IFact)ritr.Current;
                 // now assert in the new join node
                 node.assertLeft(left.add(rfcts), engine, mem);
             }
         }
     }
 }
Exemplo n.º 13
0
 /// <summary> method for propogating the retract
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 protected internal virtual void propogateRetract(IFact fact, Rete engine, IWorkingMemory mem)
 {
     for (int idx = 0; idx < successorNodes.Length; idx++)
     {
         Object nNode = successorNodes[idx];
         if (nNode is BaseAlpha)
         {
             BaseAlpha next = (BaseAlpha)nNode;
             next.retractFact(fact, engine, mem);
         }
         else if (nNode is BaseJoin)
         {
             BaseJoin next = (BaseJoin)nNode;
             // AlphaNodes always call retractRight in the
             // BetaNode
             next.retractRight(fact, engine, mem);
         }
         else if (nNode is TerminalNode)
         {
             Index inx = new Index(new IFact[] { fact });
             ((TerminalNode)nNode).retractFacts(inx, engine, mem);
         }
     }
 }
Exemplo n.º 14
0
 public virtual void clear()
 {
     reteNode = null;
 }
Exemplo n.º 15
0
        protected internal virtual void printBetaNodes(BaseJoin bjoin, bool detailed, int betaTotal)
        {
            if (bjoin is HashedEqBNode || bjoin is HashedEqNJoin)
            {
                IGenericMap<Object, Object> bm = (IGenericMap<Object, Object>) betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index) bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl) getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact) ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is HashedNotEqNJoin || bjoin is HashedNotEqBNode)
            {
                IGenericMap<Object, Object> bm = (IGenericMap<Object, Object>) betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index) bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory) getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact) ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is ExistJoin)
            {
                ExistJoin henj = (ExistJoin) bjoin;
                IGenericMap<Object, Object> bm = (IGenericMap<Object, Object>) betaLeftMemories.Get(henj);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index) bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl) getBetaRightMemory(henj);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(henj.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact) ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is NotJoin)
            {
                NotJoin nj = (NotJoin) bjoin;
                IGenericMap<Object, Object> bm = (IGenericMap<Object, Object>) getBetaLeftMemory(bjoin);
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index) bitr.Current;
                    IBetaMemory bmem = (IBetaMemory) bm.Get(indx);
                    engine.writeMessage(bmem.toPPString());
                }
            }
            else if (bjoin is TemporalEqNode)
            {
                TemporalEqNode ten = (TemporalEqNode) bjoin;
            }
            else
            {
                IGenericMap<Object, Object> bm = (IGenericMap<Object, Object>) betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index) bm.Get(bitr.Current);
                    Object rightmem = betaRightMemories.Get(bjoin);
                    if (detailed)
                    {
                        if (rightmem is HashedAlphaMemoryImpl)
                        {
                            HashedAlphaMemoryImpl hami = (HashedAlphaMemoryImpl) rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + hami.size() + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                        else
                        {
                            IGenericMap<Object, Object> rmap = (IGenericMap<Object, Object>) rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + rmap.Count + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                    }
                    if (rightmem is HashedAlphaMemoryImpl)
                    {
                        betaTotal += ((HashedAlphaMemoryImpl) rightmem).size();
                    }
                    else
                    {
                        betaTotal += ((IGenericMap<IFact, IFact>)rightmem).Count;
                    }
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Method will attach a new JoinNode to an ancestor node. An ancestor
 /// could be LIANode, AlphaNode or BetaNode.
 /// </summary>
 /// <param name="last">The last.</param>
 /// <param name="join">The join.</param>
 public virtual void attachJoinNode(BaseNode last, BaseJoin join)
 {
     if (last is BaseAlpha)
     {
         ((BaseAlpha) last).addSuccessorNode(join, engine, memory);
     }
     else if (last is BaseJoin)
     {
         ((BaseJoin) last).addSuccessorNode(join, engine, memory);
     }
 }
Exemplo n.º 17
0
        protected internal virtual void printBetaNodes(BaseJoin bjoin, bool detailed, int betaTotal)
        {
            if (bjoin is HashedEqBNode || bjoin is HashedEqNJoin)
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is HashedNotEqNJoin || bjoin is HashedNotEqBNode)
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is ExistJoin)
            {
                ExistJoin henj = (ExistJoin)bjoin;
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(henj);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(henj);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(henj.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is NotJoin)
            {
                NotJoin nj = (NotJoin)bjoin;
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)getBetaLeftMemory(bjoin);
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index       indx = (Index)bitr.Current;
                    IBetaMemory bmem = (IBetaMemory)bm.Get(indx);
                    engine.writeMessage(bmem.toPPString());
                }
            }
            else if (bjoin is TemporalEqNode)
            {
                TemporalEqNode ten = (TemporalEqNode)bjoin;
            }
            else
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index  indx     = (Index)bm.Get(bitr.Current);
                    Object rightmem = betaRightMemories.Get(bjoin);
                    if (detailed)
                    {
                        if (rightmem is HashedAlphaMemoryImpl)
                        {
                            HashedAlphaMemoryImpl hami = (HashedAlphaMemoryImpl)rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + hami.size() + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                        else
                        {
                            IGenericMap <Object, Object> rmap = (IGenericMap <Object, Object>)rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + rmap.Count + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                    }
                    if (rightmem is HashedAlphaMemoryImpl)
                    {
                        betaTotal += ((HashedAlphaMemoryImpl)rightmem).size();
                    }
                    else
                    {
                        betaTotal += ((IGenericMap <IFact, IFact>)rightmem).Count;
                    }
                }
            }
        }
Exemplo n.º 18
0
 /// <summary> Add join nodes to the rule
 /// </summary>
 public virtual void addJoinNode(BaseJoin node)
 {
     joins.Add(node);
 }
Exemplo n.º 19
0
 /// <summary>
 /// When new Successor nodes are added, we propogate the facts that matched to
 /// the new join node.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="engine">The engine.</param>
 /// <param name="mem">The mem.</param>
 public virtual void addSuccessorNode(BaseJoin node, Rete engine, IWorkingMemory mem)
 {
     if (addNode(node))
     {
         // first, we Get the memory for this node
         IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this);
         // now we iterate over the entry set
         IEnumerator itr = leftmem.GetEnumerator();
         while (itr.MoveNext())
         {
             IBetaMemory bmem = (IBetaMemory) itr.Current;
             Index left = bmem.Index;
             // iterate over the matches
             IGenericMap<Object, Object> rightmem = (IGenericMap<Object, Object>) mem.getBetaRightMemory(this);
             IEnumerator ritr = rightmem.Keys.GetEnumerator();
             while (ritr.MoveNext())
             {
                 IFact rfcts = (IFact) ritr.Current;
                 // now assert in the new join node
                 node.assertLeft(left.add(rfcts), engine, mem);
             }
         }
     }
 }