Search in sources :

Example 6 with PatternIndex

use of nars.index.term.PatternIndex 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

PatternIndex (nars.index.term.PatternIndex)6 DeriveRules (nars.derive.DeriveRules)3 DeriveRuleSource (nars.derive.rule.DeriveRuleSource)3 Compound (nars.term.Compound)3 Term (nars.term.Term)3 NAR (nars.NAR)2 DeriveRuleProto (nars.derive.rule.DeriveRuleProto)2 DeriveRuleSet (nars.derive.rule.DeriveRuleSet)2 Termed (nars.term.Termed)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.junit.jupiter.api.Test)2 Splitter (com.google.common.base.Splitter)1 Streams (com.google.common.collect.Streams)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 java.util (java.util)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1