Search in sources :

Example 1 with DeriveRules

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;
}
Also used : DeriveRules(nars.derive.DeriveRules) DeriveRuleSource(nars.derive.rule.DeriveRuleSource) DeriveRuleSet(nars.derive.rule.DeriveRuleSet) PatternIndex(nars.index.term.PatternIndex)

Example 2 with DeriveRules

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("..+"));
}
Also used : Termed(nars.term.Termed) DeriveRules(nars.derive.DeriveRules) Term(nars.term.Term) DeriveRuleSet(nars.derive.rule.DeriveRuleSet) PatternIndex(nars.index.term.PatternIndex) NotNull(org.jetbrains.annotations.NotNull) Test(org.junit.jupiter.api.Test)

Aggregations

DeriveRules (nars.derive.DeriveRules)2 DeriveRuleSet (nars.derive.rule.DeriveRuleSet)2 PatternIndex (nars.index.term.PatternIndex)2 DeriveRuleSource (nars.derive.rule.DeriveRuleSource)1 Term (nars.term.Term)1 Termed (nars.term.Termed)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.jupiter.api.Test)1