use of nars.concept.Concept in project narchy by automenta.
the class Abbreviation method input.
private void input(Prioritized b, Consumer<PLink<Compound>> each, Compound t, float scale, NAR nar) {
int vol = t.volume();
if (vol < volume.lo())
return;
if (vol <= volume.hi()) {
if (t.concept().equals(t)) /* identical to its conceptualize */
{
Concept abbreviable = nar.concept(t);
if ((abbreviable != null) && !(abbreviable instanceof PermanentConcept) && abbreviable.meta("abbr") == null) {
each.accept(new PLink<>(t, b.priElseZero()));
}
}
} else {
// recursiely try subterms of a temporal or exceedingly large concept
// budget with a proportion of this compound relative to their volume contribution
float subScale = 1f / (1 + t.subs());
t.forEach(x -> {
if (x.subs() > 0)
input(b, each, ((Compound) x), subScale, nar);
});
}
}
use of nars.concept.Concept in project narchy by automenta.
the class Abbreviation method abbreviate.
// private float scoreIfExceeds(Budget task, float min) {
// float s = or(task.priIfFiniteElseZero(), task.qua());
// if (s >= min) {
// s *= abbreviationProbability.floatValue();
// if (s >= min) {
//
// //higher probability for terms nearer the thresh. smaller and larger get less chance
// // s *= 1f - unitize(
// // Math.abs(task.volume() - volThresh) /
// // (threshFalloffRate) );
//
// if (s >= min)
// return s;
// }
// }
// return -1;
// }
// private boolean createRelation = false;
protected boolean abbreviate(@NotNull Compound abbreviated, @NotNull Prioritized b, NAR nar) {
@Nullable Concept abbrConcept = nar.concept(abbreviated);
if (abbrConcept != null && !(abbrConcept instanceof AliasConcept) && !(abbrConcept instanceof PermanentConcept)) {
final boolean[] succ = { false };
abbrConcept.meta("abbr", (ac) -> {
Term abbreviatedTerm = abbreviated.term();
AliasConcept a1 = new AliasConcept(newSerialTerm(), abbrConcept, nar);
nar.on(a1);
// set the abbreviated term to resolve to the abbreviation
nar.concepts.set(abbreviated.term(), a1);
if (!abbreviatedTerm.equals(abbreviated.term()))
// set the abbreviated term to resolve to the abbreviation
nar.concepts.set(abbreviatedTerm, a1);
// Compound abbreviation = newRelation(abbreviated, id);
// if (abbreviation == null)
// return null; //maybe could happen
//
// Task abbreviationTask = Task.tryTask(abbreviation, BELIEF, $.t(1f, abbreviationConfidence.floatValue()),
// (te, tr) -> {
//
// NALTask ta = new NALTask(
// te, BELIEF, tr,
// nar.time(), ETERNAL, ETERNAL,
// new long[]{nar.time.nextStamp()}
// );
//
//
// ta.meta(Abbreviation.class, new Term[]{abbreviatedTerm, aliasTerm.term()});
// ta.log("Abbreviate"); //, abbreviatedTerm, aliasTerm
// ta.setPri(b);
//
// nar.runLater(()->nar.input(ta));
logger.info("{} => {}", a1, abbreviatedTerm);
//
//
// return ta;
//
// //if (abbreviation != null) {
//
// //logger.info("{} <=== {}", alias, abbreviatedTerm);
//
// });
// abbreviationTask.priority();
// if (srcCopy == null) {
// delete();
// } else {
// float p = srcCopy.priSafe(-1);
// if (p < 0) {
// delete();
// } else {
// setPriority(p);
// }
// }
//
// return this;
succ[0] = true;
return a1;
});
return succ[0];
}
return false;
}
use of nars.concept.Concept in project narchy by automenta.
the class ConceptIndex method onRemove.
protected final void onRemove(Termed value) {
if (value instanceof Concept) {
if (value instanceof PermanentConcept) {
// refuse deletion
nar.runLater(() -> {
set(value);
});
} else {
Concept c = (Concept) value;
if (c instanceof TaskConcept)
forget((TaskConcept) c);
c.delete(nar);
}
}
}
use of nars.concept.Concept in project narchy by automenta.
the class STMLinkage method link.
protected static void link(Task ta, float pri, Task tb, short cid, NAR nar) {
/**
* current task's...
*/
Concept ca = ta.concept(nar, true);
if (ca != null) {
Concept cb = tb.concept(nar, true);
if (cb != null) {
if (!cb.equals(ca)) {
// null or same concept?
// TODO handle overflow?
cb.termlinks().putAsync(new CauseLink.PriCauseLink(ca.term(), pri, cid));
ca.termlinks().putAsync(new CauseLink.PriCauseLink(cb.term(), pri, cid));
// //tasklinks, not sure:
// Tasklinks.linkTask(ta, interStrength, cb);
// Tasklinks.linkTask(tb, interStrength, ca);
} else {
// create a self-termlink
ca.termlinks().putAsync(new CauseLink.PriCauseLink(ca.term(), pri, cid));
}
}
}
}
use of nars.concept.Concept in project narchy by automenta.
the class LinkageTest method linksIndirectly.
boolean linksIndirectly(@NotNull Concept src, @NotNull Concept target, @NotNull NAR nar) {
for (PriReference<Term> entry : src.termlinks()) {
// test 1st level link
Term w = entry.get();
if (target.equals(w))
return true;
Concept ww = nar.concept(w);
if (ww != null) {
if (target.equals(ww)) {
return true;
}
// test 2nd level link
for (PriReference<Term> entry2 : ww.termlinks()) {
Term e = entry2.get();
if (target.equals(e))
return true;
Concept ee = nar.concept(e);
if (ee != null && target.equals(ee))
return true;
}
}
}
return false;
}
Aggregations