Finder implements Closeable { public List<NGramModel> find(String aGram) { return find(aGram.split(" ")); } Finder(File aIndexFolder, File nGramFolder); BigInteger freq(String aUnigram); BigInteger getUnigramCount(); List<NGramModel> find(String aGram); @SuppressWarnings("unchecked") List<NGramModel> find(String[] aToken); boolean contains(String aWord); @Override void close();  }
@Test public void testFinder1() throws Exception { File index = testContext.getTestOutputFolder(); LuceneIndexer indexer = new LuceneIndexer(source, index); indexer.index(); try (Finder f = new Finder(index, jWeb1T)) { List<NGramModel> result = f.find("couch"); assertEquals(1, result.size()); assertEquals("relax on the couch", result.get(0).getGram()); assertEquals(4, result.get(0).getN()); assertEquals(100, result.get(0).getFreq()); result = f.find("relax couch"); assertEquals(1, result.size()); assertEquals("relax on the couch", result.get(0).getGram()); assertEquals(4, result.get(0).getN()); assertEquals(100, result.get(0).getFreq()); result = f.find("relax"); assertEquals(3, result.size()); result = f.find("relax"); assertEquals(3, result.size()); } for (File file : index.listFiles()) { for (File _f : file.listFiles()) { _f.delete(); } file.delete(); } index.delete(); }
@Test public void testFinder2() throws Exception { File index = testContext.getTestOutputFolder(); LuceneIndexer indexer = new LuceneIndexer(source, index, 2); indexer.index(); try (Finder f = new Finder(index, jWeb1T)) { List<NGramModel> result = f.find("couch"); assertEquals(1, result.size()); assertEquals("relax on the couch", result.get(0).getGram()); assertEquals(4, result.get(0).getN()); assertEquals(100, result.get(0).getFreq()); result = f.find("relax couch"); assertEquals(1, result.size()); assertEquals("relax on the couch", result.get(0).getGram()); assertEquals(4, result.get(0).getN()); assertEquals(100, result.get(0).getFreq()); result = f.find("relax"); assertEquals(3, result.size()); result = f.find("relax"); assertEquals(3, result.size()); } for (File file : index.listFiles()) { for (File _f : file.listFiles()) { _f.delete(); } file.delete(); } index.delete(); }