List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file, String encoding) throws IOException
From source file:eu.annocultor.data.filters.IdBasedRecordFilter.java
@Override public void load() throws Exception { if (isReadMode()) { includedRecords.addAll(FileUtils.readLines(fileToRead, "UTF-8")); }// www. j a v a 2 s.c o m }
From source file:edu.cuhk.hccl.evaluation.EvaluationApp.java
public static Map<String, long[]> buildRatingMap(File ratingFile) throws IOException { List<String> ratingLines = FileUtils.readLines(ratingFile, "UTF-8"); Collections.sort(ratingLines); Map<String, long[]> dataMap = new HashMap<String, long[]>(); for (String line : ratingLines) { String[] cols = line.split("\t"); String pair = mapping.getUserID(cols[0].trim()) + "@" + mapping.getItemID(cols[1].trim()); long[] ratings = new long[cols.length - 2]; for (int j = 2; j < cols.length; j++) { ratings[j - 2] = Long.parseLong(cols[j]); }//from ww w . j a v a 2s . c om dataMap.put(pair, ratings); } return dataMap; }
From source file:com.clov4r.moboplayer.android.nil.codec.SubtitleJni.java
/** * ?????// w w w .ja va 2 s. c o m * * @param filePath * @param index * @return */ public int openSubtitleFile(String filePath, int index, int subtiltle_index) { String charSet = getFilecharset(new File(filePath)); if (!charSet.equals("UTF-8")) { try { String tempPath = filePath.substring(0, filePath.length() - 4) + "mobo_temp_utf-8.srt"; File tempFile = new File(tempPath); if (!tempFile.exists()) { FileUtils.writeLines(tempFile, "UTF-8", FileUtils.readLines(new File(filePath), charSet)); } return openSubtitleFileInJNI(tempPath, index, subtiltle_index); } catch (Exception e) { e.printStackTrace(); } } return openSubtitleFileInJNI(filePath, index, subtiltle_index); }
From source file:de.unidue.ltl.flextag.core.reports.adapter.TtAbstractKnownUnknownWordAccuracyReport.java
protected List<String> readPredictions(File id2o) throws IOException { List<String> out = new ArrayList<>(); Map<String, String> mapping = new HashMap<>(); for (String l : FileUtils.readLines(id2o, "utf-8")) { if (l.startsWith("#labels")) { loadMapping(l, mapping);//from w ww . ja v a2s .co m } if (l.startsWith("#")) { continue; } String[] split = l.split("="); String[] split2 = split[1].split(";"); String g = mapping.get(split2[0]); String p = mapping.get(split2[1]); out.add(g + " " + p); } return out; }
From source file:com.gargoylesoftware.htmlunit.libraries.JQueryTestBase.java
/** * @throws Exception if an error occurs//from w ww .j a va2 s. c o m */ protected void runTest() throws Exception { final Iterator<HtmlElement> it = loadPage(); final List<String> lines = FileUtils.readLines(new File(getExpectedPath()), "UTF-8"); if (lines.get(0).charAt(0) == 0xFEFF) { // The file has a UTF-8 BOM; remove it! // http://unicode.org/faq/utf_bom.html#BOM lines.add(0, lines.get(0).substring(1)); lines.remove(1); } final Iterator<String> expectedIterator = lines.iterator(); while (it.hasNext()) { ok(it, expectedIterator); } final String s = getNextExpectedModuleResult(expectedIterator); if (s != null) { fail("No result found for " + s + " (and following if any)"); } }
From source file:com.seleniumtests.util.squashta.TaScriptGenerator.java
/** * Search for scenarios in feature files * @param path/*from w w w. j av a2 s. c om*/ * @param application * @return */ public List<String> parseFeatures() { Pattern scenarioPattern = Pattern.compile("^\\s*Scenario:(.*)"); Pattern scenarioOutlinePattern = Pattern.compile("^\\s*Scenario Outline:(.*)"); // look for feature file into data folder File dir = Paths.get(srcPath, "data", application, "features").toFile(); if (!dir.exists()) { return new ArrayList<>(); } File[] featureFiles = dir.listFiles((d, filename) -> filename.endsWith(".feature")); List<String> scenarios = new ArrayList<>(); for (File featureFile : featureFiles) { try { boolean exclude = false; for (String line : FileUtils.readLines(featureFile, "UTF-8")) { // exclude scenarios using tag @EXCLUDE_FROM_SQUASH_TA if (line.contains(FEATURE_EXCLUDE)) { exclude = true; } Matcher matcher = scenarioPattern.matcher(line); if (matcher.matches()) { if (!exclude) { scenarios.add(matcher.group(1).trim()); } exclude = false; } Matcher matcherOutline = scenarioOutlinePattern.matcher(line); if (matcherOutline.matches()) { if (!exclude) { scenarios.add(matcherOutline.group(1).trim()); } exclude = false; } } } catch (IOException e) { // ignore } } return scenarios; }
From source file:de.tudarmstadt.ukp.dkpro.tc.features.readability.AcademicTokenRatioExtractor.java
@Override public List<Feature> extract(JCas jcas) throws TextClassificationException { if (!listsInitialized) { try {//from w w w . j a v a2 s . c o m cocaWords = new ArrayList<String>(); coxheadWords = new ArrayList<String>(); cocaWords.addAll(FileUtils.readLines(new File("src/main/resources/academicVocabularyList_coca.txt"), "utf-8")); coxheadWords.addAll(FileUtils.readLines(new File( new DkproContext().getWorkspace().getAbsolutePath() + "/Coxhead_academicWords_en.txt"), "utf-8")); } catch (IOException e) { throw new TextClassificationException(e); } listsInitialized = true; } int sumCocaWords = 0; int sumCoxheadWords = 0; int nrOfWords = 0; for (Token tok : JCasUtil.select(jcas, Token.class)) { if (ReadabilityUtils.isLexicalWord(tok, jcas.getDocumentLanguage())) { nrOfWords++; String lemma = tok.getLemma().getValue().toLowerCase(); if (cocaWords.contains(lemma)) { sumCocaWords++; } if (coxheadWords.contains(lemma)) { sumCoxheadWords++; } } } List<Feature> featList = new ArrayList<Feature>(); featList.add(new Feature("RatioOfAcademicWords_Coxhead", sumCoxheadWords / (double) nrOfWords)); featList.add(new Feature("RatioOfAcademicWords_Coca", sumCocaWords / (double) nrOfWords)); return featList; }
From source file:eu.delving.sip.files.StorageHelper.java
static Map<String, String> readFacts(File file) throws IOException { Map<String, String> facts = new TreeMap<String, String>(); if (file.exists()) { List<String> lines = FileUtils.readLines(file, "UTF-8"); for (String line : lines) { if (line.startsWith("#")) continue; int equals = line.indexOf("="); if (equals < 0) { continue; }//from w ww .ja v a 2 s . c om String name = line.substring(0, equals).trim(); String value = line.substring(equals + 1).trim(); facts.put(name, value); } } return facts; }
From source file:core.test.server.mock.util.PersonNameUtil.java
/** * initialize mail names from file//from ww w. j ava 2 s. c om * @throws IOException * */ private void initializeMaleNames() throws IOException { URL url = getClass().getClassLoader().getResource("people-names/male-names.txt"); File file = new File(url.getFile()); maleNames = FileUtils.readLines(file, "UTF-8"); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.tgrep.TGrepWriterTest.java
@Test public void testTxt() throws Exception { File outputPath = testContext.getTestOutputFolder(); String language = "en"; String text = "This is a sample sentence. Followed by another one."; AnalysisEngineDescription seg = createEngineDescription(StanfordSegmenter.class); AnalysisEngineDescription parse = createEngineDescription(StanfordParser.class, StanfordParser.PARAM_WRITE_PENN_TREE, true, StanfordParser.PARAM_LANGUAGE, "en", StanfordParser.PARAM_VARIANT, "pcfg"); AnalysisEngineDescription tgrep = createEngineDescription(TGrepWriter.class, TGrepWriter.PARAM_TARGET_LOCATION, outputPath, TGrepWriter.PARAM_COMPRESSION, CompressionMethod.GZIP, TGrepWriter.PARAM_DROP_MALFORMED_TREES, true, TGrepWriter.PARAM_WRITE_COMMENTS, true, TGrepWriter.PARAM_WRITE_T2C, false); JCas jcas = JCasFactory.createJCas(); jcas.setDocumentLanguage(language);/* w w w . j a va 2 s . c o m*/ jcas.setDocumentText(text); DocumentMetaData meta = DocumentMetaData.create(jcas); meta.setCollectionId("testCollection"); meta.setDocumentId("testDocument"); SimplePipeline.runPipeline(jcas, seg, parse, tgrep); List<String> expected = new ArrayList<String>(); expected.add("# testDocument,0,26"); expected.add("(ROOT (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (NN sample) (NN sentence))) (. .)))"); expected.add("# testDocument,27,51"); expected.add("(ROOT (S (VP (VBN Followed) (PP (IN by) (NP (DT another) (NN one)))) (. .)))"); List<String> actual = FileUtils.readLines(new File(outputPath, "testCollection.txt"), "UTF-8"); Assert.assertEquals(expected.size(), actual.size()); for (int i = 0; i < actual.size(); i++) { Assert.assertEquals(expected.get(i), actual.get(i)); } }