4 * October 2, 2007 -- Trevor Strohman
6 * BSD License (http://www.galagosearch.org/license)
9 package galago
.retrieval
;
11 import galago
.retrieval
.extents
.ScoreIterator
;
12 import galago
.tupleflow
.BufferedDataStream
;
13 import galago
.tupleflow
.VByteInput
;
14 import java
.io
.FileNotFoundException
;
15 import java
.io
.IOException
;
21 public class SparseFloatListReader
{
22 public class ScoreListIterator
implements ScoreIterator
{
23 IndexReader
.Iterator iterator
;
32 public ScoreListIterator( IndexReader
.Iterator iterator
) throws IOException
{
33 this.iterator
= iterator
;
37 void load() throws IOException
{
38 BufferedDataStream buffered
= reader
.blockStream(iterator
);
39 stream
= new VByteInput( buffered
);
40 documentCount
= stream
.readInt();
44 if( documentCount
> 0 )
48 void read() throws IOException
{
51 if( index
< documentCount
) {
52 currentDocument
+= stream
.readInt();
53 currentScore
= stream
.readFloat();
57 public void reset() throws IOException
{
63 public int nextCandidate() {
64 return currentDocument
;
67 public String
currentTerm() {
68 return iterator
.currentTerm();
71 public void nextTerm() throws IOException
{
76 public boolean hasMatch(int document
) {
77 return document
== currentDocument
;
80 public void moveTo(int document
) throws IOException
{
81 while( !isDone() && document
> currentDocument
)
85 public void movePast(int document
) throws IOException
{
86 while( !isDone() && document
>= currentDocument
)
90 public double score(int document
, int length
) {
91 if( document
== currentDocument
)
93 return Double
.NEGATIVE_INFINITY
;
96 public boolean isDone() {
97 return index
>= documentCount
;
103 public SparseFloatListReader( String pathname
) throws FileNotFoundException
, IOException
{
104 reader
= new IndexReader( pathname
);
107 public ScoreListIterator
getIterator() throws IOException
{
108 return new ScoreListIterator( reader
.getIterator() );
111 public ScoreListIterator
getScores( String term
) throws IOException
{
112 IndexReader
.Iterator iterator
= reader
.getTerm( term
);
114 if( iterator
!= null )
115 return new ScoreListIterator( iterator
);
120 void close() throws IOException
{