Exemplo n.º 1
0
 public bool after(Stamp s, uint duration)
 {
     if (isEternal || s.isEternal)
     {
         return(false);
     }
     return(TemporalRules.order(s.occurrenceTime, occurrenceTime, duration) == TemporalRules.EnumOrder.FORWARD);
 }
Exemplo n.º 2
0
        public Stamp clone()
        {
            Stamp cloned = new Stamp();

            cloned.tense                 = tense;
            cloned.dualStamp             = dualStamp;
            cloned.creationTime          = creationTime;
            cloned.privateOccurrenceTime = privateOccurrenceTime;
            return(cloned);
        }
Exemplo n.º 3
0
        public static Stamp makeByTimeTenseSerialAndDuration(
            long time,
            EnumTense tense,
            long serial,
            uint duration
            )
        {
            Stamp created = new Stamp(tense, serial);

            created.setCreationTime(time, duration);
            return(created);
        }
Exemplo n.º 4
0
        // this is different from the OpenNARS implementation because we keep all the evidential base
        public Stamp cloneWithNewOccurrenceTime(long newOccurrenceTime)
        {
            Stamp result = clone();

            if (newOccurrenceTime == ETERNAL)
            {
                result.tense = EnumTense.ETERNAL;
            }
            result.occurrenceTime = newOccurrenceTime;
            return(result);

            throw new NotImplementedException();
        }
Exemplo n.º 5
0
        /**
         * Generate a new stamp for derived sentence by merging the two from parents
         * the first one is no shorter than the second
         *
         * \param first The first Stamp
         * \param second The second Stamp
         */
        public static Stamp zipWithTime(
            Stamp first,
            Stamp second,
            long time
            )
        {
            Debug.Assert(first.dualStamp.used >= second.dualStamp.used);

            Stamp result = new Stamp();

            result.dualStamp      = DualStamp.zip(first.dualStamp, second.dualStamp);
            result.creationTime   = time;
            result.occurrenceTime = first.occurrenceTime;
            return(result);
        }
Exemplo n.º 6
0
        /**
         * Check whether the judgment is equivalent to another one
         * <p>
         * The two may have different keys
         *
         * \param that The other judgment
         * \return Whether the two are equivalent
         */
        public bool checkEquivalentTo(ClassicalSentence that)
        {
            /*
             * if (Parameters.DEBUG) {
             *  if ((!term.equals(term)) || (punctuation != that.punctuation)) {
             *      throw new RuntimeException("invalid comparison for Sentence.equivalentTo");
             *  }
             * }*/
            bool isStampEqual = Stamp.checkEquals(
                stamp,
                that.stamp,
                Stamp.EnumCompareCreationTime.NO,
                Stamp.EnumCompareOccurrenceTime.YES,
                Stamp.EnumCompareEvidentialBaseTime.YES);

            return(truth.checkEquals(that.truth) && isStampEqual);
        }
Exemplo n.º 7
0
        /**
         * project a judgment to a difference occurrence time
         *
         * \param targetTime The time to be projected into
         * \param currentTime The current time as a reference
         * \return The projected belief
         */
        public ClassicalSentence projection(long targetTime, long currentTime)
        {
            TruthValue newTruth = projectionTruth(targetTime, currentTime);

            bool eternalizing = newTruth is EternalizedTruthValue;

            Stamp newStamp = eternalizing ? stamp.cloneWithNewOccurrenceTime(Stamp.ETERNAL) :
                             stamp.cloneWithNewOccurrenceTime(targetTime);

            MakeByTermPunctuationTruthStampNormalizeParameters parameters = new MakeByTermPunctuationTruthStampNormalizeParameters();

            parameters.term       = term;
            parameters.punctation = punctation;
            parameters.truth      = newTruth;
            parameters.stamp      = newStamp;
            parameters.normalize  = false;
            return(makeByTermPunctuationTruthStampNormalize(parameters));
        }
Exemplo n.º 8
0
        /**
         * Check if two stamps contains the same types of content
         *
         * \param a The Stamp to be compared
         * \param b The Stamp to be compared
         * \return Whether the two have contain the same evidential base
         */
        public static bool checkEquals(
            Stamp a,
            Stamp b,
            EnumCompareCreationTime compareCreatingTime,
            EnumCompareOccurrenceTime compareOccurrenceTime,
            EnumCompareEvidentialBaseTime compareEvidentialBase
            )
        {
            if (a == b)
            {
                return(true);
            }

            if (compareCreatingTime == EnumCompareCreationTime.YES)
            {
                if (a.creationTime != b.creationTime)
                {
                    return(false);
                }
            }

            if (compareOccurrenceTime == EnumCompareOccurrenceTime.YES)
            {
                if (a.occurrenceTime != b.occurrenceTime)
                {
                    return(false);
                }
            }

            if (compareEvidentialBase == EnumCompareEvidentialBaseTime.YES)
            {
                // TODO if (a.evidentialHash != b.evidentialHash) return false;

                if (!DualStamp.checkEqual(a.dualStamp, b.dualStamp))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        // checks overlap _inside_ a stamp
        // see https://github.com/opennars/opennars/blob/e844d1ee61a2d9af26e6df91b0cc63be7e7dccfc/nars_core/nars/control/DerivationContext.java#L159
        public static bool checkOverlap(Stamp stamp)
        {
            for (int i = 0; i < stamp.dualStamp.used; i++)
            {
                uint baseI = stamp.dualStamp.accessTermIdHistory(i);
                for (int j = 0; j < stamp.dualStamp.used; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    if (baseI == stamp.dualStamp.accessTermIdHistory(j))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 10
0
        // TODO LOW OPTIMIZATION< use bit based hashing scheme to accelerate this and avoid allocating nonsense >
        // see https://github.com/opennars/opennars/blob/4515f1d8e191a1f097859decc65153287d5979c5/nars_core/nars/entity/Stamp.java#L183
        public static bool checkBaseOverlap(Stamp a, Stamp b)
        {
            HashSet <uint> task_base = new HashSet <uint>();

            for (int i = 0; i < a.dualStamp.used; i++)
            {
                if (task_base.Contains(a.dualStamp.accessTermIdHistory(i)))   // can have an overlap in itself already
                {
                    return(true);
                }
                task_base.Add(a.dualStamp.accessTermIdHistory(i));
            }
            // too restrictive, its checked for non-deductive inference rules in derivedTask
            for (int i = 0; i < b.dualStamp.used; i++)
            {
                if (task_base.Contains(b.dualStamp.accessTermIdHistory(i)))   // can have an overlap in itself already
                {
                    return(true);
                }
                task_base.Add(b.dualStamp.accessTermIdHistory(i));
            }
            return(false);
        }
Exemplo n.º 11
0
        // from https://github.com/opennars/opennars/blob/1.6.5_devel17_RetrospectiveAnticipation/nars_core/nars/entity/Concept.java

        /**
         * Select a belief to interact with the given task in inference
         *
         * get the first qualified one
         *
         * \param task The selected task
         * \return The selected isBelief
         */
        public ClassicalSentence getBelief(DerivationContext nal, ClassicalTask task)
        {
            Stamp             taskStamp    = task.sentence.stamp;
            ClassicalSentence taskSentence = task.sentence;
            long currentTime = memory.time;

            int i = 0;

            foreach (ClassicalTask iBelief in beliefs)
            {
                ClassicalSentence beliefSentence = iBelief.sentence;

                // uncommented because event mechanism is not in place jet
                //nal.emit(EnumXXX.BELIEF_SELECT, iBelief);
                nal.setTheNewStamp(taskStamp, iBelief.sentence.stamp, currentTime);

                // TODO< projection >

                // return the first satisfying belief
                // HINT HUMAN< to return the first value doesn't make much sense without looking at the classical NARS code >
                return(beliefs[i].sentence);
            }
            return(null);
        }