/** * 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 }
// see https://github.com/opennars/opennars/blob/4515f1d8e191a1f097859decc65153287d5979c5/nars_core/nars/entity/Concept.java#L923 /** * Recursively build TermLinks between a compound and its components * <p> * called only from Memory.continuedProcess * * /param taskBudget The BudgetValue of the task */ public void buildTermLinks(ClassicalBudgetValue taskBudget) { if (termLinkTemplates.Count == 0) { return; } ClassicalBudgetValue subBudget = taskBudget; // HACK // uncommented because not yet implemented, TODO distributeAmongLinks(taskBudget, termLinkTemplates.size()); if (!subBudget.isAboveThreshold) { return; } foreach (ClassicalTermLink template in termLinkTemplates) { if (template.type == ClassicalTermLink.EnumType.TRANSFORM) { continue; } TermOrCompoundTermOrVariableReferer target = template.target; ClassicalConcept concept = memory.conceptualize(taskBudget, target); if (concept == null) { continue; } // this termLink to that insertTermLink(ClassicalTermLink.makeFromTemplate(target, template, subBudget)); // that termLink to this concept.insertTermLink(ClassicalTermLink.makeFromTemplate(term, template, subBudget)); if (TermUtilities.isTermCompoundTerm(target) && template.type != ClassicalTermLink.EnumType.TEMPORAL) { concept.buildTermLinks(subBudget); } } }
// function prototype and some of the methode is like https://github.com/opennars/opennars/blob/4515f1d8e191a1f097859decc65153287d5979c5/nars_core/nars/inference/RuleTables.java#L73 internal static void reason( ClassicalTaskLink taskLink, ClassicalTermLink beliefLink, DerivationContext ctx ) { { // debugging int taskId = taskLink.targetTask.name.term.getAtomicOrTerm; int beliefId = beliefLink.target.getAtomicOrTerm; if (taskId == 300002 && beliefId == 300004) { int breakpointHere2 = 1; } else if (taskId == 300004 && beliefId == 300002) { int breakpointHere2 = 1; } int breakpointHere1 = 1; } Memory memory = ctx.memory; memory.emotion.manageBusy(ctx); ClassicalTask task = ctx.currentTask; ClassicalSentence taskSentence = task.sentence; TermOrCompoundTermOrVariableReferer taskTerm = taskSentence.term; TermOrCompoundTermOrVariableReferer beliefTerm = beliefLink.target; // commented because not jet translated //if (equalSubTermsInRespectToImageAndProduct(taskTerm, beliefTerm)) // return; ClassicalConcept beliefConcept = memory.translateTermToConcept(beliefTerm); ClassicalSentence belief = (beliefConcept != null) ? beliefConcept.getBelief(ctx, task) : null; ctx.currentBelief = belief; if (belief != null) { beliefTerm = belief.term; //because interval handling that differs on conceptual level // too restrictive, its checked for non-deductive inference rules in derivedTask (also for single prem) if (Stamp.checkBaseOverlap(task.sentence.stamp, belief.stamp)) { ctx.evidentalOverlap = true; if (!task.sentence.stamp.isEternal || !belief.stamp.isEternal) { return; // only allow for eternal reasoning for now to prevent derived event floods } //return; // preparisons are made now to support this nicely } // comment out for recursive examples, this is for the future, it generates a lot of potentially useless tasks //ctx.emit(Events.BeliefReason.class, belief, beliefTerm, taskTerm, nal); if (LocalRules.match(task, belief, ctx)) // new tasks resulted from the match, so return { return; } } // current belief and task may have changed, so set again: ctx.currentBelief = belief; ctx.currentTask = task; // HACK< derivation must be made by combining compounds > if (!TermUtilities.isTermCompoundTerm(taskTerm) || !TermUtilities.isTermCompoundTerm(beliefTerm)) { return; } // derive and create new tasks for the results { IList <TemporaryDerivedCompoundWithDecorationAndTruth> derivedCompoundTermsWithDecorationAndTruth = new List <TemporaryDerivedCompoundWithDecorationAndTruth>(); bool insert = true; DeriverCaller.deriverCaller( ctx.compoundAndTermContext, ctx.compoundAndTermContext.translateToCompoundChecked(taskTerm), ctx.compoundAndTermContext.translateToCompoundChecked(beliefTerm), out derivedCompoundTermsWithDecorationAndTruth, insert); // translate derivedCompoundTermsWithDecorationAndTruth to tasks and add them // for this we have to call DerivationContext.doublePremiseTask() to generate the tasks foreach (var iDerivedWithDecorationAndTruth in derivedCompoundTermsWithDecorationAndTruth) { TermOrCompoundTermOrVariableReferer content = iDerivedWithDecorationAndTruth.derivedCompoundWithDecoration.termReferer; bool temporalInduction = false; // TODO< decide by rule? from the deriver? > bool overlapAllowed = false; // TODO< decide by rule? from the deriver? > TruthValue truth = null; truth = RuleTable.calcTruthDoublePremise(task.sentence.truth, belief.truth, iDerivedWithDecorationAndTruth.truthfunction); ClassicalBudgetValue budget = new ClassicalBudgetValue(0.5f, 0.5f, 0.5f); // TODO< calculate budget by table > ctx.doublePremiseTask(content, truth, budget, temporalInduction, overlapAllowed ); } } }