Search in sources :

Example 11 with Termed

use of nars.term.Termed in project narchy by automenta.

the class TermIOTest method assertTermEqualSerialize.

static void assertTermEqualSerialize(String s) throws Narsese.NarseseException {
    Termed t = $.$(s);
    assertTrue(t.isNormalized());
    assertTrue(t.term().isNormalized());
    assertEqualSerialize(t.term());
}
Also used : Termed(nars.term.Termed)

Example 12 with Termed

use of nars.term.Termed in project narchy by automenta.

the class LinkageTest method ProperlyLinkedIndirectlyTest.

// interlinked with an intermediate concept, this is needed in order to select one as task and the other as belief
public void ProperlyLinkedIndirectlyTest(@NotNull String spremise1, byte punc, @NotNull String spremise2) throws Exception {
    test.requireConditions = false;
    NAR nar = test.nar;
    // nar.log();
    Termed premise1 = $.$(spremise1);
    assertEquals($.$(spremise1), premise1, "reparsed");
    assertNotNull(premise1);
    assertEquals($.$(spremise1), premise1);
    Termed premise2 = $.$(spremise2);
    assertEquals($.$(spremise2), premise2, "reparsed");
    assertNotNull(premise2);
    assertEquals($.$(spremise2), premise2);
    String t1 = getTask(punc, premise1);
    String t2 = getTask(punc, premise2);
    nar.input(t1, t2).run(runCycles);
    // List<String> fails = new ArrayList();
    @Nullable Concept p1 = nar.concept(premise1);
    assertNotNull(p1.state());
    // p1.print(); System.out.println("------------------------");
    Concept p2 = nar.concept(premise2);
    assertNotNull(p2);
    assertNotNull(p2.state());
    // c2.print(); System.out.println("------------------------");
    AdjGraph<Term, Float> g = TermGraph.termlink(nar);
    boolean p12 = linksIndirectly(p1, p2, nar);
    assertTrue(p12, why(nar, premise1, premise2));
    boolean p21 = linksIndirectly(p2, p1, nar);
    assertTrue(p21, why(nar, premise2, premise1));
    System.err.println(premise1 + " not linked with " + premise2);
    int numNodes = g.nodeCount();
    assertTrue(numNodes > 0);
    assertTrue(g.edgeCount() > 0, g.toString());
// for (Term x : g.nodes()) {
// assertEquals(x + " not reachable by all other nodes", numNodes, Graphs.reachableNodes(g.asGraph(), x).size());
// }
// //g.print(System.out);
// //System.out.println(g.isConnected() + " " + g.vertexSet().size() + " " + g.edgeSet().size());
// if (!g.isConnected()) {
// //        if (!g.isStronglyConnected()) {
// //            StrongConnectivityInspector ci =
// ConnectivityInspector ci = new ConnectivityInspector(g);
// //                    new StrongConnectivityInspector(g);
// 
// System.out.println("premises: " + premise1 + " and " + premise2 + " termlink subgraph connectivity:");
// 
// ci
// .connectedSets()
// //.stronglyConnectedSubgraphs()
// .forEach( s -> System.out.println("\t" + s));
// 
// nar.forEachConceptActive(x -> x.get().print());
// 
// }
// assertTrue(g.isConnected());
}
Also used : Termed(nars.term.Termed) Concept(nars.concept.Concept) Term(nars.term.Term) TestNAR(nars.test.TestNAR) NAR(nars.NAR) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with Termed

use of nars.term.Termed 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)

Example 14 with Termed

use of nars.term.Termed in project narchy by automenta.

the class CaffeineIndexTest method testDynamicWeight.

@Test
public void testDynamicWeight() throws Narsese.NarseseException {
    StringBuilder log = new StringBuilder();
    CaffeineIndex index;
    NAR n = new NARS().index(index = new CaffeineIndex(4000, (w) -> {
        int newWeight = Math.round(1000 * (w.tasklinks().priSum() + w.termlinks().priSum()));
        log.append("weigh ").append(w).append(' ').append(newWeight).append('\n');
        return newWeight;
    }) {

        @Override
        public Termed get(Term x, boolean createIfMissing) {
            log.append("get ").append(x).append(createIfMissing ? " createIfMissing\n" : "\n");
            return super.get(x, createIfMissing);
        }
    }).get();
    n.believe("(x-->y).");
    n.believe("(x-->y).");
    System.out.println(log);
}
Also used : NARS(nars.NARS) Test(org.junit.jupiter.api.Test) NARS(nars.NARS) Narsese(nars.Narsese) NAR(nars.NAR) Termed(nars.term.Termed) Term(nars.term.Term) Termed(nars.term.Termed) Term(nars.term.Term) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Aggregations

Termed (nars.term.Termed)14 Term (nars.term.Term)8 NAR (nars.NAR)5 Concept (nars.concept.Concept)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Test (org.junit.jupiter.api.Test)3 Op (nars.Op)2 PatternIndex (nars.index.term.PatternIndex)2 Subterms (nars.subterm.Subterms)2 PrediTerm (nars.term.pred.PrediTerm)2 com.github.benmanes.caffeine.cache (com.github.benmanes.caffeine.cache)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 TreeSet (java.util.TreeSet)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 nars.$ (nars.$)1