Ejemplo n.º 1
0
        public virtual void assertFact(IFact fact)
        {
            Deffact f = (Deffact)fact;

            if (!containsFact(f))
            {
                deffactMap.Put(fact.equalityIndex(), f);
                f.setFactId = engine;
                if (profileAssert_Renamed_Field)
                {
                    assertFactWProfile(f);
                }
                else
                {
                    if (watchFact_Renamed_Field)
                    {
                        engine.writeMessage("==> " + fact.toFactString() + Constants.LINEBREAK, "t");
                    }
                    root.assertObject(f, engine, this);
                }
            }
            else
            {
                f.resetID((Deffact)deffactMap.Get(fact.equalityIndex()));
            }
        }
Ejemplo n.º 2
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.º 3
0
        public void testCreateDeffactWithNull()
        {
            Defclass    dc    = new Defclass(typeof(TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2   bean  = new TestBean2();

            bean.Attr1 = (null);
            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());
        }
Ejemplo n.º 4
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.º 5
0
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            IList <object> facts = engine.AllFacts;

            Object[] sorted = FactUtils.sortFacts(facts);
            for (int idx = 0; idx < sorted.Length; idx++)
            {
                IFact ft = (IFact)sorted[idx];
                engine.writeMessage(ft.toFactString() + Constants.LINEBREAK);
            }
            engine.writeMessage("for a total of " + sorted.Length + Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
            return(new DefaultReturnVector());
        }
Ejemplo n.º 6
0
        public void testCreateDeffactWithPrimitive()
        {
            Defclass    dc    = new Defclass(typeof(TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2   bean  = new TestBean2();

            bean.Attr1 = ("testString");

            IFact fact = dtemp.createFact(bean, dc, 1);

            Assert.IsNotNull(fact);
            Console.WriteLine(fact.toFactString());
        }
Ejemplo n.º 7
0
        public virtual void retractFact(IFact fact)
        {
            Deffact f = (Deffact)fact;

            deffactMap.Remove(f.equalityIndex());
            if (profileRetract_Renamed_Field)
            {
                retractFactWProfile(f);
            }
            else
            {
                if (watchFact_Renamed_Field)
                {
                    engine.writeMessage("<== " + fact.toFactString() + Constants.LINEBREAK, "t");
                }
                root.retractObject(f, engine, this);
            }
        }
Ejemplo n.º 8
0
 public static bool saveFacts(IList <Object> facts, String output)
 {
     try
     {
         StreamWriter         writer = new StreamWriter(output);
         IEnumerator <Object> itr    = facts.GetEnumerator();
         while (itr.MoveNext())
         {
             IFact f = (IFact)itr.Current;
             writer.Write(f.toFactString());
         }
         writer.Flush();
         writer.Close();
         return(true);
     }
     catch (IOException e)
     {
         return(false);
     }
 }
Ejemplo n.º 9
0
 public virtual void writeArray(Object[] arry, Rete engine, String output, bool linebreak)
 {
     for (int idz = 0; idz < arry.Length; idz++)
     {
         Object val = arry[idz];
         if (val is IFact)
         {
             IFact f = (IFact)val;
             engine.writeMessage(f.toFactString() + " ", output);
         }
         else
         {
             engine.writeMessage(arry[idz].ToString() + " ", output);
         }
         if (linebreak)
         {
             engine.writeMessage(Constants.LINEBREAK, output);
         }
     }
 }
Ejemplo n.º 10
0
        public void testCreateFactFromInstance()
        {
            Defclass    dc    = new Defclass(typeof(TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2   bean  = new TestBean2();

            bean.Attr1 = ("random1");
            bean.Attr2 = (101);
            short s = 10001;

            bean.Attr3 = (s);
            long l = 10101018;

            bean.Attr4 = (l);
            bean.Attr5 = (1010101);
            bean.Attr6 = (1001.1001);
            IFact fact = dtemp.createFact(bean, dc, 0);

            Assert.IsNotNull(fact);
            Console.WriteLine(fact.toFactString());
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Method will process the retractEvent, preferably with an event queue
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="fact">The fact.</param>
 public virtual void assertEvent(BaseNode node, IFact fact)
 {
     if (debug)
     {
         Trace.WriteLine("\"assert at nodeid=" + node.nodeID + " - " + node.ToString().Replace("\"", "'") + ":: with fact -" + fact.toFactString().Replace("\"", "'") + "::\"");
     }
     IEnumerator itr = listeners.GetEnumerator();
     while (itr.MoveNext())
     {
         EngineEventListener eel = (EngineEventListener) itr.Current;
         eel.eventOccurred(new EngineEvent(this, EngineEvent.ASSERT_EVENT, node, new IFact[] {fact}));
     }
 }
Ejemplo n.º 12
0
 public virtual void retractFact(IFact fact)
 {
     Deffact f = (Deffact) fact;
     deffactMap.Remove(f.equalityIndex());
     if (profileRetract_Renamed_Field)
     {
         retractFactWProfile(f);
     }
     else
     {
         if (watchFact_Renamed_Field)
         {
             engine.writeMessage("<== " + fact.toFactString() + Constants.LINEBREAK, "t");
         }
         root.retractObject(f, engine, this);
     }
 }
Ejemplo n.º 13
0
 public virtual void assertFact(IFact fact)
 {
     Deffact f = (Deffact) fact;
     if (!containsFact(f))
     {
         deffactMap.Put(fact.equalityIndex(), f);
         f.setFactId = engine;
         if (profileAssert_Renamed_Field)
         {
             assertFactWProfile(f);
         }
         else
         {
             if (watchFact_Renamed_Field)
             {
                 engine.writeMessage("==> " + fact.toFactString() + Constants.LINEBREAK, "t");
             }
             root.assertObject(f, engine, this);
         }
     }
     else
     {
         f.resetID((Deffact) deffactMap.Get(fact.equalityIndex()));
     }
 }