Search in sources :

Example 1 with Tense

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);
    }
}
Also used : Tense(nars.time.Tense) TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test)

Example 2 with Tense

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());
    }
}
Also used : Tense(nars.time.Tense) TaskConcept(nars.concept.TaskConcept) TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test)

Example 3 with Tense

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;
}
Also used : TaskBuilder(nars.task.TaskBuilder) Tense(nars.time.Tense) InvalidTaskException(nars.task.util.InvalidTaskException) Term(nars.term.Term) Truth(nars.truth.Truth)

Aggregations

Tense (nars.time.Tense)3 TestNAR (nars.test.TestNAR)2 Test (org.junit.jupiter.api.Test)2 TaskConcept (nars.concept.TaskConcept)1 TaskBuilder (nars.task.TaskBuilder)1 InvalidTaskException (nars.task.util.InvalidTaskException)1 Term (nars.term.Term)1 Truth (nars.truth.Truth)1