| 1 | |
|
| 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 | |
|
| 12 | |
|
| 13 | |
public class OrderedWindowIterator extends ExtentConjunctionIterator { |
| 14 | |
int width; |
| 15 | |
|
| 16 | |
|
| 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 | |
|
| 34 | 8 | boolean invalid = false; |
| 35 | 8 | int begin = iterators[0].current().begin; |
| 36 | |
|
| 37 | |
|
| 38 | 12 | for (int i = 1; i < iterators.length; i++) { |
| 39 | 8 | int end = iterators[i - 1].current().end; |
| 40 | |
|
| 41 | |
|
| 42 | 8 | while (end > iterators[i].current().begin) { |
| 43 | 4 | notDone = iterators[i].next(); |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 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 | |
|
| 61 | 4 | if (!invalid) { |
| 62 | 4 | extents.add(document, begin, end); |
| 63 | |
} |
| 64 | 4 | notDone = iterators[0].next(); |
| 65 | 4 | } |
| 66 | 4 | } |
| 67 | |
} |