List of usage examples for edu.stanford.nlp.io NullOutputStream NullOutputStream
NullOutputStream
From source file:org.apdplat.evaluation.Evaluation.java
License:Open Source License
/** * ?/*from ww w .j a va 2s . c om*/ * @param input * @param output * @param segmenter ? * @return ? * @throws Exception */ protected float segFile(final String input, final String output, final Segmenter segmenter) throws Exception { //?? if (!Files.exists(Paths.get(output).getParent())) { Files.createDirectory(Paths.get(output).getParent()); } float rate = 0; try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(input), "utf-8")); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( standardText == null ? new NullOutputStream() : new FileOutputStream(output), "utf-8"))) { long size = Files.size(Paths.get(input)); System.out.println("size:" + size); System.out.println("?" + (float) size / 1024 / 1024 + " MB"); int textLength = 0; int progress = 0; long start = System.currentTimeMillis(); String line = null; while ((line = reader.readLine()) != null) { if ("".equals(line.trim())) { writer.write("\n"); continue; } try { writer.write(segmenter.seg(line)); writer.write("\n"); textLength += line.length(); progress += line.length(); if (progress > 500000) { progress = 0; System.out.println("?" + (int) (textLength * 2.99 / size * 100) + "%"); } } catch (Exception e) { System.out.println("?" + line); e.printStackTrace(); } } long cost = System.currentTimeMillis() - start; rate = textLength / (float) cost; System.out.println("" + textLength); System.out.println("?" + cost + " "); System.out.println("?" + rate + " /"); } return rate; }