Coverage Report - org.galagosearch.core.retrieval.structured.OrderedWindowIterator
 
Classes in this File Line Coverage Branch Coverage Complexity
OrderedWindowIterator
92%
24/26
79%
11/14
5
 
 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  12
         super(iterators);
 19  12
         this.width = (int) parameters.getAsDefault("width", -1);
 20  12
         findDocument();
 21  12
     }
 22  
 
 23  
     public void loadExtents() {
 24  
         ExtentArrayIterator[] iterators;
 25  
 
 26  8
         iterators = new ExtentArrayIterator[extentIterators.length];
 27  24
         for (int i = 0; i < extentIterators.length; i++) {
 28  16
             iterators[i] = new ExtentArrayIterator(
 29  
                     extentIterators[i].extents());
 30  
         }
 31  8
         boolean notDone = true;
 32  12
         while (notDone) {
 33  
             // find the start of the first word
 34  8
             boolean invalid = false;
 35  8
             int begin = iterators[0].current().begin;
 36  
 
 37  
             // loop over all the rest of the words
 38  12
             for (int i = 1; i < iterators.length; i++) {
 39  8
                 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  8
                 while (end > iterators[i].current().begin) {
 43  4
                     notDone = iterators[i].next();
 44  
 
 45  
                     // if there are no more occurrences of this word,
 46  
                     // no more ordered windows are possible
 47  4
                     if (!notDone) {
 48  4
                         return;
 49  
                     }
 50  
                 }
 51  
 
 52  4
                 if (iterators[i].current().begin - end >= width) {
 53  0
                     invalid = true;
 54  0
                     break;
 55  
                 }
 56  
             }
 57  
 
 58  4
             int end = iterators[iterators.length - 1].current().end;
 59  
 
 60  
             // if it's a match, record it
 61  4
             if (!invalid) {
 62  4
                 extents.add(document, begin, end);
 63  
             }
 64  4
             notDone = iterators[0].next();
 65  4
         }
 66  4
     }
 67  
 }