edu.stanford.nlp.trees.TreeTokenizerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-corenlp Show documentation
Show all versions of stanford-corenlp Show documentation
Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.
package edu.stanford.nlp.trees;
import edu.stanford.nlp.util.logging.Redwood;
import edu.stanford.nlp.process.TokenizerFactory;
import edu.stanford.nlp.process.Tokenizer;
import edu.stanford.nlp.process.AbstractTokenizer;
import java.io.Reader;
import java.io.IOException;
import java.util.Iterator;
/** Wrapper for TreeReaderFactory. Any IOException in the readTree() method
* of the TreeReader will result in a null
* tree returned.
*
* @author Roger Levy ([email protected])
* @author javanlp
*/
public class TreeTokenizerFactory implements TokenizerFactory {
/** A logger for this class */
private static Redwood.RedwoodChannels log = Redwood.channels(TreeTokenizerFactory.class);
/** Create a TreeTokenizerFactory from a TreeReaderFactory. */
public TreeTokenizerFactory(TreeReaderFactory trf) {
this.trf = trf;
}
private TreeReaderFactory trf;
/** Gets a tokenizer from a reader.*/
public Tokenizer getTokenizer(final Reader r) {
return new AbstractTokenizer() {
TreeReader tr = trf.newTreeReader(r);
@Override
public Tree getNext() {
try {
return tr.readTree();
}
catch(IOException e) {
log.info("Error in reading tree.");
return null;
}
}
};
}
public Tokenizer getTokenizer(final Reader r, String extraOptions) {
// Silently ignore extra options
return getTokenizer(r);
}
/** Same as getTokenizer(). */
public Iterator getIterator(Reader r) {
return null;
}
public void setOptions(String options) {
//Silently ignore
}
}