Search in sources :

Example 21 with Op

use of nars.Op in project narchy by automenta.

the class Compound method eventsWhile.

// @Override
// default boolean equalsIgnoringVariables(/*@NotNull*/ Term other, boolean requireSameTime) {
// if (other instanceof Variable)
// return true;
// 
// //        if (op() == NEG)
// //            throw new UnsupportedOperationException("left hand side should already be unneg'd");
// //
// //        if (other.op()==NEG)
// //            other = other.unneg();
// 
// Op op = op();
// if (!(other.op() == op))
// return false;
// 
// int s = size();
// 
// if (other.size() == s) {
// 
// if (requireSameTime)
// if (((Compound) other).dt() != dt())
// return false;
// 
// Compound o = (Compound) other;
// Term[] a = toArray();
// Term[] b = o.toArray();
// for (int i = 0; i < s; i++) {
// if (!a[i].equalsIgnoringVariables(b[i], requireSameTime))
// return false;
// }
// return true;
// }
// return false;
// }
/* collects any contained events within a conjunction*/
@Override
default boolean eventsWhile(LongObjectPredicate<Term> events, long offset, boolean decomposeConjParallel, boolean decomposeConjDTernal, boolean decomposeXternal, int level) {
    Op o = op();
    if (o == CONJ) {
        int dt = dt();
        if ((decomposeConjDTernal || dt != DTERNAL) && (decomposeConjParallel || dt != 0) && (decomposeXternal || dt != XTERNAL)) {
            if (dt == DTERNAL)
                dt = 0;
            else if (// HACK
            dt == XTERNAL)
                dt = 0;
            Subterms tt = subterms();
            int s = tt.subs();
            long t = offset;
            boolean changeDT = t != ETERNAL && t != TIMELESS;
            level++;
            if (dt >= 0) {
                // forward
                for (int i = 0; i < s; i++) {
                    Term st = tt.sub(i);
                    if (!st.eventsWhile(events, t, decomposeConjParallel, decomposeConjDTernal, decomposeXternal, // recurse
                    level))
                        return false;
                    if (changeDT)
                        t += dt + st.dtRange();
                }
            } else {
                // reverse
                for (int i = s - 1; i >= 0; i--) {
                    Term st = tt.sub(i);
                    if (!st.eventsWhile(events, t, decomposeConjParallel, decomposeConjDTernal, decomposeXternal, // recurse
                    level))
                        return false;
                    if (changeDT)
                        t += -dt + st.dtRange();
                }
            }
            return true;
        }
    }
    return events.accept(offset, this);
}
Also used : Subterms(nars.subterm.Subterms) Op(nars.Op)

Example 22 with Op

use of nars.Op in project narchy by automenta.

the class Compound method append.

default void append(ByteArrayDataOutput out) {
    Op o = op();
    out.writeByte(o.id);
    subterms().append(out);
    if (o.temporal)
        out.writeInt(dt());
}
Also used : Op(nars.Op)

Example 23 with Op

use of nars.Op in project narchy by automenta.

the class Compound method subTimeSafe.

/**
 * TODO do shuffled search to return different repeated results wherever they may appear
 */
@Override
default int subTimeSafe(Term x, int after) {
    if (equals(x))
        return 0;
    Op op = op();
    if (op != CONJ)
        return DTERNAL;
    int dt = dt();
    if (// unknown
    dt == XTERNAL)
        return DTERNAL;
    if (impossibleSubTerm(x))
        return DTERNAL;
    /*@NotNull*/
    Subterms yy = subterms();
    /*} else */
    if (op == CONJ) {
        /* HACK apply to other cases too */
        if (after >= dt) {
            Term yy1 = yy.sub(1);
            if (yy.sub(0).equals(yy1)) {
                // return yy.sub(1).subTimeSafe(x, after - dt) + dt;
                if (x.equals(yy1))
                    return dt;
            }
        }
        boolean reverse;
        int idt;
        if (dt == DTERNAL || dt == 0) {
            // parallel or eternal, no dt increment
            idt = 0;
            reverse = false;
        } else {
            idt = dt;
            if (idt < 0) {
                idt = -idt;
                reverse = true;
            } else {
                reverse = false;
            }
        }
        int ys = yy.subs();
        int offset = 0;
        for (int yi = 0; yi < ys; yi++) {
            Term yyy = yy.sub(reverse ? ((ys - 1) - yi) : yi);
            int sdt = yyy.subTimeSafe(x, after - offset);
            if (sdt != DTERNAL)
                return sdt + offset;
            offset += idt + yyy.dtRange();
        }
    }
    return DTERNAL;
}
Also used : Subterms(nars.subterm.Subterms) Op(nars.Op)

Example 24 with Op

use of nars.Op in project narchy by automenta.

the class Compound method concept.

@Override
default Term concept() {
    Op op;
    if ((op = op()) == NEG)
        return unneg().concept();
    // unneg just in case
    Term term = root().unneg();
    if (!term.op().conceptualizable)
        return Null;
    Term term2 = term.normalize();
    if (term2 != term) {
        if (term2 == null)
            return Null;
        assert (term2.op() == op);
        // if (!term2.op().conceptualizable)
        // return Null;
        term = term2;
    }
    return term;
}
Also used : Op(nars.Op)

Example 25 with Op

use of nars.Op in project narchy by automenta.

the class Termlike method hasAny.

/**
 * has special handling for VAR_PATTERN
 */
default boolean hasAny(Op... oo) {
    boolean checkVarPattern = false;
    int checkStruct = 0;
    for (Op o : oo) {
        if (o == VAR_PATTERN)
            // check last
            checkVarPattern = true;
        else
            checkStruct |= o.bit;
    }
    return (checkStruct != 0 && hasAny(checkStruct)) || (checkVarPattern && varPattern() > 0);
}
Also used : Op(nars.Op)

Aggregations

Op (nars.Op)36 Term (nars.term.Term)13 Subterms (nars.subterm.Subterms)11 Nullable (org.jetbrains.annotations.Nullable)8 Atomic (nars.term.atom.Atomic)4 Test (org.junit.jupiter.api.Test)4 FasterList (jcog.list.FasterList)3 NAR (nars.NAR)3 Termed (nars.term.Termed)3 Atom (nars.term.atom.Atom)3 Bool (nars.term.atom.Bool)3 Pair (org.eclipse.collections.api.tuple.Pair)3 NotNull (org.jetbrains.annotations.NotNull)3 java.io (java.io)2 java.util (java.util)2 List (java.util.List)2 Map (java.util.Map)2 Stream (java.util.stream.Stream)2 nars.$ (nars.$)2 Concept (nars.concept.Concept)2