Search in sources :

Example 1 with Termed

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);
}
Also used : Termed(nars.term.Termed) HashMap(java.util.HashMap) PrediTerm(nars.term.pred.PrediTerm) Term(nars.term.Term)

Example 2 with Termed

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());
}
Also used : Subterms(nars.subterm.Subterms) Termed(nars.term.Termed) Ellipsis(nars.derive.match.Ellipsis) Term(nars.term.Term)

Example 3 with Termed

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();
    }
}
Also used : Termed(nars.term.Termed) PermanentConcept(nars.concept.PermanentConcept) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Termed

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);
    }
}
Also used : Termed(nars.term.Termed)

Example 5 with Termed

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());
}
Also used : Termed(nars.term.Termed) Activate(nars.control.Activate) TreeSet(java.util.TreeSet)

Aggregations

Termed (nars.term.Termed)14 Term (nars.term.Term)8 NAR (nars.NAR)5 Concept (nars.concept.Concept)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Test (org.junit.jupiter.api.Test)3 Op (nars.Op)2 PatternIndex (nars.index.term.PatternIndex)2 Subterms (nars.subterm.Subterms)2 PrediTerm (nars.term.pred.PrediTerm)2 com.github.benmanes.caffeine.cache (com.github.benmanes.caffeine.cache)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 TreeSet (java.util.TreeSet)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 nars.$ (nars.$)1