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());
}
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());
}
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("..+"));
}
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);
}
Aggregations