View Javadoc

1   // BSD License (http://www.galagosearch.org/license)
2   package org.galagosearch.core.retrieval.structured;
3   
4   import java.io.IOException;
5   import java.util.ArrayList;
6   import org.galagosearch.tupleflow.Parameters;
7   import org.galagosearch.tupleflow.Utility;
8   
9   /***
10   *
11   * @author trevor
12   */
13  public class OrderedWindowIterator extends ExtentConjunctionIterator {
14      int width;
15  
16      /*** Creates a new instance of UnorderedWindowIterator */
17      public OrderedWindowIterator(Parameters parameters, ExtentIterator[] iterators) throws IOException {
18          super(iterators);
19          this.width = (int) parameters.getAsDefault("width", -1);
20          findDocument();
21      }
22  
23      public void loadExtents() {
24          ExtentArrayIterator[] iterators;
25  
26          iterators = new ExtentArrayIterator[extentIterators.length];
27          for (int i = 0; i < extentIterators.length; i++) {
28              iterators[i] = new ExtentArrayIterator(
29                      extentIterators[i].extents());
30          }
31          boolean notDone = true;
32          while (notDone) {
33              // find the start of the first word
34              boolean invalid = false;
35              int begin = iterators[0].current().begin;
36  
37              // loop over all the rest of the words
38              for (int i = 1; i < iterators.length; i++) {
39                  int end = iterators[i - 1].current().end;
40  
41                  // try to move this iterator so that it's past the end of the previous word
42                  while (end > iterators[i].current().begin) {
43                      notDone = iterators[i].next();
44  
45                      // if there are no more occurrences of this word,
46                      // no more ordered windows are possible
47                      if (!notDone) {
48                          return;
49                      }
50                  }
51  
52                  if (iterators[i].current().begin - end >= width) {
53                      invalid = true;
54                      break;
55                  }
56              }
57  
58              int end = iterators[iterators.length - 1].current().end;
59  
60              // if it's a match, record it
61              if (!invalid) {
62                  extents.add(document, begin, end);
63              }
64              notDone = iterators[0].next();
65          }
66      }
67  }