use of nars.term.Termed in project narchy by automenta.
the class Derivation method init.
void init(NAR nar) {
this.clear();
this.nar = nar;
this.random = nar.random();
Termed[] derivationFunctors = new Termed[] { uniSubAny, uniSub, polarizeFunc, termlinkRandomProxy };
Map<Term, Termed> m = new HashMap<>(derivationFunctors.length + 2);
for (Termed x : ruleFunctors(nar)) m.put(x.term(), x);
for (Termed x : derivationFunctors) m.put(x.term(), x);
// m.put(TaskTerm, taskTerm);
// m.put(BeliefTerm, beliefTerm);
this.derivationFunctors = Maps.immutable.ofMap(m);
}
use of nars.term.Termed in project narchy by automenta.
the class PatternIndex method patternify.
/*@NotNull*/
public Term patternify(/*@NotNull*/
Compound x) {
Subterms s = x.subterms();
int ss = s.subs();
Term[] bb = new Term[ss];
// , temporal = false;
boolean changed = false;
for (int i = 0; i < ss; i++) {
Term a = s.sub(i);
Termed b = get(a, true);
if (a != b) {
changed = true;
}
bb[i] = b.term();
}
if (!changed && Ellipsis.firstEllipsis(s) == null)
return x;
Subterms v = changed ? Subterms.subtermsInterned(bb.length > 1 && x.op().commutative && (concurrent(x.dt())) ? Terms.sorted(bb) : bb) : s;
Ellipsis e = Ellipsis.firstEllipsis(v);
return e != null ? ellipsis(x, v, e) : // new PatternCompound.PatternCompoundSimple(x.op(), x.dt(), v);
x.op().the(x.dt(), v.arrayShared());
}
use of nars.term.Termed 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.term.Termed in project narchy by automenta.
the class TreeConceptIndex method remove.
@Override
public void remove(@NotNull Term entry) {
TermKey k = key(entry);
Termed result = concepts.get(k);
if (result != null) {
concepts.remove(k);
}
}
use of nars.term.Termed in project narchy by automenta.
the class ActivateTest method testTemplates.
static void testTemplates(String term, String expect) throws Narsese.NarseseException {
NAR n = NARS.tmp(1);
// n.believe(term + ".");
Concept c = n.conceptualize($(term));
Activate a = new Activate(c, 0.5f);
Collection<Termed> t = new TreeSet(c.templates());
assertEquals(expect, t.toString());
}
Aggregations