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);
}
}
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]);
}
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);
}
}
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);
}
}
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;
}
Aggregations