private Iterator<Pair<DictionaryTerm, InvertedListPointer>> mergeInvertedLists(
     InvertedListBuilder output,
     Map<Long, Float> tdIdfWeightAccumulator,
     long newTotalDocuments,
     InvertedList... inputs)
     throws IOException, InterruptedException {
   AnnotatingIterator<Pair<DictionaryTerm, InvertedListPointer>, InvertedList>[] listIterators =
       new AnnotatingIterator[inputs.length];
   int position = 0;
   for (InvertedList list : inputs) {
     listIterators[position++] =
         new AnnotatingIterator<Pair<DictionaryTerm, InvertedListPointer>, InvertedList>(
             list.getTermIterator(), list);
   }
   IteratorMerger<Pair<Pair<DictionaryTerm, InvertedListPointer>, InvertedList>>
       mergedTermIterators =
           new IteratorMerger<Pair<Pair<DictionaryTerm, InvertedListPointer>, InvertedList>>(
               TERM_MERGE_COMP, listIterators);
   DuplicateCollectingIterator<Pair<Pair<DictionaryTerm, InvertedListPointer>, InvertedList>>
       collectedTerms =
           new DuplicateCollectingIterator<
               Pair<Pair<DictionaryTerm, InvertedListPointer>, InvertedList>>(
               TERM_MERGE_COMP, mergedTermIterators);
   return new LazyMergedInvertedListWriterIterator(
       collectedTerms, output, newTotalDocuments, tdIdfWeightAccumulator);
 }
Пример #2
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    InvertedList list = new InvertedList();
    TestDoc doc = new TestDoc(list);
    FileReptile visitor = new FileReptile(doc);
    Scanner sc = new Scanner(System.in);
    System.out.println("Please Enter Path Name:");
    Path path = Paths.get(sc.nextLine()).normalize().toAbsolutePath();
    System.out.println("Scanning......\nPlease Wait......");
    try {
      if (!path.toFile().exists()) {
        sc.close();
        throw new Exception();
      }

      Files.walkFileTree(path, visitor);
    } catch (Exception e) {
      // e.printStackTrace();
      System.out.println("Scanning Failed");
      System.exit(-1);
    }
    // list.testOutput();
    String s;
    Pattern p = Pattern.compile("[\\w]{1,}");
    Matcher m;
    System.out.println("Scanning complete, you can search now!");
    while (true) {
      System.out.println("I search:");
      s = sc.nextLine();
      if (s.equals("quit")) break;
      m = p.matcher(s);
      if (m.find()) list.searchAndOutput(s);
    }
    sc.close();
  }