Search in sources :

Example 1 with TruthOperator

use of nars.truth.func.TruthOperator in project narchy by automenta.

the class DeriveRuleProto method build.

/**
 * compiles the conditions which are necessary to activate this rule
 */
public Pair<Set<PrediTerm<PreDerivation>>, PrediTerm<Derivation>> build(PostCondition post) {
    byte puncOverride = post.puncOverride;
    TruthOperator belief = BeliefFunction.get(post.beliefTruth);
    if ((post.beliefTruth != null) && !post.beliefTruth.equals(TruthOperator.NONE) && (belief == null)) {
        throw new RuntimeException("unknown BeliefFunction: " + post.beliefTruth);
    }
    TruthOperator goal = GoalFunction.get(post.goalTruth);
    if ((post.goalTruth != null) && !post.goalTruth.equals(TruthOperator.NONE) && (goal == null)) {
        throw new RuntimeException("unknown GoalFunction: " + post.goalTruth);
    }
    // //if (puncOverride==0) {
    // if (belief!=null && goal!=null) {
    // if (!belief.single() && !goal.single()) {
    // pre.add(TaskPolarity.belief);
    // } else if (belief.single() ^ goal.single()){
    // throw new TODO();
    // }
    // } else if (belief!=null && !belief.single()) {
    // pre.add(TaskPolarity.belief);
    // } else if (goal!=null && !goal.single()) {
    // pre.add(TaskPolarity.belief);
    // }
    // TODO add more specific conditions that also work
    // }
    String beliefLabel = belief != null ? belief.toString() : "_";
    String goalLabel = goal != null ? goal.toString() : "_";
    FasterList<Term> args = new FasterList();
    args.add($.the(beliefLabel));
    args.add($.the(goalLabel));
    if (puncOverride != 0)
        args.add($.quote(((char) puncOverride)));
    Compound ii = (Compound) $.func("truth", args.toArrayRecycled(Term[]::new));
    Solve truth = (puncOverride == 0) ? new Solve.SolvePuncFromTask(ii, belief, goal) : new Solve.SolvePuncOverride(ii, puncOverride, belief, goal);
    // PREFIX
    // for ensuring uniqueness / no duplicates
    Set<PrediTerm<PreDerivation>> precon = newHashSet(4);
    addAll(precon, PRE);
    precon.addAll(this.pre);
    // //-------------------
    // below here are predicates which affect the derivation
    // SUFFIX (order already determined for matching)
    int n = 1 + this.constraints.size() + this.post.size();
    PrediTerm[] suff = new PrediTerm[n];
    int k = 0;
    suff[k++] = truth;
    for (PrediTerm p : this.constraints) {
        suff[k++] = p;
    }
    for (PrediTerm p : this.post) {
        suff[k++] = p;
    }
    return pair(precon, (PrediTerm<Derivation>) AndCondition.the(suff));
}
Also used : FasterList(jcog.list.FasterList) PrediTerm(nars.term.pred.PrediTerm) Compound(nars.term.Compound) PrediTerm(nars.term.pred.PrediTerm) Term(nars.term.Term) nars.derive.constraint(nars.derive.constraint) TruthOperator(nars.truth.func.TruthOperator)

Example 2 with TruthOperator

use of nars.truth.func.TruthOperator in project narchy by automenta.

the class Solve method test.

@Override
public final boolean test(Derivation d) {
    d.truthFunction = null;
    byte punc = punc(d);
    boolean single;
    Truth t;
    switch(punc) {
        case BELIEF:
        case GOAL:
            TruthOperator f = (punc == BELIEF) ? belief : goal;
            d.truthFunction = f;
            if (f == null)
                // there isnt a truth function for this punctuation
                return false;
            single = f.single();
            Truth beliefTruth = d.beliefTruth;
            if (!single && beliefTruth == null)
                // double premise requiring a belief, but belief is null
                return false;
            if ((t = f.apply(// task truth is not involved in the outcome of this; set task truth to be null to prevent any negations below:
            d.taskTruth, single ? null : beliefTruth, d.nar, d.confMin)) == null)
                return false;
            float overlap = f.allowOverlap() ? 0 : single ? d.overlapSingle : d.overlapDouble;
            if (overlap > 0) {
                return false;
            // float e = t.evi() * (1f-overlap);
            // if (e < Pri.EPSILON) //yes Pri epsilon
            // return false;
            // 
            // t = t.withEvi(e);
            // if (t.conf() < confMin)
            // return false;
            // if (d.random.nextFloat() <= overlap)
            // return false;
            }
            break;
        case QUEST:
        case QUESTION:
            float o = d.overlapSingle;
            if (o > 0 && d.random.nextFloat() <= o)
                return false;
            // byte tp = d.taskPunct;
            // if ((tp == QUEST) || (tp == GOAL))
            // punc = QUEST; //use QUEST in relation to GOAL or QUEST task
            single = true;
            t = null;
            break;
        default:
            throw new InvalidPunctuationException(punc);
    }
    d.concTruth = t;
    d.concPunc = punc;
    d.single = single;
    return true;
}
Also used : TruthOperator(nars.truth.func.TruthOperator) Truth(nars.truth.Truth)

Aggregations

TruthOperator (nars.truth.func.TruthOperator)2 FasterList (jcog.list.FasterList)1 nars.derive.constraint (nars.derive.constraint)1 Compound (nars.term.Compound)1 Term (nars.term.Term)1 PrediTerm (nars.term.pred.PrediTerm)1 Truth (nars.truth.Truth)1