Search in sources :

Example 1 with Narsese

use of nars.io.Narsese in project opennars by opennars.

the class TermTest method testParseOperationInFunctionalForm.

@Test
public void testParseOperationInFunctionalForm() {
    Parameters.FUNCTIONAL_OPERATIONAL_FORMAT = true;
    NAR n = new NAR();
    Narsese p = new Narsese(n);
    try {
        Term x = p.parseTerm("wonder(a,b)");
        assertEquals(Operation.class, x.getClass());
        assertEquals("(^wonder,a,b)", x.toString());
    } catch (Narsese.InvalidInputException ex) {
        ex.printStackTrace();
        assertTrue(false);
    }
}
Also used : Narsese(nars.io.Narsese) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) NAR(nars.main.NAR) Test(org.junit.Test)

Example 2 with Narsese

use of nars.io.Narsese 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 3 with Narsese

use of nars.io.Narsese 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 4 with Narsese

use of nars.io.Narsese in project opennars by opennars.

the class SensoryChannel method addInput.

public void addInput(final String text) {
    try {
        Task t = new Narsese(nar).parseTask(text);
        this.addInput(t);
    } catch (Narsese.InvalidInputException ex) {
        Logger.getLogger(SensoryChannel.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : Task(nars.entity.Task) Narsese(nars.io.Narsese)

Example 5 with Narsese

use of nars.io.Narsese in project opennars by opennars.

the class NAR method ask.

public NAR ask(String termString, AnswerHandler answered) throws InvalidInputException {
    Task t;
    addInput(t = new Task(new Sentence(new Narsese(this).parseTerm(termString), Symbols.QUESTION_MARK, null, new Stamp(memory, Tense.Eternal)), new BudgetValue(Parameters.DEFAULT_QUESTION_PRIORITY, Parameters.DEFAULT_QUESTION_DURABILITY, 1), true));
    if (answered != null) {
        answered.start(t, this);
    }
    return this;
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Narsese(nars.io.Narsese) Sentence(nars.entity.Sentence)

Aggregations

Narsese (nars.io.Narsese)8 Task (nars.entity.Task)5 CompoundTerm (nars.language.CompoundTerm)3 Term (nars.language.Term)3 NAR (nars.main.NAR)3 Test (org.junit.Test)3 BudgetValue (nars.entity.BudgetValue)2 Sentence (nars.entity.Sentence)2 Stamp (nars.entity.Stamp)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvalidInputException (nars.io.Narsese.InvalidInputException)1 Inheritance (nars.language.Inheritance)1 Statement (nars.language.Statement)1