Beispiel #1
0
        /// <summary> if all the facts have not expired, the method returns true. If a fact has
        /// expired, the method will retract the fact.
        /// </summary>
        /// <param name="">inx
        /// </param>
        /// <param name="">engine
        /// </param>
        /// <param name="">mem
        /// </param>
        /// <returns>
        ///
        /// </returns>
        protected internal virtual bool checkFacts(Index inx, Rete engine, IWorkingMemory mem)
        {
            IFact[] facts   = inx.Facts;
            bool    fresh   = true;
            long    current = (DateTime.Now.Ticks - 621355968000000000) / 10000;

            for (int idx = 0; idx < facts.Length; idx++)
            {
                if (facts[idx] is ITemporalFact)
                {
                    TemporalDeffact tf = (TemporalDeffact)facts[idx];
                    if (tf.ExpirationTime < current)
                    {
                        // the fact has expired
                        fresh = false;
                        try
                        {
                            engine.retractFact(tf);
                        }
                        catch (RetractException e)
                        {
                            // we do nothing
                        }
                    }
                }
            }
            return(fresh);
        }
Beispiel #2
0
        public virtual IFact createTemporalFact(Object[] data, long id)
        {
            Slot[] values  = cloneAllSlots();
            long   expire  = 0;
            String source  = "";
            String service = "";
            int    valid   = 0;

            for (int idz = 0; idz < data.Length; idz++)
            {
                Slot s = (Slot)data[idz];
                // check to see if the slot is a temporal fact attribute
                if (isTemporalAttribute(s))
                {
                    if (s.Name.Equals(TemporalFact_Fields.EXPIRATION))
                    {
                        expire = Decimal.ToInt64(((Decimal)s.Value));
                    }
                    else if (s.Name.Equals(TemporalFact_Fields.SERVICE_TYPE))
                    {
                        service = (String)s.Value;
                    }
                    else if (s.Name.Equals(TemporalFact_Fields.SOURCE))
                    {
                        source = (String)s.Value;
                    }
                    else if (s.Name.Equals(TemporalFact_Fields.VALIDITY))
                    {
                        valid = Decimal.ToInt32(((Decimal)s.Value));
                    }
                }
                else
                {
                    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 if (s.Value is BoundParam)
                            {
                                values[idx].Value = s.Value;
                            }
                            else
                            {
                                values[idx].Value = s.Value;
                            }
                        }
                    }
                }
            }
            TemporalDeffact newfact = new TemporalDeffact(this, null, values, id);

            // we call this to create the string used to map the fact.
            newfact.ExpirationTime = expire;
            newfact.ServiceType    = service;
            newfact.Source         = source;
            newfact.Validity       = valid;
            newfact.equalityIndex();
            return(newfact);
        }
Beispiel #3
0
 public virtual IFact createTemporalFact(Object[] data, long id)
 {
     Slot[] values = cloneAllSlots();
     long expire = 0;
     String source = "";
     String service = "";
     int valid = 0;
     for (int idz = 0; idz < data.Length; idz++)
     {
         Slot s = (Slot) data[idz];
         // check to see if the slot is a temporal fact attribute
         if (isTemporalAttribute(s))
         {
             if (s.Name.Equals(TemporalFact_Fields.EXPIRATION))
             {
                 expire = Decimal.ToInt64(((Decimal) s.Value));
             }
             else if (s.Name.Equals(TemporalFact_Fields.SERVICE_TYPE))
             {
                 service = (String) s.Value;
             }
             else if (s.Name.Equals(TemporalFact_Fields.SOURCE))
             {
                 source = (String) s.Value;
             }
             else if (s.Name.Equals(TemporalFact_Fields.VALIDITY))
             {
                 valid = Decimal.ToInt32(((Decimal) s.Value));
             }
         }
         else
         {
             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 if (s.Value is BoundParam)
                     {
                         values[idx].Value = s.Value;
                     }
                     else
                     {
                         values[idx].Value = s.Value;
                     }
                 }
             }
         }
     }
     TemporalDeffact newfact = new TemporalDeffact(this, null, values, id);
     // we call this to create the string used to map the fact.
     newfact.ExpirationTime = expire;
     newfact.ServiceType = service;
     newfact.Source = source;
     newfact.Validity = valid;
     newfact.equalityIndex();
     return newfact;
 }