Search in sources :

Example 51 with Compound

use of nars.term.Compound in project narchy by automenta.

the class QEntry method commit.

// /** inserts the belief directly into the table */
// public void commitFast(Task t) {
// //concept.beliefs.clear();
// 
// //switch(t.punctuation) ..
// //concept.processJudgment(null, t);
// concept.processGoal(null, t);
// }
/**
 * input to NAR
 */
public void commit(byte punctuation, float qUpdateConfidence, float freqThreshold, float priorityGain) {
    clearDQ();
    double qq = getQ();
    double nq = qq;
    if (nq > 1d)
        nq = 1d;
    if (nq < -1d)
        nq = -1d;
    Term qt = concept.getTerm();
    // System.out.println(qt + " qUpdate: " + Texts.n4(q) + " + " + dq + " -> " + " (" + Texts.n4(nq) + ")");
    float nextFreq = (float) ((nq / 2f) + 0.5f);
    long now = concept.getMemory().time();
    if (qUpdateConfidence > 0 && ((now - lastCommit >= commitEvery) && FastMath.abs(nextFreq - lastFreq) > freqThreshold)) {
        Task t = TaskSeed.make(((Memory) concept.getMemory()), (Compound) qt).punctuation(punctuation).present().truth(nextFreq, qUpdateConfidence);
        t.getBudget().mulPriority(priorityGain);
        commitDirect(t);
        lastFreq = nextFreq;
        lastCommit = now;
    }
}
Also used : Compound(nars.term.Compound) Term(nars.term.Term)

Example 52 with Compound

use of nars.term.Compound in project narchy by automenta.

the class DeriveRuleSet method parseRuleComponents.

@NotNull
public static Subterms parseRuleComponents(@NotNull String src) throws Narsese.NarseseException {
    // (Compound) index.parseRaw(src)
    String[] ab = ruleImpl.split(src);
    if (ab.length != 2)
        throw new Narsese.NarseseException("Rule component must have arity=2, separated by \"|-\": " + src);
    String A = '(' + ab[0].trim() + ')';
    Term a = Narsese.term(A, false);
    if (!(a instanceof Compound))
        throw new Narsese.NarseseException("Left rule component must be compound: " + src);
    String B = '(' + ab[1].trim() + ')';
    Term b = Narsese.term(B, false);
    if (!(b instanceof Compound))
        throw new Narsese.NarseseException("Right rule component must be compound: " + src);
    return Subterms.subtermsInterned(a, b);
}
Also used : Compound(nars.term.Compound) Narsese(nars.Narsese) Term(nars.term.Term) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with Compound

use of nars.term.Compound in project narchy by automenta.

the class PatternIndex method get.

// /**
// * installs static and NAR-specific functors
// */
// public PatternIndex(NAR nar) {
// this();
// //        for (Termed t : Derivation.ruleFunctors(nar)) {
// //            set(t);
// //        }
// }
@SuppressWarnings("Java8MapApi")
@Override
public Termed get(/*@NotNull*/
Term x, boolean createIfMissing) {
    if (!x.op().conceptualizable)
        return x;
    // avoid recursion-caused concurrent modifiation exception
    Termed y = concepts.get(x);
    if (y == null) {
        Term yy = x instanceof Compound ? patternify((Compound) x) : x;
        concepts.put(yy, yy);
        return yy;
    } else {
        return y;
    }
}
Also used : Termed(nars.term.Termed) PatternCompound(nars.derive.PatternCompound) Compound(nars.term.Compound) Term(nars.term.Term)

Example 54 with Compound

use of nars.term.Compound in project narchy by automenta.

the class DynamicTruthBeliefTableTest method testDynamicConceptValid1.

@Test
public void testDynamicConceptValid1() throws Narsese.NarseseException {
    Term c = // $.$("( &&+- ,(--,($1 ==>+- (((joy-->fz)&&fwd) &&+- $1))),(joy-->fz),fwd)");
    Op.CONJ.the(XTERNAL, $.$("(--,($1 ==>+- (((joy-->fz)&&fwd) &&+- $1)))"), $.$("(joy-->fz)"), $.$("fwd")).normalize();
    assertTrue(c instanceof Compound, () -> c.toString());
    assertTrue(Task.validTaskTerm(c), () -> c + " should be a valid task term");
}
Also used : Compound(nars.term.Compound) Term(nars.term.Term) Test(org.junit.jupiter.api.Test)

Example 55 with Compound

use of nars.term.Compound in project narchy by automenta.

the class DynamicTruthBeliefTableTest method testDynamicConceptValid2.

@Test
public void testDynamicConceptValid2() throws Narsese.NarseseException {
    Term c = // ( &&+- ,(--,((--,#1)&&#2)),(--,#2),#1)
    Op.CONJ.the(XTERNAL, $.$("(--,((--,#1)&&#2))"), $.$("(--,#2)"), $.varDep(1)).normalize();
    assertTrue(c instanceof Compound, () -> c.toString());
    assertTrue(Task.validTaskTerm(c), () -> c + " should be a valid task term");
}
Also used : Compound(nars.term.Compound) Term(nars.term.Term) Test(org.junit.jupiter.api.Test)

Aggregations

Compound (nars.term.Compound)58 Test (org.junit.jupiter.api.Test)38 Term (nars.term.Term)20 Unify (nars.term.subst.Unify)3 FasterList (jcog.list.FasterList)2 XorShift128PlusRandom (jcog.math.random.XorShift128PlusRandom)2 Op (nars.Op)2 PatternCompound (nars.derive.PatternCompound)2 PatternIndex (nars.index.term.PatternIndex)2 Atomic (nars.term.atom.Atomic)2 Variable (nars.term.var.Variable)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 alice.tuprolog (alice.tuprolog)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Prioritized (jcog.pri.Prioritized)1 Narsese (nars.Narsese)1