Search in sources :

Example 1 with DeriveTime

use of nars.derive.time.DeriveTime in project narchy by automenta.

the class Termify method test.

@Override
public final boolean test(Derivation d) {
    NAR nar = d.nar;
    nar.emotion.deriveEval.increment();
    // d.xyDyn.clear();
    Term c1 = pattern.eval(d);
    if (!Taskify.valid(c1)) {
        Term c1e = c1;
        d.nar.emotion.deriveFailEval.increment(() -> {
            return rule + " |\n\t" + d.xy + "\n\t -> " + c1e;
        });
        return false;
    }
    if (c1.volume() > d.termVolMax) {
        d.nar.emotion.deriveFailVolLimit.increment();
        return false;
    }
    if (c1.op() == NEG) {
        c1 = c1.unneg();
        if (// belief or goal
        d.concTruth != null)
            d.concTruth = d.concTruth.neg();
    }
    d.concEviFactor = 1f;
    final long[] occ = d.concOcc;
    occ[0] = occ[1] = ETERNAL;
    Term c2;
    if (d.temporal) {
        boolean singleTime = d.task.isEternal() ? d.belief == null : d.single;
        // d.single;
        DeriveTime dt = singleTime ? d.dtSingle : d.dtDouble;
        if (dt == null) {
            dt = new DeriveTime(d, singleTime);
            if (singleTime)
                d.dtSingle = dt;
            else
                d.dtDouble = dt;
        }
        DeriveTime dtt = dt.get();
        // dtt.print();
        c2 = dtt.solve(c1);
        // only should eliminate XTERNAL from beliefs and goals.  ok if it's in questions/quests since it's the only way to express indefinite temporal repetition
        if ((c1 != c2 && !Taskify.valid(c2)) || ((d.concPunc == BELIEF || d.concPunc == GOAL) && c2.hasXternal())) {
            Term c1e = c1;
            d.nar.emotion.deriveFailTemporal.increment(() -> {
                return rule + "\n\t" + d + "\n\t -> " + c1e + "\t->\t" + c2;
            });
            return false;
        }
        if (occ[0] > occ[1]) {
            // HACK swap the reversed occ
            long x = occ[0];
            occ[0] = occ[1];
            occ[1] = x;
        }
        if (d.concPunc == GOAL && d.taskPunc == GOAL && !d.single && Op.values()[d._beliefOp].temporal) // d._beliefOp == IMPL.ordinal() //impl only
        {
            long derivedGoalStart = occ[0];
            if (derivedGoalStart != ETERNAL) {
                long taskWants = d.task.start();
                if (taskWants == ETERNAL) {
                    // now
                    taskWants = d.time;
                }
                if (derivedGoalStart < taskWants) {
                    // derived goal occurrs before task goal, so shift to task start
                    long gdur = occ[1] - derivedGoalStart;
                    occ[0] = taskWants;
                    occ[1] = taskWants + gdur;
                }
            }
        }
    } else {
        if (d.concPunc == BELIEF || d.concPunc == GOAL) {
            c2 = c1.temporalize(Retemporalize.retemporalizeXTERNALToDTERNAL);
            if (c1 != c2 && !Taskify.valid(c2)) {
                d.nar.emotion.deriveFailTemporal.increment();
                return false;
            }
        } else {
            c2 = c1;
        }
    }
    return d.derivedTerm.set(c2) != null;
}
Also used : Term(nars.term.Term) DeriveTime(nars.derive.time.DeriveTime) NAR(nars.NAR)

Aggregations

NAR (nars.NAR)1 DeriveTime (nars.derive.time.DeriveTime)1 Term (nars.term.Term)1