Search in sources :

Example 1 with TreeConceptIndex

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
}
Also used : NARS(nars.NARS) TreeConceptIndex(nars.index.term.TreeConceptIndex) NotNull(org.jetbrains.annotations.NotNull) NAR(nars.NAR) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with TreeConceptIndex

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());
}
Also used : TreeConceptIndex(nars.index.term.TreeConceptIndex) Test(org.junit.jupiter.api.Test)

Aggregations

TreeConceptIndex (nars.index.term.TreeConceptIndex)2 Test (org.junit.jupiter.api.Test)2 HashSet (java.util.HashSet)1 NAR (nars.NAR)1 NARS (nars.NARS)1 NotNull (org.jetbrains.annotations.NotNull)1