Search in sources :

Example 1 with DebugDerivedTask

use of nars.task.DebugDerivedTask in project narchy by automenta.

the class Taskify method test.

/**
 * note: the return value here shouldnt matter so just return true anyway
 */
@Override
public boolean test(Derivation d) {
    Truth tru = d.concTruth;
    if (tru != null) {
        float finalEvi = tru.evi() * d.concEviFactor;
        if (d.eviMin > finalEvi) {
            d.use(Param.TTL_EVI_INSUFFICIENT);
            return true;
        }
        tru = tru.withEvi(finalEvi);
    }
    Term x0 = d.derivedTerm.get();
    Term x = d.anon.get(x0).normalize();
    long[] occ = d.concOcc;
    byte punc = d.concPunc;
    assert (punc != 0) : "no punctuation assigned";
    DerivedTask t = (DerivedTask) Task.tryTask(x, punc, tru, (C, tr) -> {
        int dither = d.ditherTime;
        long start = Tense.dither(occ[0], dither);
        long end = Tense.dither(occ[1], dither);
        assert (end >= start) : "task has reversed occurrence: " + start + ".." + end;
        return Param.DEBUG ? new DebugDerivedTask(C, punc, tr, start, end, d) : new DerivedTask(C, punc, tr, start, end, d);
    });
    if (t == null) {
        d.nar.emotion.deriveFailTaskify.increment();
        return spam(d, Param.TTL_DERIVE_TASK_FAIL);
    }
    if (same(t, d._task, d.freqRes) || (d._belief != null && same(t, d._belief, d.freqRes))) {
        d.nar.emotion.deriveFailParentDuplicate.increment();
        return spam(d, Param.TTL_DERIVE_TASK_SAME);
    }
    if (d.single)
        t.setCyclic(true);
    float priority = d.deriver.prioritize.pri(t, d);
    if (priority != priority) {
        d.nar.emotion.deriveFailPrioritize.increment();
        return spam(d, Param.TTL_DERIVE_TASK_PRIORITIZE);
    }
    t.priSet(priority);
    t.cause = ArrayUtils.addAll(d.parentCause, channel.id);
    if (d.add(t) != t) {
        d.nar.emotion.deriveFailDerivationDuplicate.increment();
        spam(d, Param.TTL_DERIVE_TASK_REPEAT);
    } else {
        if (Param.DEBUG)
            t.log(channel.ruleString);
        d.use(Param.TTL_DERIVE_TASK_SUCCESS);
    }
    return true;
}
Also used : DebugDerivedTask(nars.task.DebugDerivedTask) Tense(nars.time.Tense) Logger(org.slf4j.Logger) DerivedTask(nars.task.DerivedTask) FILTER_SIMILAR_DERIVATIONS(nars.Param.FILTER_SIMILAR_DERIVATIONS) LoggerFactory(org.slf4j.LoggerFactory) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BOOL(nars.Op.BOOL) nars.$(nars.$) Util(jcog.Util) NALTask(nars.task.NALTask) Param(nars.Param) AbstractPred(nars.term.pred.AbstractPred) Task(nars.Task) Truth(nars.truth.Truth) VAR_PATTERN(nars.Op.VAR_PATTERN) Term(nars.term.Term) Term(nars.term.Term) DebugDerivedTask(nars.task.DebugDerivedTask) DerivedTask(nars.task.DerivedTask) DebugDerivedTask(nars.task.DebugDerivedTask) Truth(nars.truth.Truth)

Aggregations

Util (jcog.Util)1 nars.$ (nars.$)1 BOOL (nars.Op.BOOL)1 VAR_PATTERN (nars.Op.VAR_PATTERN)1 Param (nars.Param)1 FILTER_SIMILAR_DERIVATIONS (nars.Param.FILTER_SIMILAR_DERIVATIONS)1 Task (nars.Task)1 DebugDerivedTask (nars.task.DebugDerivedTask)1 DerivedTask (nars.task.DerivedTask)1 NALTask (nars.task.NALTask)1 Term (nars.term.Term)1 AbstractPred (nars.term.pred.AbstractPred)1 Tense (nars.time.Tense)1 Truth (nars.truth.Truth)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1