Search in sources :

Example 1 with Reference

use of suite.text.TwoPassIndexer.Reference in project suite by stupidsing.

the class TwoPassIndexerTest method test.

@Test
public void test() {
    List<String> filenames = // 
    FileUtil.findPaths(Paths.get("src/test/java")).map(// 
    Path::toAbsolutePath).map(// 
    Path::toString).filter(// 
    filename -> filename.endsWith(".java")).toList();
    TwoPassIndexer indexer = new TwoPassIndexer();
    for (String filename : filenames) indexer.pass0(filename, FileUtil.read(filename));
    for (String filename : filenames) indexer.pass1(filename, FileUtil.read(filename));
    Map<String, List<Reference>> map = indexer.getReferencesByWord();
    List<Entry<String, List<Reference>>> entries = // 
    List_.sort(// 
    map.entrySet(), (e0, e1) -> e1.getValue().size() - e0.getValue().size());
    System.out.println("Most popular key words:");
    for (int i = 0; i < 32; i++) {
        Entry<String, List<Reference>> entry = entries.get(i);
        System.out.println(String.format("%-5d \"%s\"", entry.getValue().size(), entry.getKey()));
    }
    System.out.println();
    for (Reference key : indexer.search("IOException")) System.out.println("IOException found in " + key);
}
Also used : Path(java.nio.file.Path) List(java.util.List) Paths(java.nio.file.Paths) Map(java.util.Map) Entry(java.util.Map.Entry) FileUtil(suite.os.FileUtil) List_(suite.util.List_) Test(org.junit.Test) Path(java.nio.file.Path) Reference(suite.text.TwoPassIndexer.Reference) Entry(java.util.Map.Entry) Reference(suite.text.TwoPassIndexer.Reference) List(java.util.List) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Test (org.junit.Test)1 FileUtil (suite.os.FileUtil)1 Reference (suite.text.TwoPassIndexer.Reference)1 List_ (suite.util.List_)1