use of nars.concept.PermanentConcept in project narchy by automenta.
the class TreeConceptIndex method set.
@Override
public void set(Term src, Termed target) {
@NotNull TermKey k = key(src);
concepts.acquireWriteLock();
try {
// TODO cache ref to where this resolved to accelerate the put() below
Termed existing = concepts.get(k);
if (existing != target && !(existing instanceof PermanentConcept)) {
concepts.put(k, target);
}
} finally {
concepts.releaseWriteLock();
}
}
use of nars.concept.PermanentConcept 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.PermanentConcept 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.PermanentConcept 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);
}
}
}
Aggregations