Search in sources :

Example 6 with Compound

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

the class NarseseExtendedTest method testAnonymousVariable.

@Test
public void testAnonymousVariable() throws Narsese.NarseseException {
    // (_,_) must be converted to (#1,#2)
    String input = "((_,_) <-> x)";
    Compound x = term(input);
    // Terms.printRecursive(System.out, x);
    assertEquals("((_,_)<->x)", x.toString());
    Term y = x.normalize();
    // Terms.printRecursive(System.out, y);
    assertEquals("((#1,#2)<->x)", y.toString());
    Task question = task(x + "?");
    assertEquals("((#1,#2)<->x)?", question.toStringWithoutBudget());
    Task belief = task(x + ".");
    assertEquals("((#1,#2)<->x). %1.0;.90%", belief.toStringWithoutBudget());
}
Also used : Compound(nars.term.Compound) Term(nars.term.Term) Test(org.junit.jupiter.api.Test)

Example 7 with Compound

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

the class NarseseExtendedTest method testNegation3.

@Test
public void testNegation3() throws Narsese.NarseseException {
    assertEquals("(--,(x))", term("--(x)").toString());
    assertEquals("(--,(x))", term("-- (x)").toString());
    assertEquals("(--,(x&&y))", term("-- (x && y)").toString());
    assertEquals(term("(goto(z) ==>+5 --(x))"), term("(goto(z) ==>+5 (--,(x)))"));
    assertEquals(term("(goto(z) ==>+5 --x:y)"), term("(goto(z) ==>+5 (--,x:y))"));
    Compound nab = term("--(a & b)");
    assertSame(nab.op(), Op.NEG);
    assertSame(nab.sub(0).op(), Op.SECTe);
// try {
// task("(-- negated illegal_extra_term)!");
// assertTrue(false);
// } catch (Exception e) {
// }
}
Also used : Compound(nars.term.Compound) Test(org.junit.jupiter.api.Test)

Example 8 with Compound

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

the class NarseseExtendedTest method testColonReverseInheritance.

@Test
public void testColonReverseInheritance() throws Narsese.NarseseException {
    Compound t = term("namespace:named");
    assertEquals(Op.INH, t.op());
    assertEquals("named", t.sub(0).toString());
    assertEquals("namespace", t.sub(1).toString());
    Compound u = term("<a:b --> c:d>");
    assertEquals("((b-->a)-->(d-->c))", u.toString());
    Task ut = task("<a:b --> c:d>.");
    assertNotNull(ut);
    assertEquals(ut.term(), u);
}
Also used : Compound(nars.term.Compound) Test(org.junit.jupiter.api.Test)

Example 9 with Compound

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

the class TermIOTest method testTermSerialization3_2.

@Test
public void testTermSerialization3_2() throws Narsese.NarseseException {
    // multiple variables
    Variable q = $.varQuery(1);
    Compound twoB = $.inh($.varDep(2), Atomic.the("b"));
    assertNotEquals(q.compareTo(twoB), twoB.compareTo(q));
    assertTermEqualSerialize("((#a --> b) <-> ?c)");
    Term a = $("(#2-->b)");
    Term b = $("?1");
    int x = a.compareTo(b);
    int y = b.compareTo(a);
    assertNotEquals((int) Math.signum(x), (int) Math.signum(y));
}
Also used : Variable(nars.term.var.Variable) Compound(nars.term.Compound) Term(nars.term.Term) Test(org.junit.jupiter.api.Test)

Example 10 with Compound

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

the class DynamicTruthBeliefTableTest method testDynamicConjunction2Temporal.

@Test
public void testDynamicConjunction2Temporal() throws Narsese.NarseseException {
    NAR n = NARS.shell();
    n.believe($("(x)"), (long) 0);
    n.believe($("(y)"), (long) 4);
    n.time.dur(8);
    TaskConcept cc = (TaskConcept) n.conceptualize($("((x) && (y))"));
    DynamicTruthBeliefTable xtable = (DynamicTruthBeliefTable) cc.beliefs();
    Compound template = $("((x) &&+4 (y))");
    DynTruth xt = xtable.truth(0, 0, template, n);
    assertNotNull(xt);
    // assertTrue($.t(1f, 0.81f).equals(xt.truth(n), 0.1f), xt.truth(n).toString());
    // best match to the input
    assertEquals(0.81f, xtable.taskDynamic(0, 0, $("((x) &&+4 (y))"), n).conf(), 0.05f);
    assertEquals(0.74f, xtable.taskDynamic(0, 0, $("((x) &&+6 (y))"), n).conf(), 0.07f);
    assertEquals(0.75f, xtable.taskDynamic(0, 0, $("((x) &&+2 (y))"), n).conf(), 0.07f);
    assertEquals(0.75f, xtable.taskDynamic(0, 0, $("((x) &&+0 (y))"), n).conf(), 0.07f);
    assertEquals(0.62f, xtable.taskDynamic(0, 0, $("((x) &&-32 (y))"), n).conf(), 0.2f);
}
Also used : TaskConcept(nars.concept.TaskConcept) Compound(nars.term.Compound) 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