edu.stanford.nlp.trees
Class SentenceReader

java.lang.Object
  |
  +--edu.stanford.nlp.trees.SentenceReader

public class SentenceReader
extends Object

A SentenceReader adds functionality to a Reader by reading in Sentences, or some descendant class. Like other standard classes, this class does not provide buffering, so for high performance, a typical invocation of SentenceReader would be something like:

SentenceReader sr = new SentenceReader(new BufferedReader(new FileReader(file)), myWordFactory);

It is designed for sentences to be delimited in one of two ways: either by a recognizable end-of-sentence token or by an end-of-line. If the latter, the StreamTokenizer should return end-of-lines, and the SentenceNormalizer should say to use them.

Author:
Christopher Manning

Constructor Summary
SentenceReader(Reader in)
          Construct class to read sentences from a Reader.
SentenceReader(Reader in, LabelFactory lf)
          Construct class to read sentences from a Reader.
SentenceReader(Reader in, LabelFactory lf, SentenceNormalizer sn)
          Construct class to read sentences from a Reader.
SentenceReader(Reader in, LabelFactory lf, SentenceNormalizer sn, StreamTokenizer st)
          Construct class to read sentences from a Reader.
 
Method Summary
 void close()
          Close the Reader behind this SentenceReader.
static void main(String[] args)
          Loads sentences from first argument and prints them.
 Sentence readSentence()
          Reads a single sentence.
 String toString()
          Returns a String representing the type of the SentenceReader object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SentenceReader

public SentenceReader(Reader in)
Construct class to read sentences from a Reader.

Parameters:
in - the Reader

SentenceReader

public SentenceReader(Reader in,
                      LabelFactory lf)
Construct class to read sentences from a Reader.

Parameters:
in - The Reader
lf - The LabelFactory that creates some kind of Label

SentenceReader

public SentenceReader(Reader in,
                      LabelFactory lf,
                      SentenceNormalizer sn)
Construct class to read sentences from a Reader.

Parameters:
in - Input stream
lf - The LabelFactory that creates some kind of Label
sn - the method of normalizing sentences

SentenceReader

public SentenceReader(Reader in,
                      LabelFactory lf,
                      SentenceNormalizer sn,
                      StreamTokenizer st)
Construct class to read sentences from a Reader. All of the arguments must be provided. They cannot be null.

Parameters:
in - input Reader
lf - The LabelFactory that creates some kind of Label
sn - The method of normalizing sentences.
st - StreamTokenizer that divides up input from Reader
Method Detail

readSentence

public Sentence readSentence()
                      throws IOException
Reads a single sentence.

Returns:
The sentence read in. This may be a zero length sentence (e.g., a blank line in a file where line ends indicate sentence ends). It returns null at (and only at) end of file.
Throws:
IOException - If format is invalid

close

public void close()
           throws IOException
Close the Reader behind this SentenceReader.

Throws:
IOException - If can't close file

toString

public String toString()
Returns a String representing the type of the SentenceReader object. This includes information on the objects it contains.

Overrides:
toString in class Object
Returns:
Representation of the SentenceReader

main

public static void main(String[] args)
Loads sentences from first argument and prints them. These files are assumed to be in the format of Penn Treebank POS tagged sentences.

Parameters:
args - Array of command-line arguments (just filePath)


Stanford NLP Group