use of nars.language.Term 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.language.Term 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;
}
use of nars.language.Term in project opennars by opennars.
the class TermSyntaxVis method addSyntax.
public static Term addSyntax(NARGraph g, Term t) {
if (t instanceof CompoundTerm) {
CompoundTerm ct = (CompoundTerm) t;
g.addVertex(ct);
int n = 0;
for (Term s : ct.term) {
Term v = addSyntax(g, s);
g.addEdge(ct, v, new UniqueEdge(ct.operator() + ":" + n));
n++;
}
return ct;
} else {
g.addVertex(t);
return t;
}
}
use of nars.language.Term 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));
}
}
}
}
}
use of nars.language.Term 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);
}
}
}
Aggregations