Search in sources :

Example 6 with NAR

use of nars.main.NAR in project opennars by opennars.

the class TermTest method testTermSort.

@Test
public void testTermSort() throws Exception {
    NAR n = new NAR();
    Narsese m = new Narsese(n);
    Term a = m.parseTerm("a");
    Term b = m.parseTerm("b");
    Term c = m.parseTerm("c");
    assertEquals(3, Term.toSortedSetArray(a, b, c).length);
    assertEquals(2, Term.toSortedSetArray(a, b, b).length);
    assertEquals(1, Term.toSortedSetArray(a, a).length);
    assertEquals(1, Term.toSortedSetArray(a).length);
    assertEquals("correct natural ordering", a, Term.toSortedSetArray(a, b)[0]);
}
Also used : Narsese(nars.io.Narsese) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) NAR(nars.main.NAR) Test(org.junit.Test)

Example 7 with NAR

use of nars.main.NAR in project opennars by opennars.

the class TermTest method invalidTermIndep.

@Test
public void invalidTermIndep() {
    String t = "<$1 --> (~,{place4},$1)>";
    NAR n = new NAR();
    Narsese p = new Narsese(n);
    try {
        p.parseNarsese(new StringBuilder(t + "."));
        assertTrue(false);
    } catch (Narsese.InvalidInputException ex) {
        assertTrue(true);
    }
    Term subj = null, pred = null;
    try {
        subj = p.parseTerm("$1");
        pred = p.parseTerm("(~,{place4},$1)");
        assertTrue(true);
    } catch (Narsese.InvalidInputException ex) {
        assertTrue(false);
    }
    Statement s = Statement.make(NativeOperator.INHERITANCE, subj, pred, false, 0);
    assertEquals(null, s);
    Inheritance i = Inheritance.make(subj, pred);
    assertEquals(null, i);
    try {
        CompoundTerm forced = (CompoundTerm) p.parseTerm("<a --> b>");
        assertTrue(true);
        forced.term[0] = subj;
        forced.term[1] = pred;
        forced.invalidateName();
        assertEquals(t, forced.toString());
        CompoundTerm cloned = forced.clone();
        assertEquals(null, cloned);
    } catch (Narsese.InvalidInputException ex) {
        assertTrue(false);
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) Statement(nars.language.Statement) Inheritance(nars.language.Inheritance) Narsese(nars.io.Narsese) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) NAR(nars.main.NAR) Test(org.junit.Test)

Example 8 with NAR

use of nars.main.NAR in project opennars by opennars.

the class TermTest method assertEquivalent.

protected void assertEquivalent(String term1String, String term2String) {
    try {
        NAR n = new NAR();
        Term term1 = np.parseTerm(term1String);
        Term term2 = np.parseTerm(term2String);
        assertTrue(term1 instanceof CompoundTerm);
        assertTrue(term2 instanceof CompoundTerm);
        assert (!term1String.equals(term2String));
        assert (term1.hashCode() == term2.hashCode());
        assert (term1.equals(term2));
        assert (term1.compareTo(term2) == 0);
    } catch (Exception e) {
        assertTrue(e.toString(), false);
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) NAR(nars.main.NAR)

Example 9 with NAR

use of nars.main.NAR in project opennars by opennars.

the class TermTest method testConjunctionTreeSet.

@Test
public void testConjunctionTreeSet() throws Narsese.InvalidInputException {
    NAR n = new NAR();
    // these 2 representations are equal, after natural ordering
    String term1String = "<#1 --> (&,boy,(/,taller_than,{Tom},_))>";
    Term term1 = np.parseTerm(term1String);
    String term1Alternate = "<#1 --> (&,(/,taller_than,{Tom},_),boy)>";
    Term term1a = np.parseTerm(term1Alternate);
    // <#1 --> (|,boy,(/,taller_than,{Tom},_))>
    Term term2 = np.parseTerm("<#1 --> (|,boy,(/,taller_than,{Tom},_))>");
    assertTrue(term1.toString().equals(term1a.toString()));
    assertTrue(term1.getComplexity() > 1);
    assertTrue(term1.getComplexity() == term2.getComplexity());
    assertTrue(term1.getClass().equals(Inheritance.class));
    assertTrue(term1.getClass().equals(Inheritance.class));
    // System.out.println("t1: " + term1 + ", complexity=" + term1.getComplexity());
    // System.out.println("t2: " + term2 + ", complexity=" + term2.getComplexity());
    assertTrue(term1.equals(term1.clone()));
    assertTrue(term1.compareTo(term1.clone()) == 0);
    assertTrue(term2.equals(term2.clone()));
    assertTrue(term2.compareTo(term2.clone()) == 0);
    boolean t1e2 = term1.equals(term2);
    int t1c2 = term1.compareTo(term2);
    int t2c1 = term2.compareTo(term1);
    assertTrue(!t1e2);
    assertTrue("term1 and term2 inequal, so t1.compareTo(t2) should not = 0", t1c2 != 0);
    assertTrue("term1 and term2 inequal, so t2.compareTo(t1) should not = 0", t2c1 != 0);
    /*
        System.out.println("t1 equals t2 " + t1e2);
        System.out.println("t1 compareTo t2 " + t1c2);
        System.out.println("t2 compareTo t1 " + t2c1);
        */
    TreeSet<Term> set = new TreeSet<>();
    boolean added1 = set.add((Term) term1.clone());
    boolean added2 = set.add((Term) term2.clone());
    assertTrue("term 1 added to set", added1);
    assertTrue("term 2 added to set", added2);
    assertTrue(set.size() == 2);
}
Also used : TreeSet(java.util.TreeSet) Inheritance(nars.language.Inheritance) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) NAR(nars.main.NAR) Test(org.junit.Test)

Example 10 with NAR

use of nars.main.NAR in project opennars by opennars.

the class TuneTuffy method main.

public static void main(String[] args) throws FileNotFoundException, Narsese.InvalidInputException {
    NAR n = new NAR();
    n.addInputFile("nal/use_cases/tuffy.smokes.nal");
    // new TextOutput(n, System.out, 0.95f);
    SolutionMonitor anna0 = new SolutionMonitor(n, "<Anna <-> [Smokes]>");
    SolutionMonitor bob0 = new SolutionMonitor(n, "<Bob --> [Smokes]>");
    SolutionMonitor edward0 = new SolutionMonitor(n, "<Edward --> [Smokes]>");
    SolutionMonitor frank0 = new SolutionMonitor(n, "<Frank --> [Smokes]>");
    SolutionMonitor anna = new SolutionMonitor(n, "<Anna <-> [Cancer]>");
    SolutionMonitor bob = new SolutionMonitor(n, "<Bob --> [Cancer]>");
    SolutionMonitor edward = new SolutionMonitor(n, "<Edward --> [Cancer]>");
    SolutionMonitor frank = new SolutionMonitor(n, "<Frank --> [Cancer]>");
    n.run();
    // first number is the expected Tuffy probability result
    System.out.println("0.75? " + edward);
    System.out.println("0.65? " + anna);
    System.out.println("0.50? " + bob);
    System.out.println("0.45? " + frank);
}
Also used : NAR(nars.main.NAR)

Aggregations

NAR (nars.main.NAR)28 Test (org.junit.Test)10 Term (nars.language.Term)9 NARSwing (nars.gui.NARSwing)8 CompoundTerm (nars.language.CompoundTerm)8 Narsese (nars.io.Narsese)5 Sentence (nars.entity.Sentence)4 AnswerHandler (nars.io.events.AnswerHandler)4 NWindow (automenta.vivisect.swing.NWindow)3 TextOutputHandler (nars.io.events.TextOutputHandler)3 LineChart (automenta.vivisect.timeline.LineChart)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Concept (nars.entity.Concept)2 Inheritance (nars.language.Inheritance)2 TreeMLData (automenta.vivisect.TreeMLData)1 PCanvas (automenta.vivisect.swing.PCanvas)1 Chart (automenta.vivisect.timeline.Chart)1 MultiTimeline (automenta.vivisect.timeline.MultiTimeline)1 StackedPercentageChart (automenta.vivisect.timeline.StackedPercentageChart)1