use of nars.time.Tense in project narchy by automenta.
the class BeliefTableTest method testBestMatchImplSimple.
@Test
public void testBestMatchImplSimple() throws Narsese.NarseseException {
for (Tense t : new Tense[] { Present /*, Eternal*/
}) {
NAR n = NARS.tmp();
n.dtMergeOrChoose.set(false);
n.believe("(a ==>+0 b)", t, 1f, 0.9f);
n.believe("(a ==>+5 b)", t, 1f, 0.9f);
n.believe("(a ==>-5 b)", t, 1f, 0.9f);
long when = t == Present ? 0 : ETERNAL;
for (int dt = 3; dt < 7; dt++) {
Task fwd = n.match($.impl($.$("a"), +dt, $.$("b")), BELIEF, when);
assertEquals("(a ==>+5 b)", fwd.term().toString());
}
Task bwd = n.match($.impl($.$("a"), -5, $.$("b")), BELIEF, when);
assertEquals("(a ==>-5 b)", bwd.term().toString());
Task x = n.match($.impl($.$("a"), DTERNAL, $.$("b")), BELIEF, when);
System.out.println(x);
}
}
use of nars.time.Tense in project narchy by automenta.
the class BeliefTableTest method testConceptualizationIntermpolation.
@Test
public void testConceptualizationIntermpolation() throws Narsese.NarseseException {
for (Tense t : new Tense[] { Present, Eternal }) {
NAR n = NARS.tmp();
n.dtMergeOrChoose.set(true);
n.believe("((a ==>+2 b)-->[pill])", t, 1f, 0.9f);
n.believe("((a ==>+6 b)-->[pill])", t, 1f, 0.9f);
// @NotNull Bag<Concept, PLink<Concept>> cb = n.focus.active;
// assertTrue(5 <= cb.size());
String abpill = "((a==>b)-->[pill])";
// iterator().next().get();//((ArrayBag<Concept>) cb).get(0).get();
TaskConcept cc = (TaskConcept) n.conceptualize(abpill);
assertNotNull(cc);
String correctMerge = "((a ==>+4 b)-->[pill])";
cc.beliefs().print();
// test belief match interpolated a result
long when = t == Present ? 0 : ETERNAL;
assertEquals(correctMerge, cc.beliefs().match(when, null, n).term().toString());
// test merge after capacity shrink:
// set to capacity=1 to force compression
cc.beliefs().setCapacity(1, 1);
cc.print();
// n.forEachTask(System.out::println);
// INTERMPOLATION APPLIED AFTER REVECTION:
assertEquals(correctMerge, cc.beliefs().match(0, null, n).term().toString());
}
}
use of nars.time.Tense in project narchy by automenta.
the class Narsese method decodeTask.
/**
* returns null if the Task is invalid (ex: invalid term)
*/
static Task decodeTask(NAR m, Object[] x) {
if (x.length == 1 && x[0] instanceof Task) {
return (Task) x[0];
}
Term content = ((Term) x[1]).normalize();
/*if (!(content instanceof Compound)) {
throw new NarseseException("Task term unnormalizable: " + contentRaw);
//return Command.task($.func("log", content));
} else */
Object px = x[2];
byte punct = px instanceof Byte ? (Byte) x[2] : (byte) (((Character) x[2]).charValue());
Truth t = (Truth) x[3];
if (t != null && !Float.isFinite(t.conf()))
t = $.t(t.freq(), m.confDefault(punct));
if (t == null && (punct == BELIEF || punct == GOAL)) {
t = $.t(1, m.confDefault(punct));
}
Task y = Task.tryTask(content, punct, t, (C, tr) -> {
// TODO construct directly and remove TaskBuilder
TaskBuilder ttt = new TaskBuilder(C, punct, tr).time(// creation time
m.time(), Tense.getRelativeOccurrence((Tense) x[4], m));
if (x[0] == null)
/* do not set, Memory will apply defaults */
ttt.priSet(m.priDefault(punct));
else
ttt.priSet((Float) x[0]);
return ttt.apply(m).log(NARSESE_TASK_TAG);
});
if (y == null) {
throw new InvalidTaskException(content, "input: " + Arrays.toString(x));
}
return y;
}
Aggregations