use of nars.derive.rule.DeriveRuleSource in project narchy by automenta.
the class EllipsisTest method testVarArg0.
@Disabled
@Test
public void testVarArg0() throws Narsese.NarseseException {
// String rule = "(%S --> %M), ((|, %S, %A..+ ) --> %M) |- ((|, %A, ..) --> %M), (Belief:DecomposePositiveNegativeNegative)";
String rule = "(%S ==> %M), ((&&,%S,%A..+) ==> %M) |- ((&&,%A..+) ==> %M), (Belief:DecomposeNegativePositivePositive, Order:ForAllSame, SequenceIntervals:FromBelief)";
Compound _x = $.$('<' + rule + '>');
assertTrue(_x instanceof DeriveRuleSource, _x.toString());
DeriveRuleSource x = (DeriveRuleSource) _x;
// System.out.println(x);
x = new DeriveRuleProto(x, new PatternIndex());
// System.out.println(x);
assertEquals("(((%1==>%2),((%1&&%3..+)==>%2)),(((&&,%3..+)==>%2),((DecomposeNegativePositivePositive-->Belief),(ForAllSame-->Order),(FromBelief-->SequenceIntervals))))", x.toString());
}
use of nars.derive.rule.DeriveRuleSource in project narchy by automenta.
the class TrieDeriverTest method testCompile.
public static DeriveRuleSet testCompile(boolean debug, String... rules) {
assertNotEquals(0, rules.length);
PatternIndex pi = new PatternIndex();
Stream<DeriveRuleSource> parsed = DeriveRuleSet.parse(Stream.of(rules));
DeriveRuleSet src = new DeriveRuleSet(parsed, pi, NARS.shell());
assertNotEquals(0, src.size());
DeriveRules d = the(src);
if (debug) {
// d.printRecursive();
// PrediTerm<Derivation> dd = d.what.transform(DebugDerivationPredicate::new);
}
return src;
}
use of nars.derive.rule.DeriveRuleSource in project narchy by automenta.
the class PremiseRuleTest method testParser.
@Test
public void testParser() throws Narsese.NarseseException {
// NAR p = new NAR(new Default());
assertNotNull(Narsese.term("<A --> b>"), "metaparser can is a superset of narsese");
//
assertEquals(0, Narsese.term("#A").complexity());
assertEquals(1, Narsese.term("#A").volume());
assertEquals(0, Narsese.term("%A").complexity());
assertEquals(1, Narsese.term("%A").volume());
assertEquals(3, Narsese.term("<A --> B>").complexity());
assertEquals(1, Narsese.term("<%A --> %B>").complexity());
{
// PremiseRule r = (PremiseRule) p.term(onlyRule);
// return rule(
// r
// );
DeriveRuleSource x = parse("A, A |- A, (Belief:Revision, Goal:Weak)");
assertNotNull(x);
// assertEquals("((A,A),(A,((Revision-->Belief),(Weak-->Desire))))", x.toString());
// assertEquals(12, x.getVolume());
}
int vv = 19;
{
// PremiseRule r = (PremiseRule) p.term(onlyRule);
// return rule(
// r
// );
DeriveRuleSource x = parse("<A --> B>, <B --> A> |- <A <-> B>, (Belief:Revision, Goal:Weak)");
// x = PremiseRule.rule(x);
assertEquals(vv, x.term().volume());
// assertEquals("(((%1-->%2),(%2-->%1)),((%1<->%2),((Revision-->Belief),(Weak-->Desire))))", x.toString());
}
{
// PremiseRule r = (PremiseRule) p.term(onlyRule);
// return rule(
// r
// );
DeriveRuleSource x = parse("<A --> B>, <B --> A> |- <A <-> nonvar>, (Belief:Revision, Goal:Weak)");
// x = PremiseRule.rule(x);
// same volume as previous block
assertEquals(vv, x.term().volume());
// assertEquals("(((%1-->%2),(%2-->%1)),((nonvar<->%1),((Revision-->Belief),(Weak-->Desire))))", x.toString());
}
{
// PremiseRule r = (PremiseRule) p.term(onlyRule);
// return rule(
// r
// );
DeriveRuleSource x = parse(" <A --> B>, <B --> A> |- <A <-> B>, (Belief:Conversion, Punctuation:Belief)");
// x = PremiseRule.rule(x);
assertEquals(vv, x.term().volume());
// assertEquals("(((%1-->%2),(%2-->%1)),((%1<->%2),((Conversion-->Belief),(Judgment-->Punctuation))))", x.toString());
}
// {
// TaskRule x = p.termRaw("<<A --> b> |- (X & y)>");
// assertEquals("((<A --> b>), ((&, X, y)))", x.toString());
// assertEquals(9, x.getVolume());
// }
// and the first complete rule:
// PremiseRule r = (PremiseRule) p.term(onlyRule);
// return rule(
// r
// );
DeriveRuleSource x = parse("(S --> M), (P --> M) |- (P <-> S), (Belief:Comparison,Goal:Strong)");
// x = PremiseRule.rule(x);
// assertEquals("(((%1-->%2),(%3-->%2)),((%1<->%3),((Comparison-->Belief),(Strong-->Desire))))", x.toString());
assertEquals(vv, x.term().volume());
}
Aggregations