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());
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations