FileSystem fs = FileSystem.getLocal(new Configuration());
Path termsFilePath = new Path("etc/trec-index-terms.dat");
Path termIDsFilePath = new Path("etc/trec-index-termids.dat");
Path idToTermFilePath = new Path("etc/trec-index-termid-mapping.dat");
DefaultFrequencySortedDictionary dictionary =
new DefaultFrequencySortedDictionary(termsFilePath, termIDsFilePath, idToTermFilePath, fs);
assertEquals(312232, dictionary.size());
assertEquals("page", dictionary.getTerm(1));
assertEquals("time", dictionary.getTerm(2));
assertEquals("will", dictionary.getTerm(3));
assertEquals("year", dictionary.getTerm(4));
assertEquals("nikaan", dictionary.getTerm(100000));
assertEquals(1, dictionary.getId("page"));
assertEquals(2, dictionary.getId("time"));
assertEquals(3, dictionary.getId("will"));
assertEquals(4, dictionary.getId("year"));
assertEquals(100000, dictionary.getId("nikaan"));
assertEquals(null, dictionary.getTerm(312233));
Iterator<String> iter = dictionary.iterator();
assertTrue(iter.hasNext());
assertEquals("page", iter.next());
assertTrue(iter.hasNext());
assertEquals("time", iter.next());
assertTrue(iter.hasNext());
assertEquals("will", iter.next());
assertTrue(iter.hasNext());
assertEquals("year", iter.next());
assertTrue(iter.hasNext());
int cnt = 0;
for (@SuppressWarnings("unused") String s : dictionary) {
cnt++;
}
assertEquals(dictionary.size(), cnt);
cnt = 0;
iter = dictionary.iterator();
while(iter.hasNext()) {
cnt++;
iter.next();
}
assertEquals(dictionary.size(), cnt);
}