Search in sources :

Example 6 with TermLink

use of nars.entity.TermLink in project opennars by opennars.

the class DefaultGraphizer method onConcept.

@Override
public void onConcept(NARGraph g, Concept c) {
    Term t = c.term;
    if (this.filterBox != null && terms.size() < nConcepts.get() * ((double) Parameters.CONCEPT_BAG_SIZE) && c.getPriority() > this.conceptPriorityThreshold.get() && ("".equals(this.filterBox.getText()) || t.toString().contains(this.filterBox.getText()))) {
        g.addVertex(c);
        terms.put(c.term, c);
    } else {
        return;
    }
    if (includeTermLinks) {
        for (TermLink x : c.termLinks) {
            termLinks.put(x, c);
        }
    }
    if (includeTaskLinks) {
        for (TaskLink x : c.taskLinks) {
            if (x.getPriority() > this.taskPriorityThreshold.get()) {
                taskLinks.put(x, c);
            }
        }
    }
    if (includeTermContent) {
        g.addVertex(t);
        g.addEdge(c, c.term, new NARGraph.TermContent());
    }
    if (includeBeliefs) {
        for (final Task beliefT : c.beliefs) {
            Sentence belief = beliefT.sentence;
            onBelief(belief);
            sentenceTerms.put(belief, c);
        // g.addVertex(c);
        // g.addVertex(belief);
        // g.addEdge(belief, c, new SentenceContent());
        // TODO extract to onBelief
        // TODO check if kb.getContent() is never distinct from c.getTerm()
        /*if (c.term.equals(belief.content)) {
                continue;
                }
                addTerm(g, belief.content);
                g.addEdge(term, belief.content, new TermBelief());*/
        }
    }
    if (includeQuestions) {
        for (final Task q : c.getQuestions()) {
            if (c.term.equals(q.getTerm())) {
                continue;
            }
            // TODO extract to onQuestion
            g.addVertex(q);
            // TODO q.getParentBelief()
            // TODO q.getParentTask()
            g.addEdge(c, q, new NARGraph.TermQuestion());
            onQuestion(q);
        }
    }
}
Also used : TermLink(nars.entity.TermLink) Task(nars.entity.Task) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) TaskLink(nars.entity.TaskLink) Sentence(nars.entity.Sentence)

Example 7 with TermLink

use of nars.entity.TermLink in project opennars by opennars.

the class LocalRules method solutionEval.

/* ----- Functions used both in direct and indirect processing of tasks ----- */
/**
 * Evaluate the quality of a belief as a solution to a problem, then reward
 * the belief and de-prioritize the problem
 *
 * @param problem The problem (question or goal) to be solved
 * @param solution The belief as solution
 * @param task The task to be immediately processed, or null for continued
 * process
 * @return The budget for the new task which is the belief activated, if
 * necessary
 */
public static BudgetValue solutionEval(final Task problem, final Sentence solution, Task task, final nars.control.DerivationContext nal) {
    if (problem.sentence.punctuation != solution.punctuation && solution.term.hasVarQuery()) {
        return null;
    }
    BudgetValue budget = null;
    boolean feedbackToLinks = false;
    if (task == null) {
        task = nal.getCurrentTask();
        feedbackToLinks = true;
    }
    boolean judgmentTask = task.sentence.isJudgment();
    // here its whether its a what or where question for budget adjustment
    boolean rateByConfidence = problem.getTerm().hasVarQuery();
    final float quality = solutionQuality(rateByConfidence, problem, solution, nal.mem());
    if (problem.sentence.isGoal()) {
        nal.memory.emotion.adjustSatisfaction(quality, task.getPriority(), nal);
    }
    if (judgmentTask) {
        task.incPriority(quality);
    } else {
        // +goal satisfication is a matter of degree - https://groups.google.com/forum/#!topic/open-nars/ZfCM416Dx1M
        float taskPriority = task.getPriority();
        budget = new BudgetValue(UtilityFunctions.or(taskPriority, quality), task.getDurability(), BudgetFunctions.truthToQuality(solution.truth));
        task.setPriority(Math.min(1 - quality, taskPriority));
    }
    if (feedbackToLinks) {
        TaskLink tLink = nal.getCurrentTaskLink();
        tLink.setPriority(Math.min(1 - quality, tLink.getPriority()));
        TermLink bLink = nal.getCurrentBeliefLink();
        bLink.incPriority(quality);
    }
    return budget;
}
Also used : BudgetValue(nars.entity.BudgetValue) TermLink(nars.entity.TermLink) TaskLink(nars.entity.TaskLink)

Example 8 with TermLink

use of nars.entity.TermLink in project opennars by opennars.

the class BudgetFunctions method revise.

/**
 * Evaluate the quality of a revision, then de-prioritize the premises
 *
 * @param tTruth The truth value of the judgment in the task
 * @param bTruth The truth value of the belief
 * @param truth The truth value of the conclusion of revision
 * @return The budget for the new task
 */
static BudgetValue revise(final TruthValue tTruth, final TruthValue bTruth, final TruthValue truth, final boolean feedbackToLinks, final nars.control.DerivationContext nal) {
    final float difT = truth.getExpDifAbs(tTruth);
    final Task task = nal.getCurrentTask();
    task.decPriority(1 - difT);
    task.decDurability(1 - difT);
    if (feedbackToLinks) {
        TaskLink tLink = nal.getCurrentTaskLink();
        tLink.decPriority(1 - difT);
        tLink.decDurability(1 - difT);
        TermLink bLink = nal.getCurrentBeliefLink();
        final float difB = truth.getExpDifAbs(bTruth);
        bLink.decPriority(1 - difB);
        bLink.decDurability(1 - difB);
    }
    float dif = truth.getConfidence() - max(tTruth.getConfidence(), bTruth.getConfidence());
    float priority = or(dif, task.getPriority());
    float durability = aveAri(dif, task.getDurability());
    float quality = truthToQuality(truth);
    return new BudgetValue(priority, durability, quality);
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) TermLink(nars.entity.TermLink) TaskLink(nars.entity.TaskLink)

Aggregations

TermLink (nars.entity.TermLink)8 TaskLink (nars.entity.TaskLink)5 Task (nars.entity.Task)4 BudgetValue (nars.entity.BudgetValue)3 Sentence (nars.entity.Sentence)3 CompoundTerm (nars.language.CompoundTerm)2 Term (nars.language.Term)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Concept (nars.entity.Concept)1 Item (nars.entity.Item)1 Events (nars.io.events.Events)1