/** * /param t The target Task * /param template The TermLink template * /param budget The budget */ public ClassicalTaskLink(ClassicalTask t, ClassicalTermLink template, ClassicalBudgetValue budget, uint recordLength) : base(budget) { this.type = template == null ? ClassicalTermLink.EnumType.SELF : template.type; this.index = template == null ? null : template.index; this.targetTask = t; this.recordLength = recordLength; }
// 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); }
/** * Insert a TermLink into the TermLink bag * <p> * called from buildTermLinks only * * /param termLink The termLink to be inserted */ public bool insertTermLink(ClassicalTermLink termLink) { ClassicalTermLink removed = termLinks.putIn(termLink); if (removed != null) { if (removed == termLink) { //OpenNARS memory.emit(TermLinkRemove.class, termLink, this); return(false); } else { //OpenNARS memory.emit(TermLinkRemove.class, removed, this); } } //OpenNARS memory.emit(TermLinkAdd.class, termLink, this); return(true); }
// 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); } } }
// 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); }
public Record(ClassicalTermLink link, long time) { this.link = link; this.time = time; }
// see https://github.com/opennars/opennars/blob/c3564fc6c176ceda168a9631d27a07be05faff32/nars_core/nars/entity/Concept.java#L1212 public void returnTermLink(ClassicalTermLink termLink) { termLinks.putBack(termLink, memory.convertDurationToCycles(memory.param.termLinkForgetDurations), memory); }