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