Exemplo n.º 1
0
  /**
   * Builds Document object from Penn treebank corpus.
   *
   * @param file
   * @param encoding
   * @return
   * @throws IOException
   * @throws InvalidFormatException
   */
  public Treebank load(File file, String encoding) throws IOException, InvalidFormatException {
    InputStream fin = null;
    Reader in = null;

    try {
      fin = new FileInputStream(file);
      in = new InputStreamReader(fin, encoding);
      in = new BufferedReader(in);

      return load(in);
    } finally {
      IOUtils.closeQuietly(in);
      IOUtils.closeQuietly(fin);
    }
  }
Exemplo n.º 2
0
 /**
  * Builds Document object from Penn treebank corpus.
  *
  * @param file
  * @return
  * @throws IOException
  * @throws InvalidFormatException
  */
 public Treebank load(File file) throws IOException, InvalidFormatException {
   Reader in = null;
   try {
     in = new BufferedReader(new FileReader(file));
     return load(in);
   } finally {
     IOUtils.closeQuietly(in);
   }
 }
Exemplo n.º 3
0
 /**
  * loads head rule from specified file.
  *
  * @param file
  * @throws IOException if I/O error occurs
  * @throws InvalidFormatException if rule readed from stream is invalid format
  */
 private void load(File file) throws IOException, InvalidFormatException {
   Reader reader = null;
   try {
     reader = new FileReader(file);
     load(reader);
   } finally {
     IOUtils.closeQuietly(reader);
   }
 }
Exemplo n.º 4
0
 public List<ParseTreeNode> loadParseTrees(File file) throws IOException, InvalidFormatException {
   Reader in = null;
   try {
     in = new BufferedReader(new FileReader(file));
     return loadParseTrees(in);
   } finally {
     IOUtils.closeQuietly(in);
   }
 }
Exemplo n.º 5
0
  /**
   * Creates <code>HeadRule<code> which has default rules.
   * @return created rule instance
   */
  public static HeadRule createDefaultRule() {
    HeadRule instance = new HeadRule();
    InputStream rawIn = HeadRule.class.getClassLoader().getResourceAsStream(DEFAULT_RULE_PATH);
    Reader in = null;

    try {
      in = new InputStreamReader(rawIn, DEFAULT_RULE_ENCODING);
      instance.load(in);
    } catch (UnsupportedOperationException ex) {
      throw new RuntimeException(ex);
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    } catch (InvalidFormatException ex) {
      throw new RuntimeException(ex);
    } finally {
      IOUtils.closeQuietly(in);
      IOUtils.closeQuietly(rawIn);
    }

    return instance;
  }