Search in sources :

Example 41 with Task

use of nars.Task in project narchy by automenta.

the class Conclude method match.

public static void match(final DeriveRuleProto rule, List<PrediTerm<PreDerivation>> pre, List<PrediTerm<Derivation>> post, PatternIndex index, NAR nar) {
    Term pattern = rule.conclusion().sub(0);
    // TODO may interfere with constraints, functors, etc or other features, ie.
    // if the pattern is a product for example?
    // pattern = pattern.replace(ta, Derivation._taskTerm);
    // determine if any cases where a shortcut like this can work (ie. no constraints, not a product etc)
    // //substitute compound occurrences of the exact task and belief terms with the short-cut
    // Term ta = rule.getTask();
    // if (!ta.op().var) {
    // if (pattern.equals(ta))
    // pattern = Derivation.TaskTerm;
    // }
    // Term tb = rule.getBelief();
    // if (!tb.op().var) {
    // //pattern = pattern.replace(tb, Derivation._beliefTerm);
    // if (pattern.equals(tb))
    // pattern = Derivation.BeliefTerm;
    // }
    // HACK unwrap varIntro so we can apply it at the end of the derivation process, not before like other functors
    boolean introVars1;
    Pair<Termed, Term> outerFunctor = Op.functor(pattern, (i) -> i.equals(VAR_INTRO) ? VAR_INTRO : null);
    if (outerFunctor != null) {
        introVars1 = true;
        pattern = outerFunctor.getTwo().sub(0);
    } else {
        introVars1 = false;
    }
    pattern = index.get(pattern, true).term();
    Taskify taskify = new Taskify(nar.newCause((s) -> new RuleCause(rule, s)));
    PrediTerm<Derivation> conc = AndCondition.the(new Termify($.func("derive", pattern), pattern, rule), introVars1 ? AndCondition.the(introVars, taskify) : taskify);
    final Term taskPattern = rule.getTask();
    final Term beliefPattern = rule.getBelief();
    Op to = taskPattern.op();
    boolean taskIsPatVar = to == Op.VAR_PATTERN;
    Op bo = beliefPattern.op();
    boolean belIsPatVar = bo == Op.VAR_PATTERN;
    if (!taskIsPatVar) {
        pre.add(new TaskBeliefOp(to, true, false));
        pre.addAll(SubTermStructure.get(0, taskPattern.structure()));
    }
    if (!belIsPatVar) {
        if (to == bo) {
            pre.add(new AbstractPatternOp.TaskBeliefOpEqual());
        } else {
            pre.add(new TaskBeliefOp(bo, false, true));
            pre.addAll(SubTermStructure.get(1, beliefPattern.structure()));
        }
    }
    if (taskPattern.equals(beliefPattern)) {
        post.add(new UnifyTerm.UnifySubtermThenConclude(0, taskPattern, conc));
    }
    if (taskFirst(taskPattern, beliefPattern)) {
        // task first
        post.add(new UnifyTerm.UnifySubterm(0, taskPattern));
        post.add(new UnifyTerm.UnifySubtermThenConclude(1, beliefPattern, conc));
    } else {
        // belief first
        post.add(new UnifyTerm.UnifySubterm(1, beliefPattern));
        post.add(new UnifyTerm.UnifySubtermThenConclude(0, taskPattern, conc));
    }
// Term beliefPattern = pattern.term(1);
// if (Global.DEBUG) {
// if (beliefPattern.structure() == 0) {
// if nothing else in the rule involves this term
// which will be a singular VAR_PATTERN variable
// then allow null
// if (beliefPattern.op() != Op.VAR_PATTERN)
// throw new RuntimeException("not what was expected");
// }
// }
/*System.out.println( Long.toBinaryString(
                        pStructure) + " " + pattern
        );*/
}
Also used : DepIndepVarIntroduction(nars.op.DepIndepVarIntroduction) PrediTerm(nars.term.pred.PrediTerm) AbstractPatternOp(nars.derive.op.AbstractPatternOp) nars.$(nars.$) DeriveRuleSource(nars.derive.rule.DeriveRuleSource) AndCondition(nars.term.pred.AndCondition) UnifyTerm(nars.derive.op.UnifyTerm) AbstractPred(nars.term.pred.AbstractPred) Nullable(org.jetbrains.annotations.Nullable) VAR_INTRO(nars.derive.Conclude.IntroVars.VAR_INTRO) Task(nars.Task) List(java.util.List) TaskBeliefOp(nars.derive.op.TaskBeliefOp) NAR(nars.NAR) Op(nars.Op) DeriveRuleProto(nars.derive.rule.DeriveRuleProto) PatternIndex(nars.index.term.PatternIndex) Map(java.util.Map) SubTermStructure(nars.derive.op.SubTermStructure) Termed(nars.term.Termed) Cause(nars.control.Cause) Pair(org.eclipse.collections.api.tuple.Pair) Term(nars.term.Term) AbstractPatternOp(nars.derive.op.AbstractPatternOp) TaskBeliefOp(nars.derive.op.TaskBeliefOp) Op(nars.Op) TaskBeliefOp(nars.derive.op.TaskBeliefOp) AbstractPatternOp(nars.derive.op.AbstractPatternOp) UnifyTerm(nars.derive.op.UnifyTerm) PrediTerm(nars.term.pred.PrediTerm) UnifyTerm(nars.derive.op.UnifyTerm) Term(nars.term.Term) Termed(nars.term.Termed)

Example 42 with Task

use of nars.Task in project narchy by automenta.

the class ArithmeticIntroduction method leak.

@Override
protected float leak(Task xx) {
    Term x = xx.term();
    Term y = apply(x, nar.random());
    if (y != null && !y.equals(x) && y.op().conceptualizable) {
        Task yy = Task.clone(xx, y);
        if (yy != null) {
            out.input(yy);
            return 1;
        }
    } else {
    // if (Param.DEBUG)
    // logger.warn("fail: task={} result=", xx, y);
    }
    return 0;
}
Also used : Task(nars.Task) Term(nars.term.Term)

Example 43 with Task

use of nars.Task in project narchy by automenta.

the class MapTaskIndex method removeDeleted.

public void removeDeleted() {
    Iterator<Task> ii = tasks.values().iterator();
    while (ii.hasNext()) {
        Task x = ii.next();
        if (x.isDeleted()) {
            logger.error("lingering deleted task: {}", x);
            ii.remove();
        }
    }
}
Also used : Task(nars.Task)

Example 44 with Task

use of nars.Task in project narchy by automenta.

the class DefaultBeliefTable method match.

@Override
public Task match(long start, long end, Term template, NAR nar, Predicate<Task> filter) {
    Task ete = filter == null ? eternal.strongest() : eternal.select(filter);
    Task tmp = temporal.match(start, end, template, nar, filter);
    return Task.eviMax(ete, tmp, start, end);
}
Also used : Task(nars.Task)

Example 45 with Task

use of nars.Task in project narchy by automenta.

the class DefaultBeliefTable method sample.

@Override
public Task sample(long start, long end, Term template, NAR nar) {
    Task ete = eternal.sample(start, end, template, nar);
    Task tmp = temporal.sample(start, end, template, nar);
    return Task.eviMax(ete, tmp, start, end);
}
Also used : Task(nars.Task)

Aggregations

Task (nars.Task)50 Term (nars.term.Term)15 NALTask (nars.task.NALTask)13 Truth (nars.truth.Truth)12 Nullable (org.jetbrains.annotations.Nullable)11 SignalTask (nars.task.signal.SignalTask)9 Test (org.junit.jupiter.api.Test)8 ITask (nars.task.ITask)6 FasterList (jcog.list.FasterList)5 NAR (nars.NAR)5 PreciseTruth (nars.truth.PreciseTruth)4 Util (jcog.Util)3 Top (jcog.sort.Top)3 Op (nars.Op)3 Param (nars.Param)3 TaskRegion (nars.task.util.TaskRegion)3 List (java.util.List)2 Map (java.util.Map)2 Random (java.util.Random)2 VLink (jcog.pri.VLink)2