Ejemplo n.º 1
0
        public void testNotNil()
        {
            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.NOTNILL, fact.getSlotValue(0));

            Assert.IsNotNull(ci);
            Console.WriteLine(ci.toPPString());
        }
Ejemplo n.º 2
0
 /// <summary> convienance method for getting the values based on the
 /// bindings
 /// </summary>
 /// <param name="">ft
 /// </param>
 /// <returns>
 ///
 /// </returns>
 public static BindValue[] getRightBindValues(Binding[] binds, IFact ft)
 {
     BindValue[] vals = new BindValue[binds.Length];
     for (int idx = 0; idx < binds.Length; idx++)
     {
         vals[idx] = new BindValue(ft.getSlotValue(binds[idx].RightIndex), binds[idx].negated());
     }
     return(vals);
 }
Ejemplo n.º 3
0
 /// <summary> convienance method for getting the values based on the bindings
 /// for nodes that do not have !=
 /// </summary>
 /// <param name="">ft
 /// </param>
 /// <returns>
 ///
 /// </returns>
 public static Object[] getRightValues(Binding[] binds, IFact ft)
 {
     Object[] vals = new Object[binds.Length];
     for (int idx = 0; idx < binds.Length; idx++)
     {
         vals[idx] = ft.getSlotValue(binds[idx].RightIndex);
     }
     return(vals);
 }
Ejemplo n.º 4
0
 /// <summary> convienance method for getting the values based on the
 /// bindings
 /// </summary>
 /// <param name="">ft
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public static BindValue[] getRightBindValues(Binding[] binds, IFact ft)
 {
     BindValue[] vals = new BindValue[binds.Length];
     for (int idx = 0; idx < binds.Length; idx++)
     {
         vals[idx] = new BindValue(ft.getSlotValue(binds[idx].RightIndex), binds[idx].negated());
     }
     return vals;
 }
Ejemplo n.º 5
0
 /// <summary> method will try to resolve the variable and return the value.
 /// </summary>
 public override Object getValue(Rete engine, int valueType)
 {
     if (fact != null)
     {
         return(fact.getSlotValue(column));
     }
     else
     {
         return(engine.getBinding(variableName));
     }
 }
Ejemplo n.º 6
0
 /// <summary> evaluate will extra the values from each side and evaluate it
 /// </summary>
 /// <param name="">left
 /// </param>
 /// <param name="">right
 /// </param>
 /// <returns>
 ///
 /// </returns>
 public virtual bool evaluate(IFact[] left, IFact right)
 {
     if (left[leftrow] == right)
     {
         return(false);
     }
     if (negated_Renamed_Field)
     {
         return(Evaluate.evaluateNotEqual(left[leftrow].getSlotValue(leftIndex), right.getSlotValue(rightIndex)));
     }
     else
     {
         return(Evaluate.evaluateEqual(left[leftrow].getSlotValue(leftIndex), right.getSlotValue(rightIndex)));
     }
 }
Ejemplo n.º 7
0
        /// <summary> return the value associated with the binding
        /// </summary>
        public virtual Object getBindingValue(string key)
        {
            Object val = bindValues.Get(key);

            if (val == null)
            {
                Binding bd = (Binding)bindings[key];
                if (bd != null)
                {
                    IFact left = triggerFacts[bd.LeftRow];
                    if (bd.IsObjectVar)
                    {
                        val = left;
                    }
                    else
                    {
                        val = left.getSlotValue(bd.LeftIndex);
                    }
                }
            }
            return(val);
        }
Ejemplo n.º 8
0
 /// <summary> evaluate the node's value against the slot's value. The method
 /// uses Evaluate class to perform the evaluation
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public virtual bool evaluate(IFact factInstance)
 {
     bool not = slot.NotEqualList.Contains(factInstance.getSlotValue(slot.Id));
     bool eq = slot.EqualList.Contains(factInstance.getSlotValue(slot.Id));
     if (!not && eq)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 9
0
 /// <summary> Method will evaluate a single slot from the left against the right.
 /// </summary>
 /// <param name="">left
 /// </param>
 /// <param name="">leftId
 /// </param>
 /// <param name="">right
 /// </param>
 /// <param name="">rightId
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public virtual bool evaluate(IFact left, int leftId, IFact right, int rightId, int opr)
 {
     if (opr == Constants.NOTEQUAL)
     {
         return Evaluate.evaluateNotEqual(left.getSlotValue(leftId), right.getSlotValue(rightId));
     }
     else
     {
         return Evaluate.evaluateEqual(left.getSlotValue(leftId), right.getSlotValue(rightId));
     }
 }
Ejemplo n.º 10
0
 /// <summary> evaluate the node's value against the slot's value. The method
 /// uses Evaluate class to perform the evaluation
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public virtual bool evaluate(IFact factInstance)
 {
     bool equal = true;
     IEnumerator itr = slot.EqualList.GetEnumerator();
     Object fval = factInstance.getSlotValue(slot.Id);
     while (itr.MoveNext())
     {
         Object mv = itr.Current;
         if (!mv.Equals(fval))
         {
             equal = false;
             break;
         }
     }
     if (equal)
     {
         itr = slot.NotEqualList.GetEnumerator();
         while (itr.MoveNext())
         {
             Object mv = itr.Current;
             if (mv.Equals(fval))
             {
                 equal = false;
                 break;
             }
         }
     }
     return equal;
 }
Ejemplo n.º 11
0
 /// <summary> evaluate the node's value against the slot's value. The method
 /// uses Evaluate class to perform the evaluation
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public virtual bool evaluate(IFact factInstance)
 {
     return Evaluate.evaluate(operator_Renamed, factInstance.getSlotValue(slot.Id), slot.Value);
 }
Ejemplo n.º 12
0
 /// <summary> convienance method for getting the values based on the bindings
 /// for nodes that do not have !=
 /// </summary>
 /// <param name="">ft
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public static Object[] getRightValues(Binding[] binds, IFact ft)
 {
     Object[] vals = new Object[binds.Length];
     for (int idx = 0; idx < binds.Length; idx++)
     {
         vals[idx] = ft.getSlotValue(binds[idx].RightIndex);
     }
     return vals;
 }
Ejemplo n.º 13
0
 public virtual bool evaluate(IFact[] left, IFact right, Rete engine)
 {
     if (function != null)
     {
         IReturnVector rv = function.executeFunction(engine, params_Renamed);
         return rv.firstReturnValue().BooleanValue;
     }
     else if (left.Length > leftrow)
     {
         if (left[leftrow] == right)
         {
             return false;
         }
         return Evaluate.evaluate(operator_Renamed, left[leftrow].getSlotValue(leftIndex), right.getSlotValue(rightIndex));
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 14
0
 /// <summary> evaluate the node's value against the slot's value. The method
 /// uses Evaluate class to perform the evaluation
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 /// </param>
 /// <returns>
 ///
 /// </returns>
 public virtual bool evaluate(IFact factInstance)
 {
     return(Evaluate.evaluate(operator_Renamed, factInstance.getSlotValue(slot.Id), slot.Value));
 }
Ejemplo n.º 15
0
 public virtual bool evaluate(IFact[] left, IFact right, Rete engine)
 {
     if (function != null)
     {
         IReturnVector rv = function.executeFunction(engine, params_Renamed);
         return(rv.firstReturnValue().BooleanValue);
     }
     else if (left.Length > leftrow)
     {
         if (left[leftrow] == right)
         {
             return(false);
         }
         return(Evaluate.evaluate(operator_Renamed, left[leftrow].getSlotValue(leftIndex), right.getSlotValue(rightIndex)));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
 /// <summary> evaluate will extra the values from each side and evaluate it
 /// </summary>
 /// <param name="">left
 /// </param>
 /// <param name="">right
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public virtual bool evaluate(IFact[] left, IFact right)
 {
     if (left[leftrow] == right)
     {
         return false;
     }
     if (negated_Renamed_Field)
     {
         return Evaluate.evaluateNotEqual(left[leftrow].getSlotValue(leftIndex), right.getSlotValue(rightIndex));
     }
     else
     {
         return Evaluate.evaluateEqual(left[leftrow].getSlotValue(leftIndex), right.getSlotValue(rightIndex));
     }
 }
Ejemplo n.º 17
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.º 18
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);
        }