use of nars.index.term.TreeConceptIndex in project narchy by automenta.
the class TermTreeTest method testCompoundInsertion.
@Test
public void testCompoundInsertion() throws Narsese.NarseseException {
TreeConceptIndex index;
NAR nar = new NARS().index(index = new TreeConceptIndex(1000)).get();
int preSize = index.size();
String[] terms = { "x", "(x)", "(xx)", "(xxx)", "(x,y)", "(x,z)", "(x --> z)", "(x <-> z)", "(x&&z)" };
HashSet<Term> input = new HashSet();
for (String s : terms) {
@NotNull Term ts = $(s);
input.add(ts);
index.get(ts, true);
}
assertEquals(terms.length + preSize, index.size());
for (Term x : input) assertNotNull(index.get(x, false));
// Set<Termed> stored = StreamSupport.stream(index.concepts.spliterator(), false).collect(Collectors.toSet());
// assertEquals(Sets.symmetricDifference(input, stored) + " = difference", input, stored);
index.concepts.prettyPrint();
index.print(System.out);
// String stringWithUnicode = "unicode\u00easomething";
// assertNull( tree.resolveOrAdd(stringWithUnicode)); //unicode not supported yet
}
use of nars.index.term.TreeConceptIndex in project narchy by automenta.
the class TreeConceptIndexTest method testVolumeSubTrees.
@Test
public void testVolumeSubTrees() throws Narsese.NarseseException {
TreeConceptIndex t = new TreeConceptIndex(128);
t.set($("a"));
t.set($("(a)"));
t.set($("(a-->b)"));
t.set($("(a-->(b,c,d))"));
t.set($("(a-->(b,c,d,e,f,g))"));
t.set($("(a-->(b,c,d,e,f,g,h,i,j,k))"));
t.concepts.prettyPrint(System.out);
t.print(System.out);
assertEquals(6, t.size());
System.out.println(t.concepts.root);
// each item is in a different leaf because of the volume byte prefix
List<MyConcurrentRadixTree.Node> oe = t.concepts.root.getOutgoingEdges();
assertEquals(6, oe.size());
assertTrue(oe.get(0).toString().length() < oe.get(1).toString().length());
assertTrue(oe.get(0).toString().length() < oe.get(oe.size() - 1).toString().length());
}