Ejemplo n.º 1
0
        public override bool Equals(Object val)
        {
            if (this == val)
            {
                return(true);
            }
            if (val == null || GetType() != val.GetType())
            {
                return(false);
            }

            CompositeIndex ci = (CompositeIndex)val;

            return(ci.name.Equals(name) && ci.operator_Renamed == operator_Renamed && ci.value_Renamed.Equals(value_Renamed));
        }
Ejemplo n.º 2
0
        public void testIndex()
        {
            Defclass dc = new Defclass(typeof (TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2 bean = new TestBean2();
            bean.Attr1 = ("testString");
            bean.Attr2 = (1);
            short a3 = 3;
            bean.Attr3 = (a3);
            long a4 = 101;
            bean.Attr4 = (a4);
            float a5 = 10101;
            bean.Attr5 = (a5);
            double a6 = 101.101;
            bean.Attr6 = (a6);

            IFact fact = dtemp.createFact(bean, dc, 1);
            Assert.IsNotNull(fact);
            Console.WriteLine(fact.toFactString());
            CompositeIndex ci =
                new CompositeIndex("attr1", Constants.EQUAL, fact.getSlotValue(0));
            Assert.IsNotNull(ci);
            Console.WriteLine(ci.toPPString());
            GenericHashMap<object, object> map = new GenericHashMap<object, object>();
            map.Put(ci, bean);

            CompositeIndex ci2 =
                new CompositeIndex("attr1", Constants.EQUAL, fact.getSlotValue(0));
            Assert.IsTrue(map.ContainsKey(ci2));

            CompositeIndex ci3 =
                new CompositeIndex("attr1", Constants.NOTEQUAL, fact.getSlotValue(0));
            Assert.IsFalse(map.ContainsKey(ci3));

            CompositeIndex ci4 =
                new CompositeIndex("attr1", Constants.NILL, fact.getSlotValue(0));
            Assert.IsFalse(map.ContainsKey(ci4));

            CompositeIndex ci5 =
                new CompositeIndex("attr1", Constants.NOTNILL, fact.getSlotValue(0));
            Assert.IsFalse(map.ContainsKey(ci5));
        }
Ejemplo n.º 3
0
        public void testEqual()
        {
            Defclass dc = new Defclass(typeof (TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2 bean = new TestBean2();
            bean.Attr1 = ("testString");
            bean.Attr2 = (1);
            short a3 = 3;
            bean.Attr3 = (a3);
            long a4 = 101;
            bean.Attr4 = (a4);
            float a5 = 10101;
            bean.Attr5 = (a5);
            double a6 = 101.101;
            bean.Attr6 = (a6);

            IFact fact = dtemp.createFact(bean, dc, 1);
            Assert.IsNotNull(fact);
            Console.WriteLine(fact.toFactString());
            CompositeIndex ci = new CompositeIndex("attr1", Constants.EQUAL, fact.getSlotValue(0));
            Assert.IsNotNull(ci);
            Console.WriteLine(ci.toPPString());
        }
Ejemplo n.º 4
0
        /// <summary> assert using HashMap approach
        ///
        /// </summary>
        /// <param name="">fact
        /// </param>
        /// <param name="">engine
        /// </param>
        /// <param name="">mem
        ///
        /// </param>
        public virtual void assertFactWithMap(IFact fact, Rete engine, IWorkingMemory mem)
        {
            Slot[] slots = fact.Deftemplate.AllSlots;
            // iterate over the slots
            for (int idx = 0; idx < slots.Length; idx++)
            {
                // only if the slot's node count is greater than zero
                // do we go ahead and lookup in the HashMap
                if (slots[idx].NodeCount > 0)
                {
                    // iterate over the operators
                    for (int ops = 0; ops < operators.Length; ops++)
                    {
                        CompositeIndex comIndex = new CompositeIndex(slots[idx].Name, operators[ops], fact.getSlotValue(idx));

                        Object node = entries.Get(comIndex);
                        if (node != null)
                        {
                            if (node is BaseAlpha)
                            {
                                ((BaseAlpha)node).assertFact(fact, engine, mem);
                            }
                            else if (node is BaseJoin)
                            {
                                ((BaseJoin)node).assertRight(fact, engine, mem);
                            }
                            else if (node is TerminalNode)
                            {
                                Index inx = new Index(new IFact[] { fact });
                                ((TerminalNode)node).assertFacts(inx, engine, mem);
                            }
                        }
                    }
                }
            }
            assertSecondSuccessors(fact, engine, mem);
        }
Ejemplo n.º 5
0
        /// <summary> assert using HashMap approach
        /// 
        /// </summary>
        /// <param name="">fact
        /// </param>
        /// <param name="">engine
        /// </param>
        /// <param name="">mem
        /// 
        /// </param>
        public virtual void assertFactWithMap(IFact fact, Rete engine, IWorkingMemory mem)
        {
            Slot[] slots = fact.Deftemplate.AllSlots;
            // iterate over the slots
            for (int idx = 0; idx < slots.Length; idx++)
            {
                // only if the slot's node count is greater than zero 
                // do we go ahead and lookup in the HashMap
                if (slots[idx].NodeCount > 0)
                {
                    // iterate over the operators
                    for (int ops = 0; ops < operators.Length; ops++)
                    {
                        CompositeIndex comIndex = new CompositeIndex(slots[idx].Name, operators[ops], fact.getSlotValue(idx));

                        Object node = entries.Get(comIndex);
                        if (node != null)
                        {
                            if (node is BaseAlpha)
                            {
                                ((BaseAlpha) node).assertFact(fact, engine, mem);
                            }
                            else if (node is BaseJoin)
                            {
                                ((BaseJoin) node).assertRight(fact, engine, mem);
                            }
                            else if (node is TerminalNode)
                            {
                                Index inx = new Index(new IFact[] {fact});
                                ((TerminalNode) node).assertFacts(inx, engine, mem);
                            }
                        }
                    }
                }
            }
            assertSecondSuccessors(fact, engine, mem);
        }