01: package it.unimi.dsi.mg4j.search.score;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2004-2007 Paolo Boldi
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 it.unimi.dsi.fastutil.io.BinIO;
25: import it.unimi.dsi.mg4j.index.Index;
26:
27: import java.io.IOException;
28:
29: /** Compute scores that do not depend on intervals, but that
30: * just assign a fixed score to each document; scores are read
31: * from a file whose name is passed to the constructor.
32: */
33: public class DocumentRankScorer extends AbstractScorer implements
34: DelegatingScorer {
35: /** The array of scores. */
36: private double[] score;
37:
38: /** Builds a document scorer by first reading the ranks from a file.
39: * Ranks are saved as doubles (the first double is the rank of document 0
40: * and so on).
41: *
42: * @param filename the name of the rank file.
43: */
44: public DocumentRankScorer(final String filename) throws IOException {
45: this (BinIO.loadDoubles(filename));
46: }
47:
48: /** Builds a document scorer with given scores.
49: *
50: * @param score the scores (they are not copied, so the caller is supposed
51: * not to change their values).
52: */
53: public DocumentRankScorer(final double[] score) {
54: this .score = score;
55: }
56:
57: public DocumentRankScorer copy() {
58: return new DocumentRankScorer(score);
59: }
60:
61: public double score() {
62: return score[documentIterator.document()];
63: }
64:
65: public double score(final Index index) {
66: throw new UnsupportedOperationException();
67: }
68:
69: public String toString() {
70: return "DocumentRank";
71: }
72:
73: public boolean usesIntervals() {
74: return false;
75: }
76: }
|