Search in sources :

Example 11 with NALTask

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

the class PrologCore method answer.

private void answer(Task question, Solution answer) {
    try {
        Term yt = nterm(answer.goal);
        Task y = Task.tryTask(yt, BELIEF, $.t(1f, answerConf.floatValue()), (term, truth) -> {
            NALTask t = new NALTask(term, BELIEF, truth, nar.time(), ETERNAL, ETERNAL, nar.time.nextStampArray());
            t.pri(nar.priDefault(BELIEF));
            t.log("Prolog Answer");
            return t;
        });
        if (y != null) {
            logger.info("answer {}\t{}", question, y);
            in.input(y);
        }
    } catch (Exception e) {
        logger.error("answer {} {} {}", question, answer, e);
    }
}
Also used : ITask(nars.task.ITask) NALTask(nars.task.NALTask) NALTask(nars.task.NALTask) Term(nars.term.Term)

Example 12 with NALTask

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

the class IO method readTask.

@NotNull
public static NALTask readTask(DataInput in) throws IOException {
    Term preterm = readTerm(in);
    final Term term = preterm.normalize();
    if (term == null)
        throw new IOException("un-normalizable task term");
    byte punc = in.readByte();
    Truth truth = hasTruth(punc) ? readTruth(in) : null;
    long start = in.readLong();
    long end = in.readLong();
    long[] evi = readEvidence(in);
    float pri = in.readFloat();
    long cre = in.readLong();
    NALTask mm = new NALTask(term, punc, truth, cre, start, end, evi);
    mm.priSet(pri);
    return mm;
}
Also used : NALTask(nars.task.NALTask) Term(nars.term.Term) Truth(nars.truth.Truth) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with NALTask

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

the class NAgent method alwaysWant.

@Deprecated
public NALTask alwaysWant(Termed x, float conf) {
    NALTask t = new NALTask(x.term(), GOAL, $.t(1f, conf), now, ETERNAL, ETERNAL, Stamp.UNSTAMPED);
    always.add(t);
    return t;
}
Also used : NALTask(nars.task.NALTask)

Example 14 with NALTask

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

the class NAgent method alwaysQuestion.

@Deprecated
public NALTask alwaysQuestion(Termed x) {
    NALTask t = new NALTask(x.term(), QUESTION, null, now, ETERNAL, ETERNAL, // Stamp.UNSTAMPED
    nar().time.nextStampArray()) {

        @Override
        public boolean isInput() {
            return false;
        }
    };
    always.add(t);
    return t;
}
Also used : NALTask(nars.task.NALTask)

Example 15 with NALTask

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

the class RTreeBeliefTable method mergeOrDelete.

private boolean mergeOrDelete(Space<TaskRegion> treeRW, Top2<Leaf<TaskRegion>> l, FloatFunction<Task> taskStrength, float inputStrength, FloatFunction<TaskRegion> weakestTasks, Consumer<Tasked> added, NAR nar) {
    TaskRegion a, b;
    Leaf<TaskRegion> la = l.a;
    short sa = la.size;
    if (sa > 2) {
        Top2<TaskRegion> w = new Top2<>(weakestTasks);
        la.forEach(w::add);
        a = w.a;
        b = w.b;
    } else if (sa == 2) {
        a = la.get(0);
        b = la.get(1);
    } else {
        a = la.get(0);
        Leaf<TaskRegion> lb = l.b;
        if (lb != null) {
            int sb = lb.size();
            if (sb > 1) {
                Top<TaskRegion> w = new Top<>(weakestTasks);
                lb.forEach(w);
                b = w.the;
            } else if (sb == 1) {
                b = lb.get(0);
            } else {
                // ??
                b = null;
            }
        } else {
            b = null;
        }
    }
    assert (a != null);
    Task at = a.task();
    float aPri = at.pri();
    treeRW.remove(at);
    if (b != null) {
        Task bt = b.task();
        if (bt.isDeleted()) {
            treeRW.remove(bt);
            return true;
        } else {
            at.meta("@", bt);
        }
        if (// already deleted
        aPri != aPri)
            return true;
        Task c = // HACK
        (this instanceof Simple || (at.term().equals(bt.term()))) ? Revision.mergeTemporal(nar, at, bt) : // TODO remove this when the mergeTemporal fully supports CONJ and Temporal
        Revision.merge(at, bt, nar.time(), c2wSafe(nar.confMin.floatValue()), nar);
        if (c != null && !c.equals(a) && !c.equals(b)) {
            boolean allowMerge;
            if (inputStrength != inputStrength) {
                allowMerge = true;
            } else {
                float strengthRemoved = taskStrength.floatValueOf(at) + taskStrength.floatValueOf(bt);
                float strengthAdded = taskStrength.floatValueOf(c) + inputStrength;
                allowMerge = strengthAdded >= strengthRemoved;
            }
            if (allowMerge) {
                treeRW.remove(bt);
                // forward
                ((NALTask) at).delete(c);
                // forward
                ((NALTask) bt).delete(c);
                if (treeRW.add(c))
                    added.accept(c);
                return true;
            } else {
                // merge result is not strong enough
                c.delete();
            }
        }
    }
    // TODO do this outside of the locked section
    if (Param.ETERNALIZE_EVICTED_TEMPORAL_TASKS)
        eternalize(at, added, nar);
    at.delete();
    return true;
}
Also used : SignalTask(nars.task.signal.SignalTask) NALTask(nars.task.NALTask) Task(nars.Task) TaskRegion(nars.task.util.TaskRegion) Top(jcog.sort.Top) NALTask(nars.task.NALTask) Top2(jcog.sort.Top2)

Aggregations

NALTask (nars.task.NALTask)17 Task (nars.Task)8 Term (nars.term.Term)8 Truth (nars.truth.Truth)7 Nullable (org.jetbrains.annotations.Nullable)6 ITask (nars.task.ITask)4 SignalTask (nars.task.signal.SignalTask)3 PreciseTruth (nars.truth.PreciseTruth)3 FasterList (jcog.list.FasterList)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1 Stream (java.util.stream.Stream)1 Util (jcog.Util)1 LongInterval (jcog.math.LongInterval)1 Priority (jcog.pri.Priority)1 VLink (jcog.pri.VLink)1 Top (jcog.sort.Top)1