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;
}
}
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);
}
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;
}
}
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");
}
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),#1)
Op.CONJ.the(XTERNAL, $.$("(--,((--,#1)&))"), $.$("(--,#2)"), $.varDep(1)).normalize();
assertTrue(c instanceof Compound, () -> c.toString());
assertTrue(Task.validTaskTerm(c), () -> c + " should be a valid task term");
}
Aggregations