Search in sources :

Example 1 with TermContainerToOpMap

use of nars.index.util.TermContainerToOpMap in project narchy by automenta.

the class CaffeineIndex2 method get.

@Override
public Termed get(Term x, boolean createIfMissing) {
    if (x.volume() > nar.termVolumeMax.intValue())
        // quick check to avoid creating a vector for a term that will be invalid anyway
        return null;
    assert (!(x instanceof Variable)) : "variables should not be stored in index";
    Op op = x.op();
    TermContainerToOpMap<Termed> v;
    if (createIfMissing) {
        v = vectors.get(vector(x), k -> {
            TermContainerToOpMap<Termed> t = new TermContainerToOpMap<>(k);
            Termed p = nar.conceptBuilder.apply(x, null);
            if (p != null)
                t.compareAndSet(op.id, null, p);
            return t;
        });
    } else {
        v = vectors.getIfPresent(vector(x));
    }
    return v != null ? v.get(op.id) : null;
}
Also used : Termed(nars.term.Termed) IntStream(java.util.stream.IntStream) True(nars.Op.True) Param(nars.Param) Variable(nars.term.var.Variable) Objects(java.util.Objects) Stream(java.util.stream.Stream) NAR(nars.NAR) Op(nars.Op) Subterms(nars.subterm.Subterms) com.github.benmanes.caffeine.cache(com.github.benmanes.caffeine.cache) Termed(nars.term.Termed) NotNull(org.jetbrains.annotations.NotNull) TermContainerToOpMap(nars.index.util.TermContainerToOpMap) Term(nars.term.Term) Op(nars.Op) Variable(nars.term.var.Variable) TermContainerToOpMap(nars.index.util.TermContainerToOpMap)

Aggregations

com.github.benmanes.caffeine.cache (com.github.benmanes.caffeine.cache)1 Objects (java.util.Objects)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 NAR (nars.NAR)1 Op (nars.Op)1 True (nars.Op.True)1 Param (nars.Param)1 TermContainerToOpMap (nars.index.util.TermContainerToOpMap)1 Subterms (nars.subterm.Subterms)1 Term (nars.term.Term)1 Termed (nars.term.Termed)1 Variable (nars.term.var.Variable)1 NotNull (org.jetbrains.annotations.NotNull)1