Пример #1
0
        // see https://github.com/opennars/opennars/blob/4515f1d8e191a1f097859decc65153287d5979c5/nars_core/nars/entity/TermLink.java#L137
        public bool checkEqual(ClassicalTermLink other)
        {
            // triple commented is commented because it's not fully implemented

            if (other == this)
            {
                return(true);
            }
            ///if (hashCode() != other.hashCode()) return false;

            if (other is ClassicalTermLink)
            {
                ClassicalTermLink t = (ClassicalTermLink)other;

                if (type != t.type)
                {
                    return(false);
                }
                if (!(t.index == index))
                {
                    return(false);
                }

                TermOrCompoundTermOrVariableReferer tt = t.target;
                if (target == null)
                {
                    if (tt != null)
                    {
                        return(false);
                    }
                }
                else if (tt == null)
                {
                    if (target != null)
                    {
                        return(false);
                    }
                }
                else if (!TermOrCompoundTermOrVariableReferer.isSameWithId(target, t.target))
                {
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Пример #2
0
        // see https://github.com/opennars/opennars/blob/df5878a54a456c9a692004ae770d4613d31a757d/nars_core/nars/entity/TaskLink.java#L154

        /**
         * To check whether a TaskLink should use a TermLink, return false if they interacted recently
         * <p>
         * called in TermLinkBag only
         *
         * /param termLink The TermLink to be checked
         * /param currentTime The current time
         * /return Whether they are novel to each other
         */
        public bool checkNovel(ClassicalTermLink termLink, long currentTime)
        {
            TermOrCompoundTermOrVariableReferer bTerm = termLink.target;

            if (TermOrCompoundTermOrVariableReferer.isSameWithId(bTerm, targetTask.sentence.term))
            {
                return(false);
            }
            ClassicalTermLink linkKey = termLink.name;

            // iterating the FIFO deque from oldest (first) to newest (last)
            for (int i = 0; i < records.Count; i++)
            {
                Record iRecord = records[i];
                if (linkKey.checkEqual(iRecord.link))
                {
                    if (currentTime < iRecord.time + Parameters.NOVELTY_HORIZON)
                    {
                        // too recent, not novel
                        return(false);
                    }
                    else
                    {
                        // happened long enough ago that we have forgotten it somewhat, making it seem more novel
                        iRecord.time = currentTime;

                        records.RemoveAt(i);
                        i--;

                        records.Add(iRecord);
                        return(true);
                    }
                }
            }

            // keep recordedLinks queue a maximum finite size
            while (records.Count + 1 >= recordLength)
            {
                records.RemoveAt(0); // remove first
            }

            // add knowledge reference to recordedLinks
            records.Add(new Record(linkKey, currentTime));

            return(true);
        }
Пример #3
0
 public bool equalsContent(ClassicalSentence s2)
 {
     return(TermOrCompoundTermOrVariableReferer.isSameWithId(term, s2.term));
 }