/** * Close the Reader behind this <code>TreeReader</code>. */ public void close() throws IOException { tr.close(); }
@Override public List<String> next() { if (nextYield == null) { try { if (fileReader != null) { fileReader.close(); fileReader = null; } else if (treeReader != null) { treeReader.close(); treeReader = null; } } catch (IOException e) { e.printStackTrace(); } return null; } else { List<String> next = nextYield; primeNext(); return next; } }
private static void resolveDummyTags(File treeFile, TwoDimensionalCounter<String, String> pretermLabel, TwoDimensionalCounter<String, String> unigramTagger) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), "UTF-8")); TreeReaderFactory trf = new FrenchTreeReaderFactory(); TreeReader tr = trf.newTreeReader(br); PrintWriter pw = new PrintWriter(new PrintStream(new FileOutputStream(new File(treeFile + ".fixed")),false,"UTF-8")); int nTrees = 0; for(Tree t; (t = tr.readTree()) != null;nTrees++) { traverseAndFix(t, pretermLabel, unigramTagger); pw.println(t.toString()); } pw.close(); tr.close(); System.out.println("Processed " +nTrees+ " trees"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private boolean primeNextFile() { try { if(curPathIter.hasNext() || (primeNextPath() && curPathIter.hasNext())) { currentFile = curPathIter.next(); currentFilename = currentFile.getAbsolutePath(); if(PRINT_FILENAMES) log.info(currentFile); if (tr != null) { tr.close(); } tr = treeReaderFactory().newTreeReader(IOUtils.readerFromFile(currentFile, encoding())); curLineId = 1; return true; } } catch (UnsupportedEncodingException e) { System.err.printf("%s: Filesystem does not support encoding:%n%s%n", this.getClass().getName(), e.toString()); throw new RuntimeException(e); } catch (FileNotFoundException e) { System.err.printf("%s: File does not exist:%n%s%n", this.getClass().getName(),e.toString()); throw new RuntimeException(e); } catch (IOException e) { System.err.printf("%s: Unable to close open tree reader:%n%s%n", this.getClass().getName(),currentFile.getPath()); throw new RuntimeException(e); } return false; }
/** * @param args */ public static void main(String[] args) { if(args.length != 1) { System.err.printf("Usage: java %s tree_file > trees%n", HebrewTreeReaderFactory.class.getName()); System.exit(-1); } TreebankLanguagePack tlp = new HebrewTreebankLanguagePack(); File treeFile = new File(args[0]); try { TreeReaderFactory trf = new HebrewTreeReaderFactory(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), tlp.getEncoding())); TreeReader tr = trf.newTreeReader(br); int numTrees = 0; for(Tree t; ((t = tr.readTree()) != null); numTrees++) System.out.println(t.toString()); tr.close(); System.err.printf("Processed %d trees.%n",numTrees); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
tr.close(); pwDev.close(); pwTrain.close();
System.out.println(tree.toString()); tr.close();
TreeReader tr = trf.newTreeReader(file.getPath(), in); process(file, tr, posPattern, wordPattern, plainPrint); tr.close(); } catch (IOException e) { e.printStackTrace();
tr.close(); System.err.printf("%s: %d trees%n",file.getName(),numTrees); totalTrees += numTrees;
tr.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace();
/** * * @param args File to run on */ public static void main(String[] args) { if(args.length < 1) { System.out.printf("Usage: java %s tree_file%n", NegraPennTreeReaderFactory.class.getName()); return; } TreebankLanguagePack tlp = new NegraPennLanguagePack(); TreeReaderFactory trf = new NegraPennTreeReaderFactory(2,false,false,tlp); try { TreeReader tr = trf.newTreeReader(IOUtils.readerFromString(args[0], tlp.getEncoding())); for (Tree t; (t = tr.readTree()) != null; ) { t.pennPrint(); } tr.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
labelPreterm, pretermLabel, labelTerm, termLabel); tr.close(); //Closes the underlying reader
updateTagger(unigramTagger, t); tr.close(); //Closes the underlying reader
tr.close(); //Closes the underlying reader