List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file) throws IOException
From source file:com.github.ipaas.ideploy.plugin.core.Comparetor.java
public static void main(String[] args) throws IOException { // List<NameValuePair> params = new ArrayList<NameValuePair>(); // UserInfo userInfo = new UserInfo(); // userInfo.setEmail("chenql"); // userInfo.setPassword(""); // userInfo.setUrl(""); // params.add(new BasicNameValuePair("userName", userInfo.getEmail())); // params.add(new BasicNameValuePair("password", userInfo.getPassword())); // params.add(new BasicNameValuePair("id", "uphone")); // String json = RequestAcion.post(userInfo.getUrl() + "/crs_code/code_info", params, true); // System.out.println(json); // /* ww w . j a va 2 s. c o m*/ List<String> list = FileUtils.readLines(new File("D://update.txt")); for (String str : list) { if (CharUtil.isChinese(str)) { System.out.println(str); } } }
From source file:edu.isistan.carcha.lsa.LSARunner.java
/** * The main method.//from w ww .j a v a 2s. co m * * @param args the arguments * @throws Exception the exception */ @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { List<Entity> testConcerns = Utils.transformedList(FileUtils.readLines(new File(args[0])), new String2Concern(true)); List<Entity> testDesignDecisions = Utils.transformedList(FileUtils.readLines(new File(args[1])), new String2Concern(true)); LSARunner runner = new LSARunner(testConcerns, testDesignDecisions, 100, 0.75); TraceabilityDocument doc = runner.getTraceability(); logger.info(doc); }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step8GoldDataAggregator.java
public static void main(String[] args) throws Exception { String inputDir = args[0] + "/"; // output dir File outputDir = new File(args[1]); File turkersConfidence = new File(args[2]); if (outputDir.exists()) { outputDir.delete();//from w w w.ja v a 2 s . co m } outputDir.mkdir(); List<String> annotatorsIDs = new ArrayList<>(); // for (File f : FileUtils.listFiles(new File(inputDir), new String[] { "xml" }, false)) { // QueryResultContainer queryResultContainer = QueryResultContainer // .fromXML(FileUtils.readFileToString(f, "utf-8")); // for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) { // for (QueryResultContainer.MTurkRelevanceVote relevanceVote : rankedResults.mTurkRelevanceVotes) { // if (!annotatorsIDs.contains(relevanceVote.turkID)) // annotatorsIDs.add(relevanceVote.turkID); // } // } // } HashMap<String, Integer> countVotesForATurker = new HashMap<>(); // creates temporary file with format for mace // Hashmap annotations: key is the id of a document and a sentence // Value is an array votes[] of turkers decisions: true or false (relevant or not) // the length of this array equals the number of annotators in List<String> annotatorsIDs. // If an annotator worked on the task his decision is written in the array otherwise the value is NULL // key: queryID + clueWebID + sentenceID // value: true and false annotations TreeMap<String, Annotations> annotations = new TreeMap<>(); for (File f : FileUtils.listFiles(new File(inputDir), new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); System.out.println("Reading " + f.getName()); for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) { String documentID = rankedResults.clueWebID; for (QueryResultContainer.MTurkRelevanceVote relevanceVote : rankedResults.mTurkRelevanceVotes) { Integer turkerID; if (!annotatorsIDs.contains(relevanceVote.turkID)) { annotatorsIDs.add(relevanceVote.turkID); turkerID = annotatorsIDs.size() - 1; } else { turkerID = annotatorsIDs.indexOf(relevanceVote.turkID); } Integer count = countVotesForATurker.get(relevanceVote.turkID); if (count == null) { count = 0; } count++; countVotesForATurker.put(relevanceVote.turkID, count); String id; List<Integer> trueVotes; List<Integer> falseVotes; for (QueryResultContainer.SingleSentenceRelevanceVote singleSentenceRelevanceVote : relevanceVote.singleSentenceRelevanceVotes) if (!"".equals(singleSentenceRelevanceVote.sentenceID)) { id = f.getName() + "_" + documentID + "_" + singleSentenceRelevanceVote.sentenceID; Annotations turkerVotes = annotations.get(id); if (turkerVotes == null) { trueVotes = new ArrayList<>(); falseVotes = new ArrayList<>(); turkerVotes = new Annotations(trueVotes, falseVotes); } trueVotes = turkerVotes.trueAnnotations; falseVotes = turkerVotes.falseAnnotations; if ("true".equals(singleSentenceRelevanceVote.relevant)) { // votes[turkerID] = true; trueVotes.add(turkerID); } else if ("false".equals(singleSentenceRelevanceVote.relevant)) { // votes[turkerID] = false; falseVotes.add(turkerID); } else { throw new IllegalStateException("Annotation value of sentence " + singleSentenceRelevanceVote.sentenceID + " in " + rankedResults.clueWebID + " equals " + singleSentenceRelevanceVote.relevant); } try { int allVotesCount = trueVotes.size() + falseVotes.size(); if (allVotesCount > 5) { System.err.println(id + " doesn't have 5 annotators: true: " + trueVotes.size() + " false: " + falseVotes.size()); // nasty hack, we're gonna strip some data; true votes first /* we can't do that, it breaks something down the line int toRemove = allVotesCount - 5; if (trueVotes.size() >= toRemove) { trueVotes = trueVotes .subList(0, trueVotes.size() - toRemove); } else if ( falseVotes.size() >= toRemove) { falseVotes = falseVotes .subList(0, trueVotes.size() - toRemove); } */ System.err.println("Adjusted: " + id + " doesn't have 5 annotators: true: " + trueVotes.size() + " false: " + falseVotes.size()); } } catch (IllegalStateException e) { e.printStackTrace(); } turkerVotes.trueAnnotations = trueVotes; turkerVotes.falseAnnotations = falseVotes; annotations.put(id, turkerVotes); } else { throw new IllegalStateException( "Empty Sentence ID in " + f.getName() + " for turker " + turkerID); } } } } File tmp = printHashMap(annotations, annotatorsIDs.size()); String file = TEMP_DIR + "/" + tmp.getName(); MACE.main(new String[] { "--prefix", file }); //gets the keys of the documents and sentences ArrayList<String> lines = (ArrayList<String>) FileUtils.readLines(new File(file + ".prediction")); int i = 0; TreeMap<String, TreeMap<String, ArrayList<HashMap<String, String>>>> ids = new TreeMap<>(); ArrayList<HashMap<String, String>> sentences; if (lines.size() != annotations.size()) { throw new IllegalStateException( "The size of prediction file is " + lines.size() + "but expected " + annotations.size()); } for (Map.Entry entry : annotations.entrySet()) { //1001.xml_clueweb12-1905wb-13-07360_8783 String key = (String) entry.getKey(); String[] IDs = key.split("_"); if (IDs.length > 2) { String queryID = IDs[0]; String clueWebID = IDs[1]; String sentenceID = IDs[2]; TreeMap<String, ArrayList<HashMap<String, String>>> clueWebIDs = ids.get(queryID); if (clueWebIDs == null) { clueWebIDs = new TreeMap<>(); } sentences = clueWebIDs.get(clueWebID); if (sentences == null) { sentences = new ArrayList<>(); } HashMap<String, String> sentence = new HashMap<>(); sentence.put(sentenceID, lines.get(i)); sentences.add(sentence); clueWebIDs.put(clueWebID, sentences); ids.put(queryID, clueWebIDs); } else { throw new IllegalStateException("Wrong ID " + key); } i++; } for (Map.Entry entry : ids.entrySet()) { TreeMap<Integer, String> value = (TreeMap<Integer, String>) entry.getValue(); String queryID = (String) entry.getKey(); QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(new File(inputDir, queryID), "utf-8")); for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) { for (Map.Entry val : value.entrySet()) { String clueWebID = (String) val.getKey(); if (clueWebID.equals(rankedResults.clueWebID)) { List<QueryResultContainer.SingleSentenceRelevanceVote> goldEstimatedLabels = new ArrayList<>(); List<QueryResultContainer.SingleSentenceRelevanceVote> turkersVotes = new ArrayList<>(); int size = 0; int hitSize = 0; String hitID = ""; for (QueryResultContainer.MTurkRelevanceVote vote : rankedResults.mTurkRelevanceVotes) { if (!hitID.equals(vote.hitID)) { hitID = vote.hitID; hitSize = vote.singleSentenceRelevanceVotes.size(); size = size + hitSize; turkersVotes.addAll(vote.singleSentenceRelevanceVotes); } else { if (vote.singleSentenceRelevanceVotes.size() != hitSize) { hitSize = vote.singleSentenceRelevanceVotes.size(); size = size + hitSize; turkersVotes.addAll(vote.singleSentenceRelevanceVotes); } } } ArrayList<HashMap<String, String>> sentenceList = (ArrayList<HashMap<String, String>>) val .getValue(); if (sentenceList.size() != turkersVotes.size()) { try { throw new IllegalStateException("Expected size of annotations is " + turkersVotes.size() + "but found " + sentenceList.size() + " for document " + rankedResults.clueWebID + " in " + queryID); } catch (IllegalStateException ex) { ex.printStackTrace(); } } for (QueryResultContainer.SingleSentenceRelevanceVote s : turkersVotes) { String valSentence = null; for (HashMap<String, String> anno : sentenceList) { if (anno.keySet().contains(s.sentenceID)) { valSentence = anno.get(s.sentenceID); } } QueryResultContainer.SingleSentenceRelevanceVote singleSentenceVote = new QueryResultContainer.SingleSentenceRelevanceVote(); singleSentenceVote.sentenceID = s.sentenceID; if (("false").equals(valSentence)) { singleSentenceVote.relevant = "false"; } else if (("true").equals(valSentence)) { singleSentenceVote.relevant = "true"; } else { throw new IllegalStateException("Annotation value of sentence " + singleSentenceVote.sentenceID + " equals " + val.getValue()); } goldEstimatedLabels.add(singleSentenceVote); } rankedResults.goldEstimatedLabels = goldEstimatedLabels; } } } File outputFile = new File(outputDir, queryID); FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8"); System.out.println("Finished " + outputFile); } ArrayList<String> annotators = (ArrayList<String>) FileUtils.readLines(new File(file + ".competence")); FileWriter fileWriter; StringBuilder sb = new StringBuilder(); for (int j = 0; j < annotatorsIDs.size(); j++) { String[] s = annotators.get(0).split("\t"); Float score = Float.parseFloat(s[j]); String turkerID = annotatorsIDs.get(j); System.out.println(turkerID + " " + score + " " + countVotesForATurker.get(turkerID)); sb.append(turkerID).append(" ").append(score).append(" ").append(countVotesForATurker.get(turkerID)) .append("\n"); } fileWriter = new FileWriter(turkersConfidence); fileWriter.append(sb.toString()); fileWriter.close(); }
From source file:eu.europeana.portal.portal2.speedtests.TermProvider.java
public static List<String> getRandomWords(int count) { List<String> queries = null; try {/*w w w.j a va 2 s . co m*/ queries = FileUtils.readLines(new File("/home/peterkiraly/words.txt")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<String> random = new ArrayList<String>(); String query; while (random.size() < count) { int startRecord = (int) (Math.random() * queries.size()); query = queries.get(startRecord).trim().replaceAll("[\"'()]", "").replace("/", "\\/"); if (query.length() >= 3 && !random.contains(query)) { random.add(query); } } return random; }
From source file:com.z2data.files.ReadOperations.java
/** * read file line by line/* ww w . j a v a 2s.c om*/ * @param filePath * @return list of lines */ public static List<String> readList(String filePath) { List<String> lines = null; try { File file = new File(filePath); lines = FileUtils.readLines(file); return lines; } catch (Exception ex) { ex.printStackTrace(); } return lines; }
From source file:api.behindTheName.NameReader.java
static HashMap<String, String> load() { HashMap<String, String> data = new HashMap<>(); File file = new File("options.txt"); try {/*from ww w . j ava 2 s . c om*/ List<String> lines = FileUtils.readLines(file); for (String s : lines) { if (s.contains("#")) continue; String htk = s.split("\\s")[0]; String cntry = s.substring(htk.length() + 1); data.put(cntry, htk); } } catch (IOException ex) { Logger.getLogger(NameReader.class.getName()).log(Level.SEVERE, null, ex); } return data; }
From source file:naftoreiclag.flowchartarch.ParseFiler.java
public static Genes readGenes() throws IOException { List<String> data = FileUtils.readLines(new File("file.txt")); System.out.println(data.getClass().toString()); System.out.println(data.size()); Genes genes = new Genes(); List<Element> linage = new ArrayList<Element>(); linage.add(0, genes);/*from w w w. j ava2 s. co m*/ for (String line : data) { // Track where we are on the string int head = 0; // Depth for (; head < line.length(); ++head) { if (line.charAt(head) != tab) { break; } } int depth = head; if (depth < 1) { continue; } // Type name for (; head < line.length(); ++head) { if (line.charAt(head) == sep) { break; } } String name = line.substring(depth, head); ++head; System.out.println("depth: " + depth + " type: " + name); // parse accordingly Element el = parse(name); linage.add(depth, el); linage.get(depth - 1).addChild(el); } return genes; }
From source file:dev.argent.hive.SqlScriptLoader.java
@SuppressWarnings("unchecked") public static String[] getScripts(Class<?> clazz, String sqlFileName) { try {//from w w w. j av a2 s.c o m String fileName = clazz.getResource(sqlFileName).getFile(); String comments = stripComments((List<String>) FileUtils.readLines(new File(fileName))); return StringUtils.delimitedListToStringArray(comments, ";"); } catch (IOException e) { log.warn(e.getMessage(), e); throw new IllegalArgumentException("SqlFile load failed. fileName : " + sqlFileName, e); } }
From source file:com.daphne.es.maintain.icon.web.controller.tmp.GenCssSql.java
private static void readUploadFile() throws IOException { String fromFile = "E:\\workspace\\git\\es\\web\\src\\main\\webapp\\WEB-INF\\static\\comp\\zTree\\css\\zTreeStyle\\img\\diy\\icon.txt"; String toFile = "C:\\Documents and Settings\\Administrator\\?\\b.sql"; String template = "insert into `maintain_icon` (`id`, `identity`, `img_src`, `type`, `width`, `height`) values(%1$d, '%2$s', '%3$s', 'upload_file', %4$d, %5$d);"; List<String> list = FileUtils.readLines(new File(fromFile)); FileWriter writer = new FileWriter(toFile); int count = 300; for (int i = 0, l = list.size(); i < l; i += 2) { writer.write(String.format(template, count++, list.get(i), list.get(i + 1), 16, 16)); writer.write("\r\n"); }/*from w w w . j a v a 2 s. c o m*/ writer.close(); }
From source file:com.wendal.java.dex.decomplier.toolkit.IO_Tool.java
@SuppressWarnings("unchecked") public static List<String> getFile(String filepath) throws IOException { if (filepath != null) { File file = new File(filepath); if (file.exists() && file.isFile()) { return FileUtils.readLines(file); }/*from www . j ava 2 s. c om*/ } /*null*/ return null; }