org.finetracker
Class InputIterator

java.lang.Object
  extended by org.finetracker.InputIterator

public class InputIterator
extends java.lang.Object

This class reads FeatureVectors from file or stdin. Because there is only one stdin, the behavior of the class is undefined if it is instantiated more than once with stdin as parameter. Usage of this class:

1. Instantiate it with InputIterator()

2. Call hasNext(). If it returns TRUE, proceed to the next step. If it returns FALSE, the current fragment has ended. Call hasNext() again to retrieve the next fragment. If it returns null, the stream has ended and no more calls should be made. That ends the algorithm.

3. Call next() to retrieve the feature vector.

4. Go to step 2.

The input file must consist of one or more fragments. Each fragment looks like this:
-- fragmentname
0.0 0.0 0.0 0.0

Where 0.0 can be any double value. Each line represents one feature vector. After the feature vectors of a fragment, an empty line must occur to signal the end of the fragment. After the empty line, a new fragment can start.

Author:
Frank Kusters

Constructor Summary
InputIterator()
          Creates an Input object with either the specified file or stdin as input.
 
Method Summary
 java.lang.Boolean hasNext()
          Reads one line from input (a line ending with '\n').
 FeatureVector next()
          next() transforms the last read line into a FeatureVector, which is subsequently returned.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputIterator

public InputIterator()
              throws java.io.IOException
Creates an Input object with either the specified file or stdin as input. Stdin is used if filename is equal to a dash ("-").

Throws:
java.io.IOException - when the file cannot be opened (for example if it doesn't exist or is a directory)
Method Detail

next

public FeatureVector next()
                   throws java.io.IOException
next() transforms the last read line into a FeatureVector, which is subsequently returned. If the input cannot be parsed, an Exception is thrown.

Returns:
the FeatureVector as read from input, or null when the end of the input has been reached.
Throws:
java.io.IOException - if a string from the input could not be converted to a number or if the number of features read doesn't match the expected number of features

hasNext

public java.lang.Boolean hasNext()
                          throws java.io.IOException
Reads one line from input (a line ending with '\n'). It returns null if the end of the stream has been reached, a FALSE object if the end of the vectors/word has been reached, and a TRUE object in all other cases. Note that this function returns Boolean objects, not boolean values. This is to enable three kinds of return values instead of two. A call to hasNext() enables calling next().

Returns:
the values as described above
Throws:
java.io.IOException - if input cannot be read from