01: package it.unimi.dsi.mg4j.search.score;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2004-2007 Paolo Boldi and Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or modify it
09: * under the terms of the GNU Lesser General Public License as published by the Free
10: * Software Foundation; either version 2.1 of the License, or (at your option)
11: * any later version.
12: *
13: * This library is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITfNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16: * for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: import java.io.IOException;
25:
26: import it.unimi.dsi.fastutil.ints.AbstractIntIterator;
27: import it.unimi.dsi.fastutil.objects.Reference2DoubleMap;
28: import it.unimi.dsi.mg4j.index.Index;
29: import it.unimi.dsi.mg4j.search.DocumentIterator;
30:
31: /** An abstract implementation of {@link it.unimi.dsi.mg4j.search.score.Scorer}.
32: * It provides internal caching of the underlying
33: * document iterator during {@linkplain #wrap(DocumentIterator) wrapping},
34: * and a complete implementation of the {@link it.unimi.dsi.fastutil.ints.IntIterator}
35: * methods by delegation to the underlying document iterator (implementing subclasses
36: * that do not alter this behaviour should implement {@link it.unimi.dsi.mg4j.search.score.DelegatingScorer}).
37: * The {@link #setWeights(Reference2DoubleMap)}
38: * method simply returns false.
39: *
40: */
41: public abstract class AbstractScorer extends AbstractIntIterator
42: implements Scorer {
43: /** The current document iterator. */
44: protected DocumentIterator documentIterator;
45:
46: /** Wraps the given document iterator.
47: *
48: * <p>This method {@linkplain #documentIterator records internally the provided iterator}.
49: *
50: * @param documentIterator the document iterator that will be used in subsequent calls to
51: * {@link #score()} and {@link #score(Index)}.
52: */
53:
54: public void wrap(final DocumentIterator documentIterator)
55: throws IOException {
56: this .documentIterator = documentIterator;
57: }
58:
59: /** Returns false. */
60:
61: public boolean setWeights(
62: final Reference2DoubleMap<Index> index2Weight) {
63: return false;
64: }
65:
66: @Deprecated
67: public int nextInt() {
68: return documentIterator.nextInt();
69: }
70:
71: public int nextDocument() throws IOException {
72: return documentIterator.nextDocument();
73: }
74:
75: public int skip(final int n) {
76: return documentIterator.skip(n);
77: }
78:
79: public boolean hasNext() {
80: return documentIterator.hasNext();
81: }
82: }
|