示例#1
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());
        }
示例#2
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;
                    }
                }
            }
        }
示例#3
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;
                    }
                }
            }
        }