| 1 | |
|
| 2 | |
package org.galagosearch.core.retrieval.structured; |
| 3 | |
|
| 4 | |
import java.io.IOException; |
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
public abstract class ScoringFunctionIterator implements ScoreIterator { |
| 11 | |
boolean done; |
| 12 | |
CountIterator iterator; |
| 13 | |
|
| 14 | 12 | public ScoringFunctionIterator(CountIterator iterator) { |
| 15 | 12 | this.iterator = iterator; |
| 16 | 12 | } |
| 17 | |
|
| 18 | |
public abstract double scoreCount(int count, int length); |
| 19 | |
|
| 20 | |
public double score(int document, int length) { |
| 21 | 52 | int count = 0; |
| 22 | |
|
| 23 | 52 | if (iterator.document() == document) { |
| 24 | 36 | count = iterator.count(); |
| 25 | |
} |
| 26 | 52 | return scoreCount(count, length); |
| 27 | |
} |
| 28 | |
|
| 29 | |
public void moveTo(int document) throws IOException { |
| 30 | 0 | if (!iterator.isDone()) { |
| 31 | 0 | iterator.skipToDocument(document); |
| 32 | |
} |
| 33 | 0 | } |
| 34 | |
|
| 35 | |
public void movePast(int document) throws IOException { |
| 36 | 48 | if (!iterator.isDone() && iterator.document() <= document) { |
| 37 | 36 | iterator.skipToDocument(document + 1); |
| 38 | |
} |
| 39 | 48 | } |
| 40 | |
|
| 41 | |
public int nextCandidate() { |
| 42 | 44 | if (isDone()) { |
| 43 | 0 | return Integer.MAX_VALUE; |
| 44 | |
} |
| 45 | 44 | return iterator.document(); |
| 46 | |
} |
| 47 | |
|
| 48 | |
public boolean isDone() { |
| 49 | 132 | return iterator.isDone(); |
| 50 | |
} |
| 51 | |
|
| 52 | |
public boolean hasMatch(int document) { |
| 53 | 0 | return !isDone() && iterator.document() == document; |
| 54 | |
} |
| 55 | |
|
| 56 | |
public void reset() throws IOException { |
| 57 | 0 | iterator.reset(); |
| 58 | 0 | } |
| 59 | |
} |