Search in sources :

Example 1 with DeriveRuleSet

use of nars.derive.rule.DeriveRuleSet in project narchy by automenta.

the class PremiseRuleTest method testTryFork.

@Test
public void testTryFork() {
    DeriveRules d = new DeriveRuleSet(NARS.shell(), "X,Y |- (X&&Y), (Belief:Intersection)", "X,Y |- (||,X,Y), (Belief:Union)").compile();
    /*
TODO - share unification state for different truth/conclusions
    TruthFork {
      (Union,_):
      (Intersection,_):
         (unify...
         (
      and {
        truth(Union,_)
        unify(task,%1)
        unify(belief,%2) {
          and {
            derive((||,%1,%2))
            taskify(3)
          }
        }
      }
      and {
        truth(Intersection,_)
        unify(task,%1)
        unify(belief,%2) {
 */
    d.printRecursive();
}
Also used : DeriveRuleSet(nars.derive.rule.DeriveRuleSet) Test(org.junit.jupiter.api.Test)

Example 2 with DeriveRuleSet

use of nars.derive.rule.DeriveRuleSet in project narchy by automenta.

the class PremiseRuleTest method testMinSubsRulePredicate.

// @Test
// public void testNotSingleVariableRule1() throws Narsese.NarseseException {
// //tests an exceptional case that should now be fixed
// 
// String l = "((B,P) --> ?X) ,(B --> A), task(\"?\") |- ((B,P) --> (A,P)), (Belief:BeliefStructuralDeduction, Punctuation:Judgment)";
// new PremiseRuleSet(new PatternTermIndex(n), l).
// 
// Compound x = parse(l, i).normalizeRule(i);
// assertNotNull(x);
// assertNotNull(x.toString());
// assertTrue(!x.toString().contains("%B"));
// }
@Test
public void testMinSubsRulePredicate() {
    // test that the constraint on %2 being of size > 1 is testable in the Proto phase
    DeriveRules d = new DeriveRuleSet(NARS.shell(), "(A-->B),B,is(B,\"[\"),subsMin(B,2) |- (A-->dropAnySet(B)), (Belief:StructuralDeduction)").compile();
    d.printRecursive();
    assertNotNull(d);
}
Also used : DeriveRuleSet(nars.derive.rule.DeriveRuleSet) Test(org.junit.jupiter.api.Test)

Example 3 with DeriveRuleSet

use of nars.derive.rule.DeriveRuleSet in project narchy by automenta.

the class PremiseRuleTest method testConjWithEllipsisIsXternal.

@Test
public void testConjWithEllipsisIsXternal() {
    DeriveRules d = new DeriveRuleSet(NARS.shell(), "X,Y |- (&&,X,%A..+), (Belief:Analogy)", "X,Y |- (&&,%A..+), (Belief:Analogy)").compile();
    d.printRecursive();
}
Also used : DeriveRuleSet(nars.derive.rule.DeriveRuleSet) Test(org.junit.jupiter.api.Test)

Example 4 with DeriveRuleSet

use of nars.derive.rule.DeriveRuleSet 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 5 with DeriveRuleSet

use of nars.derive.rule.DeriveRuleSet 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

DeriveRuleSet (nars.derive.rule.DeriveRuleSet)6 Test (org.junit.jupiter.api.Test)5 DeriveRules (nars.derive.DeriveRules)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