Package edu.stanford.nlp.pipeline

Source Code of edu.stanford.nlp.pipeline.AbstractInputStreamAnnotationCreator

package edu.stanford.nlp.pipeline;

import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.io.ReaderInputStream;

import java.io.*;

/**
* Creates a stub implementation for creating annotation from
*   various input sources using InputStream as the main input source
*
* @author Angel Chang
*/
public abstract class AbstractInputStreamAnnotationCreator implements AnnotationCreator {
  @Override
  public Annotation createFromText(String text) throws IOException {
    return create(new StringReader(text));
  }

  @Override
  public Annotation createFromFile(String filename) throws IOException {
    InputStream stream = new BufferedInputStream(new FileInputStream(filename));
    Annotation anno = create(stream);
    IOUtils.closeIgnoringExceptions(stream);
    return anno;
  }

  @Override
  public Annotation createFromFile(File file) throws IOException {
    return createFromFile(file.getAbsolutePath());
  }

  @Override
  public Annotation create(InputStream stream) throws IOException {
    return create(stream, "UTF-8");
  }

  @Override
  public Annotation create(Reader reader) throws IOException {
    // TODO: Is this okay?  If we are using this class, maybe we want byte-level stuff
    //  not character level
    return create(new ReaderInputStream(reader));
  }
}
TOP

Related Classes of edu.stanford.nlp.pipeline.AbstractInputStreamAnnotationCreator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.