List of usage examples for org.apache.commons.io LineIterator LineIterator
public LineIterator(final Reader reader) throws IllegalArgumentException
Reader
. From source file:edu.scripps.fl.pubchem.app.CIDDownloader.java
public static void main(String[] args) throws Exception { CIDDownloader fetcher = new CIDDownloader(); CommandLineHandler clh = new CommandLineHandler() { public void configureOptions(Options options) { options.addOption(OptionBuilder.withLongOpt("input_file").withType("").withValueSeparator('=') .hasArg().create()); options.addOption(OptionBuilder.withLongOpt("output_file").withType("").withValueSeparator('=') .hasArg().isRequired().create()); }/*from ww w.ja v a2 s . co m*/ }; args = clh.handle(args); String inputFile = clh.getCommandLine().getOptionValue("input_file"); String outputFile = clh.getCommandLine().getOptionValue("output_file"); fetcher.setOutputFile(outputFile); Iterator<?> iterator; if (null == inputFile) { if (args.length == 0) { log.info("Running query to find CIDs in PCAssayResult but not in PCCompound"); SQLQuery query = PubChemDB.getSession().createSQLQuery( "select distinct r.cid from pcassay_result r left join pccompound c on r.cid = c.cid where (r.cid is not null and r.cid > 0 ) and c.cid is null order by r.cid"); ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY); iterator = new ScrollableResultsIterator<Integer>(Integer.class, scroll); } else { iterator = Arrays.asList(args).iterator(); } } else if ("-".equals(inputFile)) { log.info("Reading CIDs (one per line) from STDIN"); iterator = new LineIterator(new InputStreamReader(System.in)); } else { log.info("Reading CIDs (one per line) from " + inputFile); iterator = new LineIterator(new FileReader(inputFile)); } fetcher.process(iterator); System.exit(0); }
From source file:au.org.ala.names.util.FileUtils.java
/** * @param source the source input stream * @param encoding the encoding used by the input stream * @return/* w w w. j av a2 s. co m*/ * @throws UnsupportedEncodingException */ public static LineIterator getLineIterator(InputStream source, String encoding) { try { return new LineIterator(new BufferedReader(new InputStreamReader(source, encoding))); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Unsupported encoding" + encoding, e); } }
From source file:de.tudarmstadt.lt.nlkg.EvaluatePreds.java
static void evaluate(String file) throws IllegalArgumentException, FileNotFoundException { DT dt = new DT() { {//from www. ja v a 2s . c o m _mysql_dbname = "nlkg_1"; } }; LineIterator iter = new LineIterator(new FileReader(file)); iter.nextLine(); // skip first line int lineno = 1; double tp = 0d, tn = 0d, fp = 0d, fn = 0d; while (iter.hasNext() && (lineno < 100 || true)) { lineno++; String line = iter.nextLine(); if (line.trim().isEmpty()) continue; String[] splits = line.split("\t"); String x = splits[0].trim(); String y = splits[1].trim(); String pred_l = splits[2].trim(); String pred_r = splits[3].trim(); boolean entailing_trueclass = Boolean.valueOf(splits[4].trim()); _X.add(x); _Y.add(y); _PRED_L.add(pred_l); _PRED_R.add(pred_r); _ENTAILING.add(entailing_trueclass); boolean entailing_predicted = predictEntailing(dt, pred_l, pred_r); if (lineno % 100 == 0) Evaluate.log_progress(); if (entailing_predicted && entailing_trueclass) { Evaluate.log_true(String.format("%d %-10s %-30s %-30s %b %n", lineno, "tp", pred_l, pred_r, entailing_trueclass)); tp++; } if (!entailing_predicted && !entailing_trueclass) { Evaluate.log_true(String.format("%d %-10s %-30s %-30s %b %n", lineno, "tn", pred_l, pred_r, entailing_trueclass)); tn++; } if (entailing_predicted && !entailing_trueclass) { Evaluate.log_false(String.format("%d %-10s %-30s %-30s %b %n", lineno, "fp", pred_l, pred_r, entailing_trueclass)); fp++; } if (!entailing_predicted && entailing_trueclass) { Evaluate.log_false(String.format("%d %-10s %-30s %-30s %b %n", lineno, "fn", pred_l, pred_r, entailing_trueclass)); fn++; } } System.out.format("tp: %d; fp: %d; fn: %d; tn: %d; %n", (int) tp, (int) fp, (int) fn, (int) tn); System.out.println("Precision = " + (tp / (tp + fp))); System.out.println("Recall = " + (tp / (tp + fn))); System.out.println("F1 = " + ((2 * tp) / ((2 * tp) + fn + fp))); dt.disconnect(); }
From source file:edu.umd.cs.hcil.twitterreplay.GzippedFileReader.java
public void open() throws FileNotFoundException, IOException { FileInputStream inFileStream = new FileInputStream(mFile); GZIPInputStream gzippedStream = new GZIPInputStream(inFileStream, 65536); BufferedReader reader = new BufferedReader(new InputStreamReader(gzippedStream, Charset.forName("UTF-8"))); mReaderIterator = new LineIterator(reader); }
From source file:com.lithium.flow.io.InputStreamSpliterator.java
public InputStreamSpliterator(@Nonnull InputStream in, @Nonnull Charset encoding) { checkNotNull(in);//from w w w .j ava 2 s. c o m checkNotNull(encoding); it = new LineIterator(new InputStreamReader(in, encoding)); }
From source file:com.mewmew.fairy.v1.spell.BaseLineSpell.java
@Override public void process(InputStream in, OutputStream out) { LineIterator iter = null;//from www . j a va 2s. c om try { output = createOutput(out); pipe = createPipe(); iter = new LineIterator(new InputStreamReader(in)); PipeUtil.process(iter, pipe, output); } catch (IOException e) { throw new RuntimeException(e); } finally { if (iter != null) { iter.close(); } } }
From source file:de.tudarmstadt.lt.lm.service.PreTokenizedStringProvider.java
@Override public List<String>[] getNgrams(String text, String language_code) throws Exception { LOG.trace(String.format("Computing ngrams from text: %s", StringUtils.abbreviate(text, 200))); List<String>[] ngrams = null; text = text.trim();//from w w w . ja va2s . c o m for (LineIterator iter = new LineIterator(new StringReader(text)); iter.hasNext();) { List<String> tokens = tokenizeSentence(iter.nextLine()); LOG.trace(String.format("Current sentence: %s", StringUtils.abbreviate(tokens.toString(), 200))); if (tokens.size() < getLanguageModel().getOrder()) { LOG.trace("Too few tokens."); continue; } List<String>[] current_ngrams = getNgramSequenceFromSentence(tokens); LOG.trace(String.format("Current ngrams: %s", StringUtils.abbreviate(Arrays.toString(current_ngrams), 200))); if (ngrams == null) ngrams = current_ngrams; else ngrams = ArrayUtils.getConcatinatedArray(ngrams, current_ngrams); } LOG.trace(String.format("Ngrams for text: %n\t'%s'%n\t%s ", StringUtils.abbreviate(text, 200), StringUtils.abbreviate(Arrays.toString(ngrams), 200))); return ngrams; }
From source file:com.meltmedia.cadmium.core.meta.MimeTypeConfigProcessor.java
static void addDefaultMimeTypes(Map<String, String> mimeTypeMap) throws IllegalArgumentException, UnsupportedEncodingException { InputStream in = null;/* w w w . ja v a 2s . co m*/ try { in = MimeTypeConfigProcessor.class.getResourceAsStream("mime.types"); if (in == null) { log.warn("The default mime type file is missing."); return; } LineIterator lineIterator = new LineIterator(new InputStreamReader(in, "UTF-8")); while (lineIterator.hasNext()) { String line = lineIterator.next(); line = line.replaceAll("(\\A[^#]*)(#.*)?\\Z", "$1").trim(); // kill comments. if (line.length() == 0) continue; // skip blank lines. String[] parts = line.split("\\s+"); if (parts.length < 2) continue; // skip lines with no extensions. String type = parts[0]; for (int i = 1; i < parts.length; i++) { mimeTypeMap.put(parts[i], type); } } } finally { IOUtils.closeQuietly(in); } }
From source file:mitm.common.postfix.PostfixMainConfigParser.java
private static List<String> normalize(Reader config) { List<String> lines = new LinkedList<String>(); LineIterator it = new LineIterator(config); String line = ""; try {//from w w w . jav a 2 s .co m while (it.hasNext()) { String nextLine = it.nextLine(); Matcher matcher = CONTINUATION.matcher(nextLine); if (!nextLine.trim().startsWith("#") && matcher.matches()) { /* its a continuation line */ line = line + LF + nextLine; } else { matcher = NAME_VALUE.matcher(nextLine); if (matcher.matches()) { /* its a name/value line */ if (StringUtils.isNotEmpty(line)) { /* store the previous line because it is finished */ lines.add(line); } line = nextLine; } else { /* it's some other line like a comment */ if (StringUtils.isNotEmpty(line)) { /* store the previous line because it is finished */ lines.add(line); } lines.add(nextLine); line = ""; } } } if (StringUtils.isNotEmpty(line)) { lines.add(line); } } finally { LineIterator.closeQuietly(it); } return lines; }
From source file:com.mewmew.fairy.v1.book.Join.java
@Override protected ObjectPipe<Map<String, Object>, Map<String, Object>> createPipe() { try {/*w w w .j a va 2 s . c o m*/ return new BaseObjectPipe<Map<String, Object>, Map<String, Object>>( new com.mewmew.fairy.v1.json.map.Join( new SimpleJsonIterator(new LineIterator(new FileReader(join))), key)); } catch (IOException e) { throw new RuntimeException(e); } }