Пример #1
0
        /// <summary> Method takes a list of Slots and creates a deffact from it.
        ///
        /// </summary>
        /// <param name="">data
        /// </param>
        /// <param name="">id
        /// </param>
        /// <returns>
        ///
        /// </returns>
        public virtual IFact createFact(IList data, long id)
        {
            Slot[]      values = cloneAllSlots();
            IEnumerator itr    = data.GetEnumerator();

            while (itr.MoveNext())
            {
                Slot s = (Slot)itr.Current;
                for (int idx = 0; idx < values.Length; idx++)
                {
                    if (values[idx].Name.Equals(s.Name))
                    {
                        if (s.Value == null)
                        {
                            values[idx].Value = Constants.NIL_SYMBOL;
                        }
                        else if (values[idx].ValueType == Constants.STRING_TYPE && !(s.Value is BoundParam))
                        {
                            values[idx].Value = s.Value.ToString();
                        }
                        else
                        {
                            values[idx].Value = s.Value;
                        }
                    }
                }
            }
            Deffact newfact = new Deffact(this, null, values, id);

            // we call this to create the string used to map the fact.
            newfact.equalityIndex();
            return(newfact);
        }
Пример #2
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);
            }
        }
Пример #3
0
 public virtual bool containsFact(Deffact fact)
 {
     return(deffactMap.ContainsKey(fact.equalityIndex()));
 }
Пример #4
0
 public virtual bool containsFact(Deffact fact)
 {
     return deffactMap.ContainsKey(fact.equalityIndex());
 }
Пример #5
0
        public virtual IFact createFact(Object[] data, long id)
        {
            Slot[]        values     = cloneAllSlots();
            List <Object> bslots     = new List <Object>();
            bool          hasbinding = false;

            for (int idz = 0; idz < data.Length; idz++)
            {
                Slot s = (Slot)data[idz];
                for (int idx = 0; idx < values.Length; idx++)
                {
                    if (values[idx].Name.Equals(s.Name))
                    {
                        if (s is MultiSlot)
                        {
                            // since the value is multislot, we have to
                            // check for boundparams
                            MultiSlot ms    = (MultiSlot)s;
                            Object[]  mvals = (Object[])ms.Value;
                            for (int mdx = 0; mdx < mvals.Length; mdx++)
                            {
                                if (mvals[mdx] is BoundParam)
                                {
                                    bslots.Add((MultiSlot)ms.Clone());
                                    hasbinding = true;
                                    break;
                                }
                            }
                            values[idx].Value = s.Value;
                        }
                        else
                        {
                            if (s.Value == null)
                            {
                                values[idx].Value = Constants.NIL_SYMBOL;
                            }
                            else if (values[idx].ValueType == Constants.STRING_TYPE && !(s.Value is BoundParam))
                            {
                                values[idx].Value = s.Value.ToString();
                            }
                            else if (s.Value is BoundParam)
                            {
                                values[idx].Value = s.Value;
                                bslots.Add((Slot)s.Clone());
                                hasbinding = true;
                            }
                            else
                            {
                                values[idx].Value = s.Value;
                            }
                        }
                        break;
                    }
                }
            }
            Deffact newfact = new Deffact(this, null, values, id);

            if (hasbinding)
            {
                Slot[] slts2 = new Slot[bslots.Count];
                bslots.CopyTo(slts2, 0);
                newfact.boundSlots = slts2;
                newfact.hasBinding_Renamed_Field = true;
            }
            // we call this to create the string used to map the fact.
            newfact.equalityIndex();
            return(newfact);
        }
Пример #6
0
 public virtual IFact createFact(Object[] data, long id)
 {
     Slot[] values = cloneAllSlots();
     List<Object> bslots = new List<Object>();
     bool hasbinding = false;
     for (int idz = 0; idz < data.Length; idz++)
     {
         Slot s = (Slot) data[idz];
         for (int idx = 0; idx < values.Length; idx++)
         {
             if (values[idx].Name.Equals(s.Name))
             {
                 if (s is MultiSlot)
                 {
                     // since the value is multislot, we have to
                     // check for boundparams
                     MultiSlot ms = (MultiSlot) s;
                     Object[] mvals = (Object[]) ms.Value;
                     for (int mdx = 0; mdx < mvals.Length; mdx++)
                     {
                         if (mvals[mdx] is BoundParam)
                         {
                             bslots.Add((MultiSlot) ms.Clone());
                             hasbinding = true;
                             break;
                         }
                     }
                     values[idx].Value = s.Value;
                 }
                 else
                 {
                     if (s.Value == null)
                     {
                         values[idx].Value = Constants.NIL_SYMBOL;
                     }
                     else if (values[idx].ValueType == Constants.STRING_TYPE && !(s.Value is BoundParam))
                     {
                         values[idx].Value = s.Value.ToString();
                     }
                     else if (s.Value is BoundParam)
                     {
                         values[idx].Value = s.Value;
                         bslots.Add((Slot) s.Clone());
                         hasbinding = true;
                     }
                     else
                     {
                         values[idx].Value = s.Value;
                     }
                 }
                 break;
             }
         }
     }
     Deffact newfact = new Deffact(this, null, values, id);
     if (hasbinding)
     {
         Slot[] slts2 = new Slot[bslots.Count];
         bslots.CopyTo(slts2,0);
         newfact.boundSlots = slts2;
         newfact.hasBinding_Renamed_Field = true;
     }
     // we call this to create the string used to map the fact.
     newfact.equalityIndex();
     return newfact;
 }
Пример #7
0
 /// <summary> Method takes a list of Slots and creates a deffact from it.
 /// 
 /// </summary>
 /// <param name="">data
 /// </param>
 /// <param name="">id
 /// </param>
 /// <returns>
 /// 
 /// </returns>
 public virtual IFact createFact(IList data, long id)
 {
     Slot[] values = cloneAllSlots();
     IEnumerator itr = data.GetEnumerator();
     while (itr.MoveNext())
     {
         Slot s = (Slot) itr.Current;
         for (int idx = 0; idx < values.Length; idx++)
         {
             if (values[idx].Name.Equals(s.Name))
             {
                 if (s.Value == null)
                 {
                     values[idx].Value = Constants.NIL_SYMBOL;
                 }
                 else if (values[idx].ValueType == Constants.STRING_TYPE && !(s.Value is BoundParam))
                 {
                     values[idx].Value = s.Value.ToString();
                 }
                 else
                 {
                     values[idx].Value = s.Value;
                 }
             }
         }
     }
     Deffact newfact = new Deffact(this, null, values, id);
     // we call this to create the string used to map the fact.
     newfact.equalityIndex();
     return newfact;
 }