public static ClassicalTask make(MakeParameters parameters) { ClassicalTask created = new ClassicalTask(parameters.sentence); created.budget = parameters.budget; created.parentTask = new WeakReference <ClassicalTask>(parameters.parentTask); created.parentBelief = new WeakReference <ClassicalSentence>(parameters.parentBelief); created.bestSolution = parameters.bestSolution; return(created); }
// from https://github.com/opennars/opennars/blob/4515f1d8e191a1f097859decc65153287d5979c5/nars_core/nars/entity/Concept.java#L345 public static void addToTable(ClassicalTask task, bool rankTruthExpectation, IList <ClassicalTask> table, uint max, /*final Class eventAdd*/ object eventAdd /*final Class eventRemove, */, object eventRemove /*final Object... extraEventArguments*/) { int preSize = table.Count; ClassicalTask removedT; ClassicalSentence removed = null; removedT = addToTable(task, table, max, rankTruthExpectation); if (removedT != null) { removed = removedT.sentence; } /* * if (removed != null) { * memory.event.emit(eventRemove, this, removed, task, extraEventArguments); * } * if ((preSize != table.size()) || (removed != null)) { * memory.event.emit(eventAdd, this, task, extraEventArguments); * } */ }
// 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); }
// 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); }
/** * 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); }