/** * Returns all the text in the given file * * @return The text in the file. */ public static String slurpFile(String filename) throws IOException { return slurpFile(filename, defaultEncoding); }
/** * Returns all the text in the given File as a single String. * If the file's name ends in .gz, it is assumed to be gzipped and is silently uncompressed. */ public static String slurpFile(File file) throws IOException { return slurpFile(file, null); }
public static String[][] readFile(String filename) throws Exception { String file = IOUtils.slurpFile(filename); String[] lines = file.split("\n"); String[][] cols = new String[lines.length][]; for (int i = 0; i < lines.length; i++) { cols[i] = lines[i].split("\\s+"); } return cols; }
public static double[][] load2DMatrixFromFile(String filename) throws IOException { String s = IOUtils.slurpFile(filename); String[] rows = s.split("[\r\n]+"); double[][] result = new double[rows.length][]; for (int i=0; i<result.length; i++) { String[] columns = rows[i].split("\\s+"); result[i] = new double[columns.length]; for (int j=0; j<result[i].length; j++) { result[i][j] = Double.parseDouble(columns[j]); } } return result; }
/** * Returns all the text in the given file with the given * encoding. If the file cannot be read (non-existent, etc.), then * the method throws an unchecked RuntimeIOException. If the caller * is willing to tolerate missing files, they should catch that * exception. */ public static String slurpFileNoExceptions(String filename, String encoding) { try { return slurpFile(filename, encoding); } catch (IOException e) { throw new RuntimeIOException("slurpFile IO problem", e); } }
/** * Returns all the text in the given file with the given * encoding. If the file cannot be read (non-existent, etc.), then * the method throws an unchecked RuntimeIOException. If the caller * is willing to tolerate missing files, they should catch that * exception. */ public static String slurpFileNoExceptions(String filename) { try { return slurpFile(filename); } catch (IOException e) { throw new RuntimeIOException(e); } }
public static LinkedList<String[]> readCSVStrictly(String filename, int numColumns) throws IOException { return readCSVStrictly(slurpFile(filename).toCharArray(), numColumns); }
public static void processTextFile(AnnotationPipeline pipeline, String in, String out, String date) throws IOException { String text = IOUtils.slurpFile(in); PrintWriter pw = (out != null)? IOUtils.getPrintWriter(out):new PrintWriter(System.out); String string = textToAnnotatedXml(pipeline, text, date); pw.println(string); pw.flush(); if (out != null) pw.close(); }
private static Stream<SentimentDatum> imdb(String path, SentimentClass label) { return StreamSupport.stream( IOUtils.iterFilesRecursive(new File(path)).spliterator(), true) .map(x -> { try { return new SentimentDatum(IOUtils.slurpFile(x), label); } catch (IOException e) { throw new RuntimeIOException(e); } }); }
public MUCMentionExtractor(Dictionaries dict, Properties props, Semantics semantics) throws Exception { super(dict, semantics); String fileName = props.getProperty(Constants.MUC_PROP); fileContents = IOUtils.slurpFile(fileName); currentOffset = 0; tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(false), ""); stanfordProcessor = loadStanfordProcessor(props); }
/** Tests a few methods. * If the first arg is -readDoc then this method tests * readDocumentFromFile. * Otherwise, it tests readTag/readUntilTag and slurpFile. */ public static void main(String[] args) throws Exception { if (args[0].equals("-readDoc")) { Document doc = readDocumentFromFile(args[1]); System.out.println(doc); } else { String s = IOUtils.slurpFile(args[0]); Reader r = new StringReader(s); String tag = readTag(r); while (tag != null && ! tag.isEmpty()) { readUntilTag(r); tag = readTag(r); if (tag == null || tag.isEmpty()) { break; } System.out.println("got tag=" + new XMLTag(tag)); } } }
String input =IOUtils.slurpFile(inputFile);
log.info("java Morphology [-rebuildVerbTable file|-stem word+|file+]"); } else if (args.length == 2 && args[0].equals("-rebuildVerbTable")) { String verbs = IOUtils.slurpFile(args[1]); String[] words = verbs.split("\\s+"); System.out.print(" private static final String[] verbStems = { ");
public static void main(String[] args) throws Exception { Properties props = StringUtils.argsToProperties(args); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String file = props.getProperty("file"); String loadFile = props.getProperty("loadFile"); if (loadFile != null && ! loadFile.isEmpty()) { CustomAnnotationSerializer ser = new CustomAnnotationSerializer(false, false); InputStream is = new FileInputStream(loadFile); Pair<Annotation, InputStream> pair = ser.read(is); pair.second.close(); Annotation anno = pair.first; System.out.println(anno.toShorterString(StringUtils.EMPTY_STRING_ARRAY)); is.close(); } else if (file != null && ! file.equals("")) { String text = edu.stanford.nlp.io.IOUtils.slurpFile(file); Annotation doc = new Annotation(text); pipeline.annotate(doc); CustomAnnotationSerializer ser = new CustomAnnotationSerializer(false, false); PrintStream os = new PrintStream(new FileOutputStream(file + ".ser")); ser.write(doc, os).close(); log.info("Serialized annotation saved in " + file + ".ser"); } else { log.info("usage: CustomAnnotationSerializer [-file file] [-loadFile file]"); } }
} catch (Exception ex) { throw new RuntimeException(String.format("error:\n%s\ninput:\n%s\noutput:\n%s", ex, IOUtils.slurpFile(inputFile), output), ex);
} catch (Exception ex) { throw new RuntimeException(String.format("error:\n%s\ninput:\n%s\noutput:\n%s", ex, IOUtils.slurpFile(inputFile), output), ex);
public static void main(String[] args) throws IOException { int i = 0; while (i < args.length) { Tree tree = Tree.valueOf(args[i]); if (tree == null) { // maybe it was a filename tree = Tree.valueOf(IOUtils.slurpFile(args[i])); } if (tree != null) { System.out.println(escape(texTree(tree))); } i++; } if (i == 0) { Tree tree = (new PennTreeReader(new BufferedReader(new InputStreamReader(System.in)), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree(); System.out.println(escape(texTree(tree))); } }
String fileContents = IOUtils.slurpFile(args[1]); List<List<CoreLabel>> out = classifier.classify(fileContents); for (List<CoreLabel> sentence : out) {
text = IOUtils.slurpFile(args[0]); } else { text = "Obama was born in Hawaii. He is our president.";