Search in sources :

Example 21 with Concept

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

the class TermTest method testConceptInstancing.

@Test
public void testConceptInstancing() throws Narsese.InvalidInputException {
    NAR n = new NAR();
    String statement1 = "<a --> b>.";
    Term a = np.parseTerm("a");
    assertTrue(a != null);
    Term a1 = np.parseTerm("a");
    assertTrue(a.equals(a1));
    n.addInput(statement1);
    n.cycles(4);
    n.addInput(" <a  --> b>.  ");
    n.cycles(1);
    n.addInput(" <a--> b>.  ");
    n.cycles(1);
    String statement2 = "<a --> c>.";
    n.addInput(statement2);
    n.cycles(4);
    Term a2 = np.parseTerm("a");
    assertTrue(a2 != null);
    Concept ca = n.memory.concept(a2);
    assertTrue(ca != null);
    assertEquals(true, n.memory.concepts.iterator().hasNext());
}
Also used : Concept(nars.entity.Concept) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) NAR(nars.main.NAR) Test(org.junit.Test)

Example 22 with Concept

use of nars.entity.Concept 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 23 with Concept

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

the class BagOperationsTest method makeConcept.

static Concept makeConcept(String name, float priority) {
    BudgetValue budg = new BudgetValue(priority, priority, priority);
    Concept s = new Concept(budg, new Term(name), nar.memory);
    return s;
}
Also used : BudgetValue(nars.entity.BudgetValue) Concept(nars.entity.Concept) Term(nars.language.Term)

Example 24 with Concept

use of nars.entity.Concept 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 25 with Concept

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

Aggregations

Concept (nars.entity.Concept)30 Task (nars.entity.Task)18 Term (nars.language.Term)14 Sentence (nars.entity.Sentence)10 BudgetValue (nars.entity.BudgetValue)7 Events (nars.io.events.Events)6 CompoundTerm (nars.language.CompoundTerm)6 TruthValue (nars.entity.TruthValue)5 Interval (nars.language.Interval)4 ArrayList (java.util.ArrayList)3 Conjunction (nars.language.Conjunction)3 Color (java.awt.Color)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 DerivationContext (nars.control.DerivationContext)2 Item (nars.entity.Item)2 Stamp (nars.entity.Stamp)2 Implication (nars.language.Implication)2 NAR (nars.main.NAR)2 Memory (nars.storage.Memory)2