Search in sources :

Example 1 with TaskLink

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

the class NARGraphDisplay method edge.

@Override
public void edge(AbstractGraphVis<V, E> g, EdgeVis<V, E> e) {
    E edge = e.edge;
    int color = defaultEdgeColor;
    float thickness = lineWidth;
    if (edge instanceof NARGraph.TermLinkEdge) {
        TermLink t = ((NARGraph.TermLinkEdge) edge).getObject();
        float p = t.getPriority();
        thickness = (1 + p) * lineWidth;
        color = Video.color(255f * (0.5f + p * 0.5f), 255f * (0.5f + p * 0.5f), 125f, 255f * (0.5f + p * 0.5f));
    }
    if (edge instanceof NARGraph.TaskLinkEdge) {
        TaskLink t = ((NARGraph.TaskLinkEdge) edge).getObject();
        float p = t.targetTask.getPriority();
        thickness = (1 + p) * lineWidth;
        color = Video.color(125f, 255f * (0.5f + p * 0.5f), 125f, 255f * (0.5f + p * 0.5f));
    }
    e.color = color;
    e.thickness = thickness;
}
Also used : TermLink(nars.entity.TermLink) TaskLink(nars.entity.TaskLink)

Example 2 with TaskLink

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

the class DefaultGraphizer method onFinish.

@Override
public void onFinish(NARGraph g) {
    if (includeSyntax > 0) {
        for (final Term a : terms.keySet()) {
            if (a instanceof CompoundTerm) {
                CompoundTerm c = (CompoundTerm) a;
                g.addVertex(c.operator());
                g.addEdge(c.operator(), c, new NARGraph.TermType());
                if (includeSyntax - 1 > 0) {
                    recurseTermComponents(g, c, includeSyntax - 1);
                }
            }
        }
    }
    if (includeTermContent) {
        for (final Term a : terms.keySet()) {
            for (final Term b : terms.keySet()) {
                if (a == b) {
                    continue;
                }
                if (a.containsTerm(b)) {
                    g.addVertex(a);
                    g.addVertex(b);
                    g.addEdge(a, b, new NARGraph.TermContent());
                }
                if (b.containsTerm(a)) {
                    g.addVertex(a);
                    g.addVertex(b);
                    g.addEdge(b, a, new NARGraph.TermContent());
                }
            }
        }
    }
    if (includeDerivations && includeBeliefs) {
        for (final Map.Entry<Sentence, Concept> s : sentenceTerms.entrySet()) {
            final Sentence derivedSentence = s.getKey();
            final Concept derived = s.getValue();
            for (final Map.Entry<Sentence, Concept> t : sentenceTerms.entrySet()) {
                if (s == t) {
                    continue;
                }
                final Sentence deriverSentence = t.getKey();
                final Concept deriver = t.getValue();
                if (derived == deriver) {
                    continue;
                }
            }
        }
    }
    if (includeTermLinks) {
        for (Map.Entry<TermLink, Concept> et : termLinks.entrySet()) {
            TermLink t = et.getKey();
            Concept from = et.getValue();
            Concept to = terms.get(t.target);
            if (to != null) {
                g.addEdge(from, to, new NARGraph.TermLinkEdge(t));
            }
        }
    }
    if (includeTaskLinks) {
        for (Map.Entry<TaskLink, Concept> et : taskLinks.entrySet()) {
            TaskLink t = et.getKey();
            if (this.taskPriorityThreshold != null && t.getPriority() > this.taskPriorityThreshold.get()) {
                Concept from = et.getValue();
                if (t.targetTask != null) {
                    Task theTask = t.targetTask;
                    if (!g.containsVertex(theTask)) {
                        g.addVertex(theTask);
                        Term term = theTask.getTerm();
                        if (term != null) {
                            Concept c = terms.get(term);
                            if (c != null) {
                                if (g.containsVertex(c)) {
                                    g.addVertex(c);
                                }
                                g.addEdge(c, theTask, new NARGraph.TermContent());
                            }
                        }
                        onTask(theTask);
                    }
                    g.addEdge(from, t.targetTask, new NARGraph.TaskLinkEdge(t));
                }
            }
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) Concept(nars.entity.Concept) TermLink(nars.entity.TermLink) Task(nars.entity.Task) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) TaskLink(nars.entity.TaskLink) Map(java.util.Map) HashMap(java.util.HashMap) Sentence(nars.entity.Sentence)

Example 3 with TaskLink

use of nars.entity.TaskLink 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 4 with TaskLink

use of nars.entity.TaskLink 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 5 with TaskLink

use of nars.entity.TaskLink 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

TaskLink (nars.entity.TaskLink)5 TermLink (nars.entity.TermLink)5 Task (nars.entity.Task)3 BudgetValue (nars.entity.BudgetValue)2 Sentence (nars.entity.Sentence)2 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