use of nars.derive.DeriveRules 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.DeriveRules in project narchy by automenta.
the class TrieDeriverTest method testConclusionWithXTERNAL.
// @Test public void testRuleSerialization() {
// byte[] x = IO.termToBytes( NARS.tmp(1).derivation().deriver );
// assertTrue(x.length > 128 );
// System.out.println(x.length + " bytes");
//
// Term y = IO.termFromBytes(x);
// assertTrue(y.volume() > 64 );
// //System.out.println(y);
//
// // z = new PremiseRuleSet.rules()
// //TrieDeriver.print(y);
// }
@Test
public void testConclusionWithXTERNAL() {
PatternIndex idx = new PatternIndex() {
@Override
@Nullable
public Termed get(@NotNull Term x, boolean create) {
Termed u = super.get(x, create);
assertNotNull(u);
if (u != x) {
System.out.println(x + " (" + x.getClass() + ")" + " -> " + u + " (" + u.getClass() + ")");
if (u.equals(x) && u.getClass().equals(x)) {
fail("\t ^ same class, wasteful duplicate");
}
}
return u;
}
};
DeriveRules d = the(new DeriveRuleSet(idx, NARS.shell(), "Y, Y |- (?1 &&+0 Y), ()", "X, X |- (?1 &&+- X), ()"));
System.out.println();
d.printRecursive();
System.out.println(d);
String ds = d.toString();
assertTrue(ds.contains("?2&|"));
assertTrue(ds.contains("?2 &&+-"));
// assertTrue("something at least got stored in the index", idx.size() > 16);
// test that A..+ survives as an ellipsis
// assertTrue(d.trie.getSummary().contains("..+"));
}
Aggregations