Ejemplo n.º 1
0
 /// <summary>
 /// Add a new ObjectTypeNode. The implementation will check to see
 /// if the node already exists. It will only Add the node if it
 /// doesn't already exist in the network.
 /// </summary>
 /// <param name="node">The node.</param>
 public virtual void addObjectTypeNode(ObjectTypeNode node)
 {
     if (!inputNodes.ContainsKey(node.Deftemplate))
     {
         inputNodes.Put(node.Deftemplate, node);
     }
 }
Ejemplo n.º 2
0
        /// <summary> implementation will Remove the template from the HashMap
        /// and it will Remove the ObjectTypeNode from the network.
        /// </summary>
        public virtual void removeTemplate(ITemplate temp, Rete engine, IWorkingMemory mem)
        {
            deftemplates.Remove(temp.Name);
            if (temp.ClassName != null)
            {
                deftemplates.Remove(temp.ClassName);
            }
            ObjectTypeNode otn = mem.RuleCompiler.getObjectTypeNode(temp);

            mem.RuleCompiler.removeObjectTypeNode(otn);
        }
Ejemplo n.º 3
0
 public virtual void clear()
 {
     lock (this)
     {
         IEnumerator itr = inputNodes.Values.GetEnumerator();
         while (itr.MoveNext())
         {
             ObjectTypeNode otn = (ObjectTypeNode)itr.Current;
             otn.clearSuccessors();
         }
         inputNodes.Clear();
     }
 }
Ejemplo n.º 4
0
 public void testOneSlot()
 {
     Defclass dc = new Defclass(typeof (TestBean2));
     Deftemplate dtemp = dc.createDeftemplate("testBean2");
     TestBean2 bean = new TestBean2();
     Slot[] slts = dtemp.AllSlots;
     ObjectTypeNode otn = new ObjectTypeNode(1, dtemp);
     AlphaNode an = new AlphaNode(1);
     slts[0].Value = ConversionUtils.convert(110);
     an.Operator = Constants.EQUAL;
     an.Slot = (slts[0]);
     Console.WriteLine("node::" + an.ToString());
     Assert.IsNotNull(an.ToString(), "Should have a value.");
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Method will Get the deftemplate's parent and do a lookup
 /// </summary>
 /// <param name="fact">The fact.</param>
 /// <param name="template">The template.</param>
 /// <param name="engine">The engine.</param>
 /// <param name="mem">The mem.</param>
 public virtual void retractObjectParent(IFact fact, ITemplate template, Rete engine, IWorkingMemory mem)
 {
     lock (this)
     {
         ObjectTypeNode otn = (ObjectTypeNode)inputNodes.Get(template);
         if (otn != null)
         {
             otn.retractFact(fact, engine, mem);
         }
         if (template.Parent != null)
         {
             retractObjectParent(fact, template.Parent, engine, mem);
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// method will find the first LeftInputAdapter node for the
        /// ObjectTypeNode. There should only be one that is a direct
        /// successor.
        /// </summary>
        /// <param name="otn">The otn.</param>
        /// <returns></returns>
        public virtual LIANode findLIANode(ObjectTypeNode otn)
        {
            LIANode node = null;

            if (otn.SuccessorNodes != null && otn.SuccessorNodes.Length > 0)
            {
                Object[] nodes = (Object[])otn.SuccessorNodes;
                for (int idx = 0; idx < nodes.Length; idx++)
                {
                    if (nodes[idx] is LIANode)
                    {
                        node = (LIANode)nodes[idx];
                        break;
                    }
                }
            }
            return(node);
        }
Ejemplo n.º 7
0
        protected internal virtual void removeAlphaNodes(IList nodes, ObjectTypeNode otn)
        {
            BaseNode prev = otn;

            for (int idx = 0; idx < nodes.Count; idx++)
            {
                BaseNode node = (BaseNode)nodes[idx];
                if (node.useCount > 1)
                {
                    node.decrementUseCount();
                }
                else
                {
                    prev.removeNode(node);
                }
                prev = node;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// assertObject begins the pattern matching
 /// </summary>
 /// <param name="fact">The fact.</param>
 /// <param name="engine">The engine.</param>
 /// <param name="mem">The mem.</param>
 public virtual void assertObject(IFact fact, Rete engine, IWorkingMemory mem)
 {
     lock (this)
     {
         // we assume Rete has already checked to see if the object
         // has been added to the working memory, so we just assert.
         // we need to lookup the defclass and deftemplate to assert
         // the object to the network
         ObjectTypeNode otn = (ObjectTypeNode)inputNodes.Get(fact.Deftemplate);
         if (otn != null)
         {
             otn.assertFact(fact, engine, mem);
         }
         if (fact.Deftemplate.Parent != null)
         {
             assertObjectParent(fact, fact.Deftemplate.Parent, engine, mem);
         }
     }
 }
Ejemplo n.º 9
0
 /// <summary> The implementation will use either the defclass or the
 /// template name for the key. The templates are stored in
 /// a HashMap.
 /// </summary>
 public virtual void addTemplate(ITemplate temp, Rete engine, IWorkingMemory mem)
 {
     if (!deftemplates.ContainsKey(temp.Name))
     {
         // we have to set the template's module
         if (temp.ClassName != null)
         {
             deftemplates.Put(temp.Name, temp);
             deftemplates.Put(temp.ClassName, temp);
             templateCount++;
         }
         else
         {
             deftemplates.Put(temp.Name, temp);
             templateCount++;
         }
         ObjectTypeNode otn = new ObjectTypeNode(engine.nextNodeId(), temp);
         mem.RuleCompiler.addObjectTypeNode(otn);
     }
 }
Ejemplo n.º 10
0
 /// <summary> implementation uses the deftemplate for the HashMap key and the
 /// node for the value. If the node already exists in the HashMap,
 /// or the key already exists, the compiler will not Add it to the
 /// network.
 /// </summary>
 public virtual void addObjectTypeNode(ObjectTypeNode node)
 {
     if (!inputnodes.ContainsKey(node.Deftemplate))
     {
         inputnodes.Put(node.Deftemplate, node);
     }
     // if it is the objectTypeNode for InitialFact, we go ahead and create
     // the Left Input Adapter node for it
     if (node.Deftemplate is InitialFact)
     {
         try
         {
             IFLIANode lian = new IFLIANode(engine.nextNodeId());
             node.addSuccessorNode(lian, engine, engine.workingMem);
         }
         catch (AssertException e)
         {
         }
     }
 }
Ejemplo n.º 11
0
        public void testTwoSlots()
        {
            Defclass dc = new Defclass(typeof (TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2 bean = new TestBean2();
            Slot[] slts = dtemp.AllSlots;
            ObjectTypeNode otn = new ObjectTypeNode(1, dtemp);
            AlphaNode an1 = new AlphaNode(1);
            AlphaNode an2 = new AlphaNode(1);

            slts[0].Value = ("testString");
            slts[1].Value = (ConversionUtils.convert(999));

            an1.Slot = (slts[0]);
            an1.Operator = (Constants.EQUAL);
            Console.WriteLine("node::" + an1.toPPString());
            Assert.IsNotNull(an1.toPPString());

            an2.Slot = (slts[1]);
            an2.Operator = (Constants.GREATER);
            Console.WriteLine("node::" + an2.toPPString());
            Assert.IsNotNull(an2.toPPString());
        }
Ejemplo n.º 12
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);
                }
            }
        }
Ejemplo n.º 13
0
 /// <summary> The implementation will use either the defclass or the
 /// template name for the key. The templates are stored in
 /// a HashMap.
 /// </summary>
 public virtual void addTemplate(ITemplate temp, Rete engine, IWorkingMemory mem)
 {
     if (!deftemplates.ContainsKey(temp.Name))
     {
         // we have to set the template's module
         if (temp.ClassName != null)
         {
             deftemplates.Put(temp.Name, temp);
             deftemplates.Put(temp.ClassName, temp);
             templateCount++;
         }
         else
         {
             deftemplates.Put(temp.Name, temp);
             templateCount++;
         }
         ObjectTypeNode otn = new ObjectTypeNode(engine.nextNodeId(), temp);
         mem.RuleCompiler.addObjectTypeNode(otn);
     }
 }
Ejemplo n.º 14
0
 protected internal virtual void removeAlphaNodes(IList nodes, ObjectTypeNode otn)
 {
     BaseNode prev = otn;
     for (int idx = 0; idx < nodes.Count; idx++)
     {
         BaseNode node = (BaseNode) nodes[idx];
         if (node.useCount > 1)
         {
             node.decrementUseCount();
         }
         else
         {
             prev.removeNode(node);
         }
         prev = node;
     }
 }
Ejemplo n.º 15
0
 /// <summary> Method will Remove the ObjectTypeNode and call Clear on it.
 /// </summary>
 public virtual void removeObjectTypeNode(ObjectTypeNode node)
 {
     inputnodes.Remove(node.Deftemplate);
     node.clear(memory);
     node.clearSuccessors();
 }
Ejemplo n.º 16
0
 /// <summary> The current implementation just removes the ObjectTypeNode
 /// and doesn't prevent the removal. The method should be called
 /// with care, since removing the ObjectTypeNode can have serious
 /// negative effects. This would generally occur when an undeftemplate
 /// occurs.
 /// </summary>
 public virtual void removeObjectTypeNode(ObjectTypeNode node)
 {
     inputNodes.Remove(node.Deftemplate);
 }
Ejemplo n.º 17
0
 /// <summary> Method will Remove the ObjectTypeNode and call Clear on it.
 /// </summary>
 public virtual void removeObjectTypeNode(ObjectTypeNode node)
 {
     inputnodes.Remove(node.Deftemplate);
     node.clear(memory);
     node.clearSuccessors();
 }
Ejemplo n.º 18
0
 /// <summary>
 /// method will find the first LeftInputAdapter node for the
 /// ObjectTypeNode. There should only be one that is a direct
 /// successor.
 /// </summary>
 /// <param name="otn">The otn.</param>
 /// <returns></returns>
 public virtual LIANode findLIANode(ObjectTypeNode otn)
 {
     LIANode node = null;
     if (otn.SuccessorNodes != null && otn.SuccessorNodes.Length > 0)
     {
         Object[] nodes = (Object[]) otn.SuccessorNodes;
         for (int idx = 0; idx < nodes.Length; idx++)
         {
             if (nodes[idx] is LIANode)
             {
                 node = (LIANode) nodes[idx];
                 break;
             }
         }
     }
     return node;
 }
Ejemplo n.º 19
0
 /// <summary> implementation uses the deftemplate for the HashMap key and the
 /// node for the value. If the node already exists in the HashMap,
 /// or the key already exists, the compiler will not Add it to the
 /// network.
 /// </summary>
 public virtual void addObjectTypeNode(ObjectTypeNode node)
 {
     if (!inputnodes.ContainsKey(node.Deftemplate))
     {
         inputnodes.Put(node.Deftemplate, node);
     }
     // if it is the objectTypeNode for InitialFact, we go ahead and create
     // the Left Input Adapter node for it
     if (node.Deftemplate is InitialFact)
     {
         try
         {
             IFLIANode lian = new IFLIANode(engine.nextNodeId());
             node.addSuccessorNode(lian, engine, engine.workingMem);
         }
         catch (AssertException e)
         {
         }
     }
 }