@Test public void dictionaryContainTest() { ArrayList<String> str = new ArrayList<String>(); str.add("part"); str.add("part"); // meant to be dup str.add("par"); str.add("partition"); str.add("party"); str.add("parties"); str.add("paint"); TrieDictionaryBuilder<String> b = newDictBuilder(str); int baseId = new Random().nextInt(100); TrieDictionary<String> dict = b.build(baseId); str.add("py"); b = newDictBuilder(str); baseId = new Random().nextInt(100); TrieDictionary<String> dict2 = b.build(baseId); assertEquals(true, dict2.contains(dict)); assertEquals(false, dict.contains(dict2)); }
private void testEnumeratorValues(String file) throws Exception { InputStream is = new FileInputStream(file); ArrayList<String> str = loadStrings(is); TrieDictionaryBuilder<String> b = newDictBuilder(str); TrieDictionary<String> dict = b.build(0); System.out.println("Dictionary size for file " + file + " is " + dict.getSize()); Stopwatch sw = new Stopwatch(); sw.start(); List<String> values1 = dict.enumeratorValuesByParent(); System.out.println("By iterating id visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms"); sw.reset(); sw.start(); List<String> values2 = dict.enumeratorValues(); System.out.println("By pre-order visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms"); sw.stop(); assertEquals(Sets.newHashSet(values1), Sets.newHashSet(values2)); }
private static void benchmarkStringDictionary(Iterable<String> str) throws IOException { TrieDictionaryBuilder<String> b = newDictBuilder(str); b.stats().print(); TrieDictionary<String> dict = b.build(0);
TrieDictionaryBuilder<String> b = newDictBuilder(str); TrieDictionary<String> dict = b.build(0);
@Test public void testAllNullValue() { ArrayList<String> strs = new ArrayList<String>(); strs.add(""); TrieDictionaryBuilder<String> builder = newDictBuilder(strs); TrieDictionary<String> dict = builder.build(0); assertEquals(1, dict.getSize()); assertEquals(0, dict.getIdFromValue("")); }
private static void testStringDictionary(ArrayList<String> str, ArrayList<String> notFound) { TrieDictionaryBuilder<String> b = newDictBuilder(str); int baseId = new Random().nextInt(100); TrieDictionary<String> dict = b.build(baseId);
private static void benchmarkStringDictionary(ArrayList<String> str) throws UnsupportedEncodingException { TrieDictionaryBuilder<String> b = newDictBuilder(str); b.stats().print(); TrieDictionary<String> dict = b.build(0);
TrieDictionaryBuilder<String> b = newDictBuilder(str); TrieDictionary<String> dict = b.build(0);
private static void testStringDictionary(ArrayList<String> str, ArrayList<String> notFound) { TrieDictionaryBuilder<String> b = newDictBuilder(str); int baseId = new Random().nextInt(100); TrieDictionary<String> dict = b.build(baseId);