Search in sources :

Example 56 with Task

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

the class ConceptMonitor method strongestProjectedEternalizedBelief.

public static Sentence strongestProjectedEternalizedBelief(NAR nar, String st) {
    Concept c = ConceptMonitor.concept(nar, st);
    if (c != null) {
        for (Task t : c.beliefs) {
            Sentence s = t.sentence;
            Sentence projected = s.projection(nar.memory.time(), nar.memory.time());
            return projected;
        }
    }
    return null;
}
Also used : Concept(nars.entity.Concept) Task(nars.entity.Task) Sentence(nars.entity.Sentence)

Example 57 with Task

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

the class PerceptionAccel method event.

@Override
public void event(Class event, Object[] args) {
    if (event == Events.InduceSucceedingEvent.class) {
        // todo misleading event name, it is for a new incoming event
        Task newEvent = (Task) args[0];
        if (newEvent.sentence.punctuation == Symbols.JUDGMENT_MARK) {
            eventbuffer.add(newEvent);
            while (eventbuffer.size() > cur_maxlen + 1) {
                eventbuffer.remove(0);
            }
            DerivationContext nal = (DerivationContext) args[1];
            perceive(nal);
        }
    }
    if (event == Events.ConceptForget.class) {
        Concept forgot = (Concept) args[0];
        handleConjunctionSequence(forgot.term, false);
    }
    if (event == Events.ConceptNew.class) {
        Concept newC = (Concept) args[0];
        handleConjunctionSequence(newC.term, true);
    }
}
Also used : Concept(nars.entity.Concept) Task(nars.entity.Task) DerivationContext(nars.control.DerivationContext) Events(nars.io.events.Events)

Example 58 with Task

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

the class NARGraphDisplay method vertex.

@Override
public void vertex(AbstractGraphVis<V, E> g, VertexVis<V, E> v) {
    float alpha = 0.9f;
    V o = v.getVertex();
    v.shape = Shape.Ellipse;
    float rad = 1f;
    if (o instanceof Sentence) {
        Sentence kb = (Sentence) o;
        if (kb.truth != null) {
            float confidence = kb.truth.getConfidence();
            alpha = 0.5f + 0.5f * confidence;
        }
    // Term t = ((Sentence) o).content;
    // rad = (float) (Math.log(1 + 2 + confidence));
    } else if (o instanceof Task) {
        Task ta = (Task) o;
        rad = 2.0f + ta.getPriority() * 2.0f;
        alpha = ta.getDurability();
        v.shape = Shape.Rectangle;
    } else if (o instanceof Concept) {
        Concept co = (Concept) o;
        // Term t = co.term;
        rad = (2 + 6 * co.budget.summary());
        if (!co.beliefs.isEmpty()) {
            float confidence = co.beliefs.get(0).sentence.truth.getConfidence();
            alpha = 0.5f + 0.5f * confidence;
        }
    // v.stroke = 5;
    } else if (o instanceof Term) {
        Term t = (Term) o;
    // rad = (float) (Math.log(1 + 2 + t.getComplexity()));
    }
    Object x = o;
    if (!(x instanceof Concept)) {
        if (!(x instanceof Task)) {
            if (x instanceof Concept)
                x = ((Concept) o).getTerm();
            // Video.hashFloat(x.hashCode());
            float hue = 0.0f;
            if (x instanceof Task)
                hue = 0.4f;
            float brightness = 0.33f + 0.66f * rad / 9.0f;
            float saturation = 0.33f + 0.66f * rad / 9.0f;
            // brightness*=brightness;
            // saturation*=saturation;
            v.color = Video.colorHSB(hue, saturation, brightness, 0.25f + (0.75f * alpha));
        } else if (x instanceof Task) {
            float rr = 0.5f, gg = 0.5f, bb = 0.5f, aa = 1.0f;
            Task t = (Task) o;
            if (t.sentence.truth != null) {
                float conf = t.sentence.truth.getConfidence();
                float freq = t.sentence.truth.getFrequency();
                aa = 0.25f + conf * 0.75f;
                float evidence = TruthFunctions.c2w(conf);
                float positive_evidence_in_0_1 = TruthFunctions.w2c(evidence * freq);
                float negative_evidence_in_0_1 = TruthFunctions.w2c(evidence * (1.0f - freq));
                rr = positive_evidence_in_0_1;
                bb = negative_evidence_in_0_1;
                gg = 0.0f;
            }
            Color HSB = new Color(rr, gg, bb, aa);
            float[] hsb = new float[3];
            Color.RGBtoHSB((int) (rr * 255.0f), (int) (gg * 255.0f), (int) (bb * 255.0f), hsb);
            v.color = Video.colorHSB(hsb[0], hsb[1], hsb[2], aa);
        }
    } else if (x instanceof Concept) {
        Concept conc = ((Concept) o);
        float rr = 0.5f, gg = 0.5f, bb = 0.5f, aa = 1.0f;
        if (conc.beliefs.size() > 0) {
            Sentence sent = conc.beliefs.get(0).sentence;
            float conf = sent.truth.getConfidence();
            float freq = sent.truth.getFrequency();
            aa = 0.25f + conf * 0.75f;
            float evidence = TruthFunctions.c2w(conf);
            float positive_evidence_in_0_1 = TruthFunctions.w2c(evidence * freq);
            float negative_evidence_in_0_1 = TruthFunctions.w2c(evidence * (1.0f - freq));
            rr = positive_evidence_in_0_1;
            bb = negative_evidence_in_0_1;
            gg = 0.0f;
        }
        Color HSB = new Color(rr, gg, bb, aa);
        float[] hsb = new float[3];
        Color.RGBtoHSB((int) (rr * 255.0f), (int) (gg * 255.0f), (int) (bb * 255.0f), hsb);
        v.color = Video.colorHSB(hsb[0], hsb[1], hsb[2], aa);
    }
    String label;
    if (o instanceof Concept) {
        label = ((Concept) o).term.toString();
    } else if (o instanceof Task) {
        label = ((Task) o).sentence.toString();
    } else {
        label = o.toString();
    }
    if (label.length() > maxLabelLen) {
        label = label.substring(0, maxLabelLen - 2) + "..";
    }
    v.label = label;
    v.speed = nodeSpeed;
    v.radius = rad * nodeSize;
    v.textColor = defaultTextColor;
    v.textScale = textSize;
}
Also used : Concept(nars.entity.Concept) Task(nars.entity.Task) Color(java.awt.Color) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 59 with Task

use of nars.entity.Task 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 60 with Task

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

Aggregations

Task (nars.entity.Task)78 Sentence (nars.entity.Sentence)54 Term (nars.language.Term)37 BudgetValue (nars.entity.BudgetValue)36 TruthValue (nars.entity.TruthValue)34 Stamp (nars.entity.Stamp)25 CompoundTerm (nars.language.CompoundTerm)21 Concept (nars.entity.Concept)18 Conjunction (nars.language.Conjunction)11 Statement (nars.language.Statement)10 Events (nars.io.events.Events)8 Inheritance (nars.language.Inheritance)8 Interval (nars.language.Interval)8 Narsese (nars.io.Narsese)6 SetExt (nars.language.SetExt)6 SetInt (nars.language.SetInt)6 ArrayList (java.util.ArrayList)5 DerivationContext (nars.control.DerivationContext)5 Implication (nars.language.Implication)5 Memory (nars.storage.Memory)5