Exemple #1
0
        // see https://github.com/opennars/opennars/blob/c3564fc6c176ceda168a9631d27a07be05faff32/nars_core/nars/entity/Concept.java#L1191

        /**
         * Replace default to prevent repeated inference, by checking TaskLink
         *
         * /param taskLink The selected TaskLink
         * /param time The current time
         * /return The selected TermLink
         */
        public ClassicalTermLink selectTermLink(ClassicalTaskLink taskLink, long time)
        {
            maintainDisappointedAnticipations();
            uint toMatch = Parameters.TERM_LINK_MAX_MATCHED;

            for (int i = 0; (i < toMatch) && (termLinks.size > 0); i++)
            {
                ClassicalTermLink termLink = termLinks.takeNext();
                if (termLink == null)
                {
                    break;
                }

                if (taskLink.checkNovel(termLink, time))
                {
                    //return, will be re-inserted in caller method when finished processing it
                    return(termLink);
                }

                returnTermLink(termLink);
            }
            return(null);
        }
Exemple #2
0
        /**
         * Insert a TaskLink into the TaskLink bag for indirect processing
         *
         * /param taskLink The termLink to be inserted
         */
        public bool insertTaskLink(ClassicalTaskLink taskLink, DerivationContext nal)
        {
            ClassicalTask target = taskLink.targetTask;
            ClassicalTask ques   = taskLink.targetTask;

            // TODO< implement if variables are implemented >

            /* commented and not translated because variables not implemented
             * if((ques.sentence.isQuestion() || ques.sentence.isQuest()) && ques.getTerm().hasVarQuery()) { //ok query var, search
             *  boolean newAnswer = false;
             *
             *  for(TaskLink t : this.taskLinks) {
             *
             *      Term[] u = new Term[] { ques.getTerm(), t.getTerm() };
             *      if(!t.getTerm().hasVarQuery() && Variables.unify(Symbols.VAR_QUERY, u)) {
             *          Concept c = nal.memory.concept(t.getTerm());
             *          if(c != null && ques.sentence.isQuestion() && c.beliefs.size() > 0) {
             *              final Task taskAnswer = c.beliefs.get(0);
             *              if(taskAnswer!=null) {
             *                  newAnswer |= trySolution(taskAnswer.sentence, ques, nal, false); //order important here
             *              }
             *          }
             *          if(c != null && ques.sentence.isQuest() &&  c.desires.size() > 0) {
             *              final Task taskAnswer = c.desires.get(0);
             *              if(taskAnswer!=null) {
             *                  newAnswer |= trySolution(taskAnswer.sentence, ques, nal, false); //order important here
             *              }
             *          }
             *      }
             *  }
             *  if(newAnswer && ques.isInput()) {
             *      memory.emit(Events.Answer.class, ques, ques.getBestSolution());
             *  }
             * }*/

            // TODO< implement if variables are implemented >

            /* commented and not translated because variables not implemented
             * //belief side:
             * Task t = taskLink.getTarget();
             * if(t.sentence.isJudgment()) { //ok query var, search
             *  for(TaskLink quess: this.taskLinks) {
             *      ques = quess.getTarget();
             *      if((ques.sentence.isQuestion() || ques.sentence.isQuest()) && ques.getTerm().hasVarQuery()) {
             *          boolean newAnswer = false;
             *          Term[] u = new Term[] { ques.getTerm(), t.getTerm() };
             *          if(!t.getTerm().hasVarQuery() && Variables.unify(Symbols.VAR_QUERY, u)) {
             *              Concept c = nal.memory.concept(t.getTerm());
             *              if(c != null && ques.sentence.isQuestion() && c.beliefs.size() > 0) {
             *                  final Task taskAnswer = c.beliefs.get(0);
             *                  if(taskAnswer!=null) {
             *                      newAnswer |= trySolution(taskAnswer.sentence, ques, nal, false); //order important here
             *                  }
             *              }
             *              if(c != null && ques.sentence.isQuest() &&  c.desires.size() > 0) {
             *                  final Task taskAnswer = c.desires.get(0);
             *                  if(taskAnswer!=null) {
             *                      newAnswer |= trySolution(taskAnswer.sentence, ques, nal, false); //order important here
             *                  }
             *              }
             *          }
             *          if(newAnswer && ques.isInput()) {
             *              memory.emit(Events.Answer.class, ques, ques.getBestSolution());
             *          }
             *      }
             *  }
             * }
             */

            { // handle max per concept
                // if taskLinks already contain a certain amount of tasks with same content then one has to go
                bool              isEternal       = target.sentence.stamp.isEternal;
                int               nSameContent    = 0;
                float             lowest_priority = float.MaxValue;
                ClassicalTaskLink lowest          = null;
                foreach (ClassicalTaskLink tl in taskLinks)
                {
                    ClassicalSentence s = tl.targetTask.sentence;
                    if (s.term == taskLink.targetTask.sentence.term && s.stamp.isEternal == isEternal)
                    {
                        nSameContent++;                           // same content and occurrence-type, so count +1
                        if (tl.budget.priority < lowest_priority) //the current one has lower priority so save as lowest
                        {
                            lowest_priority = tl.budget.priority;
                            lowest          = tl;
                        }
                        if (nSameContent > Parameters.TASKLINK_PER_CONTENT)    // ok we reached the maximum so lets delete the lowest
                        {
                            taskLinks.takeElement(lowest);
                            // commented because events not implemented yet  memory.emit(TaskLinkRemove.class, lowest, this);
                            break;
                        }
                    }
                }
            }

            ClassicalTaskLink removed = taskLinks.putIn(taskLink);

            if (removed != null)
            {
                if (removed == taskLink)
                {
                    // commented because events not implemented yet memory.emit(TaskLinkRemove.class, taskLink, this);
                    return(false);
                }
                else
                {
                    // commented because events not implemented yet memory.emit(TaskLinkRemove.class, removed, this);
                }

                removed.wasDiscarded();
            }
            // commented because events not implemented yet memory.emit(TaskLinkAdd.class, taskLink, this);
            return(true);
        }