/** * Put an item back into the itemTable * <p> * The only place where the forgetting rate is applied * * \param oldItem The Item to put back * \return the item which was removed, or null if none removed */ public E putBack(E oldItem, float forgetCycles, Memory m) { float relativeThreshold = Parameters.FORGET_QUALITY_RELATIVE; BudgetFunctions.applyForgetting(oldItem.budget, getForgetCycles(forgetCycles, oldItem), relativeThreshold); return(putIn(oldItem)); }
/** * Link to a new task from all relevant concepts for continued processing in * the near future for unspecified time. * <p> * The only method that calls the TaskLink constructor. * * /param task The task to be linked * /param content The content of the task */ private static void linkToTask(DerivationContext ctx, ClassicalConcept @this, ClassicalTask task) { ClassicalBudgetValue taskBudget = task.budget; @this.insertTaskLink( new ClassicalTaskLink( task, null, taskBudget, Parameters.TERM_LINK_RECORD_LENGTH), ctx); // link type: SELF if (!TermUtilities.isTermCompoundTerm(@this.term)) { return; } if (@this.termLinkTemplates.isEmpty()) { return; } ClassicalBudgetValue subBudget = BudgetFunctions.distributeAmongLinks(taskBudget, @this.termLinkTemplates.Count); if (!subBudget.isAboveThreshold) { return; } // else here for (int t = 0; t < @this.termLinkTemplates.Count; t++) { ClassicalTermLink termLink = @this.termLinkTemplates[t]; if (termLink.type == ClassicalTermLink.EnumType.TEMPORAL) { continue; } TermOrCompoundTermOrVariableReferer componentTerm = termLink.target; ClassicalConcept componentConcept = @this.memory.conceptualize(subBudget, componentTerm); if (componentConcept != null) { componentConcept.insertTaskLink( new ClassicalTaskLink( task, termLink, subBudget, Parameters.TERM_LINK_RECORD_LENGTH), ctx); } } @this.buildTermLinks(taskBudget); // recursively insert TermLink }
// from https://github.com/opennars/opennars/blob/62c814fb0f3e474a176515103394049b2887ec29/nars_core/nars/entity/Concept.java#L740 /** * Add a new belief (or goal) into the table Sort the beliefs/desires by * rank, and remove redundant or low rank one * * \param newSentence The judgment to be processed * \param table The table to be revised * \param capacity The capacity of the table * \return whether table was modified */ public static ClassicalTask addToTable(ClassicalTask newTask, IList <ClassicalTask> table, uint capacity, bool rankTruthExpectation) { ClassicalSentence newSentence = newTask.sentence; float rank1 = BudgetFunctions.rankBelief(newSentence, rankTruthExpectation); // for the new isBelief float rank2; int i; for (i = 0; i < table.Count; i++) { ClassicalSentence judgment2 = table[i].sentence; rank2 = BudgetFunctions.rankBelief(judgment2, rankTruthExpectation); if (rank1 >= rank2) { if (newSentence.checkEquivalentTo(judgment2)) { //System.out.println(" ---------- Equivalent Belief: " + newSentence + " == " + judgment2); return(null); } table.Insert(i, newTask); break; } } if (table.Count == capacity) { // nothing } else if (table.Count > capacity) { ClassicalTask removed = table[table.Count - 1]; table.RemoveAt(table.Count - 1); return(removed); } else if (i == table.Count) // branch implies implicit table.size() < capacity { table.Add(newTask); } return(null); }
/** * Merge one BudgetValue into another * @param that The other Budget */ public void merge(ClassicalBudgetValue that) { BudgetFunctions.merge(this, that); }