List of usage examples for java.util.regex Pattern matcher
public Matcher matcher(CharSequence input)
From source file:br.on.daed.services.horizons.HttpConnector.java
public static void main(String args[]) { Pattern compile = Pattern.compile( "(?:^|\\s*)(?:Mass[^(]*\\(?)(?<unit>[0-9^]+)?(?:[^=~]*(?:=|~)\\s*)(?<mass>[0-9.,E]+)(?:\\s*)(?:\\((?!.*\\+-)(?<postunit>.*\\^.*)\\))?"); Matcher matcher = compile .matcher("*******************************************************************************\n" + " Revised: Sep 28, 2012 Deimos / (Mars) 402\n" + "\n" + " SATELLITE PHYSICAL PROPERTIES:\n" + " Radius (km) = 7.8 x 6.0 x 5.1 Density (g cm^-3) = 1.76 +- 0.30\n" + " Mass (10^20 kg ) = 1.80 (10^-5) Geometric Albedo = 0.06 \n" + " (+- 0.15) V(1,0) = +12.89\n" + "\n" + " SATELLITE ORBITAL DATA:\n" + " Semi-major axis, a (km) = 23.4632(10^3) Orbital period = 1.263 d\n" + " Eccentricity, e = 0.00033 Rotational period = Synchronous\n" + " Inclination, i (deg) = 1.791\n" + "*******************************************************************************\n" + " \n" + " \n" + "*******************************************************************************\n" + "Ephemeris / WWW_USER Thu Aug 25 13:58:15 2016 Pasadena, USA / Horizons \n" + "*******************************************************************************\n" + "Target body name: Deimos (402) {source: mar097}\n" + "Center body name: Sun (10) {source: mar097}\n" + "Center-site name: BODY CENTER\n" + "*******************************************************************************\n" + "Start time : A.D. 2000-Jan-01 00:00:00.0000 TDB\n" + "Stop time : A.D. 2000-Jan-02 00:00:00.0000 TDB\n" + "Step-size : 597600 minutes\n" + "*******************************************************************************\n" + "Center geodetic : 0.00000000,0.00000000,0.0000000 {E-lon(deg),Lat(deg),Alt(km)}\n" + "Center cylindric: 0.00000000,0.00000000,0.0000000 {E-lon(deg),Dxy(km),Dz(km)}\n" + "Center radii : 696000.0 x 696000.0 x 696000.0 k{Equator, meridian, pole} \n" + "System GM : 2.9591220828559109E-04 au^3/d^2\n" + "Output units : AU-D, deg, Julian day number (Tp) \n" + "Output format : 10\n" + "Reference frame : ICRF/J2000.0 \n" + "Output type : GEOMETRIC osculating elements\n" + "Coordinate systm: Ecliptic and Mean Equinox of Reference Epoch \n" + "*******************************************************************************\n" + "JDTDB\n" + " EC QR IN\n" + " OM W Tp\n" + " N MA TA\n" + " A AD PR\n" + "*******************************************************************************\n" + "$$SOE\n" + "2451544.500000000 = A.D. 2000-Jan-01 00:00:00.0000 (TDB)\n" + " EC= 2.326887802497893E-02 QR= 1.337811007124899E+00 IN= 2.139216386111699E+00\n" + " OM= 4.083435138741744E+01 W = 1.857454986387542E+02 Tp= 2451332.176361185033\n" + " N = 6.148574868705978E-01 MA= 1.305487789649286E+02 TA= 1.325368384195841E+02\n" + " A = 1.369681969813503E+00 AD= 1.401552932502106E+00 PR= 5.855015311471115E+02\n" + "$$EOE\n" + "*******************************************************************************\n" + "Coordinate system description:\n" + "\n" + " Ecliptic and Mean Equinox of Reference Epoch\n" + "\n" + " Reference epoch: J2000.0\n" + " xy-plane: plane of the Earth's orbit at the reference epoch\n" + " x-axis : out along ascending node of instantaneous plane of the Earth's\n" + " orbit and the Earth's mean equator at the reference epoch\n" + " z-axis : perpendicular to the xy-plane in the directional (+ or -) sense\n" + " of Earth's north pole at the reference epoch.\n" + "\n" + "Symbol meaning [1 au=149597870.700 km, 1 day=86400.0 s]:\n" + "\n" + " JDTDB Epoch Julian Date, Barycentric Dynamical Time\n" + " EC Eccentricity, e \n" + " QR Periapsis distance, q (AU) \n" + " IN Inclination w.r.t xy-plane, i (degrees) \n" + " OM Longitude of Ascending Node, OMEGA, (degrees) \n" + " W Argument of Perifocus, w (degrees) \n" + " Tp Time of periapsis (Julian day number) \n" + " N Mean motion, n (degrees/day) \n" + " MA Mean anomaly, M (degrees) \n" + " TA True anomaly, nu (degrees) \n" + " A Semi-major axis, a (AU) \n" + " AD Apoapsis distance (AU) \n" + " PR Sidereal orbit period (day) \n" + "\n" + "Geometric states/elements have no aberration corrections applied.\n" + "\n" + " Computations by ...\n" + " Solar System Dynamics Group, Horizons On-Line Ephemeris System\n" + " 4800 Oak Grove Drive, Jet Propulsion Laboratory\n" + " Pasadena, CA 91109 USA\n" + " Information: http://ssd.jpl.nasa.gov/\n" + " Connect : telnet://ssd.jpl.nasa.gov:6775 (via browser)\n" + " telnet ssd.jpl.nasa.gov 6775 (via command-line)\n" + " Author : Jon.Giorgini@jpl.nasa.gov\n" + "*******************************************************************************\n" + "\n" + "!$$SOF\n" + "OBJ_DATA = YES\n" + "CENTER = 10\n" + "COMMAND = 402\n" + "MAKE_EPHEM = YES\n" + "OUT_UNITS = AU-D\n" + "TABLE_TYPE = ELEM\n" + "START_TIME = JD2451544.5\n" + "STOP_TIME = JD2451545.5\n" + "STEP_SIZE = 415d"); matcher.find();//from w w w .j ava2s . com String group = matcher.group("postunit"); System.out.println(group); }
From source file:org.roda.core.common.SeleniumUtils.java
/** * /*from w ww .ja va2 s . c om*/ * @param args: * the first argument is the RODA base url and the second argument is * the driver path * @throws InterruptedException * @throws IOException */ public static void main(String[] args) throws InterruptedException, IOException { if (args.length != 2) { System.err.println("Number of arguments not correct since it is only needed two arguments. " + "The first argument is the RODA base url and the second argument is the driver path"); commandHelp(); System.exit(0); } url = args[0]; driverPath = args[1]; ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File(driverPath)) .usingAnyFreePort().build(); service.start(); driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); driver.get(url); // welcome page saveHTML(); savePublicPages(); saveLoginPages(); saveHelpPages(); savePlanningPages(); saveAdminPages(); saveIngestPages(); saveSearchPages(); saveBrowsePages(); driver.quit(); service.stop(); for (Entry<String, String> entry : locations.entrySet()) { String location = entry.getKey(); String html = getHTMLSource(location); Pattern expression = Pattern.compile("<div id=\"webaxscore\".*?<span>(.*?)</span>"); Matcher matcher = expression.matcher(html); if (matcher.find()) { System.out.println(location + " | " + locations.get(location) + " | " + matcher.group(1)); } } }
From source file:com.opengamma.bbg.loader.BloombergSwaptionFileLoader.java
/** * Little util to parse swaption tickers into a csv for further analysis. * @param args command line params/*from w w w . ja v a 2s. c o m*/ */ public static void main(String[] args) { // CSIGNORE CSVReader csvReader = null; CSVWriter csvWriter = null; try { csvReader = new CSVReader(new BufferedReader(new FileReader(args[0]))); csvWriter = new CSVWriter(new BufferedWriter(new FileWriter(args[1]))); String[] line; Pattern pattern = Pattern.compile("^(\\w\\w\\w).*?(\\d+)(M|Y)(\\d+)(M|Y)\\s*?(PY|RC)\\s*?(.*)$"); BloombergReferenceDataProvider rawBbgRefDataProvider = getBloombergSecurityFileLoader(); MongoDBValueCachingReferenceDataProvider bbgRefDataProvider = MongoCachedReferenceData .makeMongoProvider(rawBbgRefDataProvider, BloombergSwaptionFileLoader.class); while ((line = csvReader.readNext()) != null) { String name = line[NAME_FIELD]; Matcher matcher = pattern.matcher(name); if (matcher.matches()) { String ccy = matcher.group(1); String swapTenorSize = matcher.group(2); String swapTenorUnit = matcher.group(3); String optionTenorSize = matcher.group(4); String optionTenorUnit = matcher.group(5); String payReceive = matcher.group(6); String distanceATM = matcher.group(7); String buid = "/buid/" + line[BUID_FIELD]; String value = bbgRefDataProvider.getReferenceDataValue(buid, "TICKER"); csvWriter.writeNext(new String[] { name, ccy, swapTenorSize, swapTenorUnit, optionTenorSize, optionTenorUnit, payReceive, distanceATM, value }); } else { s_logger.error("Couldn't parse " + name + " field"); } } } catch (IOException ioe) { s_logger.error("Error while reading file", ioe); } finally { IOUtils.closeQuietly(csvReader); IOUtils.closeQuietly(csvWriter); } }
From source file:de.codesourcery.eve.skills.datamodel.EveFlags.java
public static void main(String[] args) { final Pattern PATTERN = Pattern.compile("^([0-9]+),(.*?),(.*)$"); for (String line : FLAGS.split("\n")) { final String trimmed = StringUtils.strip(line); final Matcher m = PATTERN.matcher(line); if (!m.matches()) { throw new RuntimeException(); }//w ww . j a v a2 s .c om final int id = Integer.parseInt(m.group(1)); final String name = m.group(2).toUpperCase().replaceAll(" ", "_"); final String displayName = StringUtils.strip(m.group(3)); System.out.println(name + "(" + id + ",\"" + displayName + "\"),"); } }
From source file:edu.ku.brc.web.ParsePaleo.java
/** * @param args// w ww.j a v a2 s. c o m */ public static void main(String[] args) { if (true) { ParsePaleo pp = new ParsePaleo(); pp.processAll(); return; } try { HashSet<String> set = new HashSet<String>(); for (String line : FileUtils.readLines(new File("/Users/rods/Downloads/ages.txt"))) { //Pattern p = Pattern.compile("\"([^\"\\]*(\\.[^\"\\]*)*)\"|\'([^\'\\]*(\\.[^\'\\]*)*)\'"); //Pattern p = Pattern.compile("\"([^\"]*)\"|(\\S+)"); Pattern p = Pattern.compile("\"([^\"]*)\""); Matcher m = p.matcher(line); //List<String> animals = new ArrayList()<String>(); while (m.find()) { //System.out.println(m.group()); set.add(replace(m.group(), "\"", "")); //animals.add(m.group()); } } for (String str : set) { System.out.println(str); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.meidusa.amoeba.route.AbstractQueryRouter.java
License:asdf
public static void main(String[] aa) { String[] aaa = StringUtil.split("asdfasdf,asdf;aqwer", ";,"); for (String aaaaa : aaa) { System.out.println(aaaaa); }/*from ww w . j av a 2 s. co m*/ System.out.println(System.currentTimeMillis()); String source = "^fileSys_[a-zA-Z0-9_]*"; Pattern pattern = null; if (pattern == null) { pattern = Pattern.compile(source); } java.util.regex.Matcher matcher = pattern.matcher("fileSys_abc12d"); System.out.println(matcher.matches()); }
From source file:com.basistech.lucene.tools.LuceneQueryTool.java
public static void main(String[] args) throws IOException, org.apache.lucene.queryparser.classic.ParseException { String charsetName = Charset.defaultCharset().name(); if (!"UTF-8".equals(charsetName)) { // Really only a problem on mac, where the default charset is MacRoman, // and it cannot be changed via the system Locale. System.err.println(String.format("defaultCharset is %s, but we require UTF-8.", charsetName)); System.err.println("Set -Dfile.encoding=UTF-8 on the Java command line, or"); System.err.println("set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 in the environment."); System.exit(1);/*w ww . j a va 2s .c om*/ } Options options = LuceneQueryTool.createOptions(); CommandLineParser parser = new GnuParser(); CommandLine cmdline = null; try { cmdline = parser.parse(options, args); validateOptions(options, args); } catch (org.apache.commons.cli.ParseException e) { System.err.println(e.getMessage()); usage(options); System.exit(1); } String[] remaining = cmdline.getArgs(); if (remaining != null && remaining.length > 0) { System.err.println("unknown extra args found: " + Lists.newArrayList(remaining)); usage(options); System.exit(1); } String[] indexPaths = cmdline.getOptionValues("index"); IndexReader[] readers = new IndexReader[indexPaths.length]; for (int i = 0; i < indexPaths.length; i++) { readers[i] = DirectoryReader.open(FSDirectory.open(new File(indexPaths[i]))); } IndexReader reader = new MultiReader(readers, true); LuceneQueryTool that = new LuceneQueryTool(reader); String opt; opt = cmdline.getOptionValue("query-limit"); if (opt != null) { that.setQueryLimit(Integer.parseInt(opt)); } opt = cmdline.getOptionValue("output-limit"); if (opt != null) { that.setOutputLimit(Integer.parseInt(opt)); } opt = cmdline.getOptionValue("analyzer"); if (opt != null) { that.setAnalyzer(opt); } opt = cmdline.getOptionValue("query-field"); if (opt != null) { that.setDefaultField(opt); } opt = cmdline.getOptionValue("output"); PrintStream out = null; if (opt != null) { out = new PrintStream(new FileOutputStream(new File(opt)), true); that.setOutputStream(out); } if (cmdline.hasOption("show-id")) { that.setShowId(true); } if (cmdline.hasOption("show-hits")) { that.setShowHits(true); } if (cmdline.hasOption("show-score")) { that.setShowScore(true); } if (cmdline.hasOption("sort-fields")) { that.setSortFields(true); } if (cmdline.hasOption("suppress-names")) { that.setSuppressNames(true); } if (cmdline.hasOption("tabular")) { that.setTabular(true); } String[] opts; opts = cmdline.getOptionValues("fields"); if (opts != null) { that.setFieldNames(Lists.newArrayList(opts)); } opt = cmdline.getOptionValue("regex"); if (opt != null) { Pattern p = Pattern.compile("^(.*?):/(.*)/$"); Matcher m = p.matcher(opt); if (m.matches()) { that.setRegex(m.group(1), Pattern.compile(m.group(2))); } else { System.err.println("Invalid regex, should be field:/regex/"); usage(options); System.exit(1); } } opts = cmdline.getOptionValues("query"); that.run(opts); if (out != null) { out.close(); } reader.close(); }
From source file:com.wittawat.wordseg.Main.java
public static void main(String[] args) throws Exception { Console con = System.console(); if (con == null) { System.out.println("The system must support console to run the program."); System.exit(1);//from w w w.ja v a2 s . c om } // Load model System.out.println("Loading model ..."); Classifier model = Data.getDefaultModel(); System.out.println("Finished loading model."); System.out.println(getAgreement()); boolean isUseDict = true; // Dummy statement to eliminate all lazy loading System.out.println("\n" + new NukeTokenizer3( "?????", model, isUseDict).tokenize() + "\n"); System.out.println(getHelp()); final String SET_DICT_PAT_STR = "\\s*set\\s+dict\\s+(true|false)\\s*"; final Pattern SET_DICT_PAT = Pattern.compile(SET_DICT_PAT_STR); while (true) { System.out.print(">> "); String line = con.readLine(); if (line != null && !line.trim().equals("")) { line = line.trim(); try { if (line.equals("h") || line.equals("help")) { System.out.println(getHelp()); } else if (line.equals("about")) { System.out.println(getAbout()); } else if (line.equals("agreement")) { System.out.println(getAgreement()); } else if (SET_DICT_PAT.matcher(line).find()) { Matcher m = SET_DICT_PAT.matcher(line); m.find(); String v = m.group(1); isUseDict = v.equals("true"); System.out.println("Dictionary will " + (isUseDict ? "" : "not ") + "be used."); } else if (line.matches("q|quit|exit")) { System.out.println("Bye"); System.exit(0); } else if (line.contains(":tokfile:")) { String[] splits = line.split(":tokfile:"); String in = splits[0]; String out = splits[1]; String content = FileUtils.readFileToString(new File(in)); long start = new Date().getTime(); NukeTokenizer tokenizer = new NukeTokenizer3(content, model, isUseDict); String tokenized = tokenizer.tokenize(); long end = new Date().getTime(); System.out.println("Time to tokenize: " + (end - start) + " ms."); FileUtils.writeStringToFile(new File(out), tokenized); } else if (line.contains(":tokfile")) { String[] splits = line.split(":tokfile"); String in = splits[0]; String content = FileUtils.readFileToString(new File(in)); long start = new Date().getTime(); NukeTokenizer tokenizer = new NukeTokenizer3(content, model, isUseDict); String tokenized = tokenizer.tokenize(); long end = new Date().getTime(); System.out.println(tokenized); System.out.println("Time to tokenize: " + (end - start) + " ms."); } else if (line.contains(":tok:")) { String[] splits = line.split(":tok:"); String inText = splits[0]; String out = splits[1]; long start = new Date().getTime(); NukeTokenizer tokenizer = new NukeTokenizer3(inText, model, isUseDict); String tokenized = tokenizer.tokenize(); long end = new Date().getTime(); System.out.println("Time to tokenize: " + (end - start) + " ms."); FileUtils.writeStringToFile(new File(out), tokenized); } else if (line.contains(":tok")) { String[] splits = line.split(":tok"); String inText = splits[0]; long start = new Date().getTime(); NukeTokenizer tokenizer = new NukeTokenizer3(inText, model, isUseDict); String tokenized = tokenizer.tokenize(); long end = new Date().getTime(); System.out.println(tokenized); System.out.println("Time to tokenize: " + (end - start) + " ms."); } else { System.out.println("Unknown command"); } } catch (Exception e) { System.out.println("Error. See the exception."); e.printStackTrace(); } } } }
From source file:eu.annocultor.converters.geonames.GeonamesDumpToRdf.java
public static void main(String[] args) throws Exception { File root = new File("input_source"); // load country-continent match countryToContinent// ww w . ja v a 2 s .c o m .load((new GeonamesDumpToRdf()).getClass().getResourceAsStream("/country-to-continent.properties")); // creating files Map<String, BufferedWriter> files = new HashMap<String, BufferedWriter>(); Map<String, Boolean> started = new HashMap<String, Boolean>(); for (Object string : countryToContinent.keySet()) { String continent = countryToContinent.getProperty(string.toString()); File dir = new File(root, continent); if (!dir.exists()) { dir.mkdir(); } files.put(string.toString(), new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File(root, continent + "/" + string + ".rdf")), "UTF-8"))); System.out.println(continent + "/" + string + ".rdf"); started.put(string.toString(), false); } System.out.println(started); Pattern countryPattern = Pattern .compile("<inCountry rdf\\:resource\\=\"http\\://www\\.geonames\\.org/countries/\\#(\\w\\w)\"/>"); long counter = 0; LineIterator it = FileUtils.lineIterator(new File(root, "all-geonames-rdf.txt"), "UTF-8"); try { while (it.hasNext()) { String text = it.nextLine(); if (text.startsWith("http://sws.geonames")) continue; // progress counter++; if (counter % 100000 == 0) { System.out.print("*"); } // System.out.println(counter); // get country String country = null; Matcher matcher = countryPattern.matcher(text); if (matcher.find()) { country = matcher.group(1); } // System.out.println(country); if (country == null) country = "null"; text = text.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><rdf:RDF", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><rdf:RDF"); if (started.get(country) == null) throw new Exception("Unknow country " + country); if (started.get(country).booleanValue()) { // remove RDF opening text = text.substring(text.indexOf("<rdf:RDF ")); text = text.substring(text.indexOf(">") + 1); } // remove RDF ending text = text.substring(0, text.indexOf("</rdf:RDF>")); files.get(country).append(text + "\n"); if (!started.get(country).booleanValue()) { // System.out.println("Started with country " + country); } started.put(country, true); } } finally { LineIterator.closeQuietly(it); } for (Object string : countryToContinent.keySet()) { boolean hasStarted = started.get(string.toString()).booleanValue(); if (hasStarted) { BufferedWriter bf = files.get(string.toString()); bf.append("</rdf:RDF>"); bf.flush(); bf.close(); } } return; }
From source file:de.citec.csra.elancsv.parser.SimpleParser.java
public static void main(String[] args) throws IOException, ParseException { Options opts = new Options(); opts.addOption("file", true, "Tab-separated ELAN export file to load."); opts.addOption("tier", true, "Tier to analyze. Optional: Append ::num to interpret annotations numerically."); opts.addOption("format", true, "How to read information from the file name. %V -> participant, %A -> annoatator, %C -> condition, e.g. \"%V - %A\""); opts.addOption("help", false, "Print this help and exit"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(opts, args); if (cmd.hasOption("help")) { helpExit(opts, "where OPTION includes:"); }/*from ww w.j av a 2 s .c o m*/ String infile = cmd.getOptionValue("file"); if (infile == null) { helpExit(opts, "Error: no file given."); } String format = cmd.getOptionValue("format"); if (format == null) { helpExit(opts, "Error: no format given."); } String tier = cmd.getOptionValue("tier"); if (tier == null) { helpExit(opts, "Error: no tier given."); } // TODO count values in annotations (e.g. search all robot occurrences) String[] tn = tier.split("::"); boolean numeric = false; if (tn.length == 2 && tn[1].equals("num")) { numeric = true; tier = tn[0]; } format = "^" + format + "$"; format = format.replaceFirst("%V", "(?<V>.*?)"); format = format.replaceFirst("%A", "(?<A>.*?)"); format = format.replaceFirst("%C", "(?<C>.*?)"); Pattern pa = Pattern.compile(format); Map<String, Participant> participants = new HashMap<>(); BufferedReader br = new BufferedReader(new FileReader(infile)); String line; int lineno = 0; while ((line = br.readLine()) != null) { String[] parts = line.split("\t"); lineno++; if (parts.length < 5) { System.err.println("WARNING: line '" + lineno + "' too short '" + line + "'"); continue; } Annotation a = new Annotation(Long.valueOf(parts[ElanFormat.START.field]), Long.valueOf(parts[ElanFormat.STOP.field]), Long.valueOf(parts[ElanFormat.DURATION.field]), parts[ElanFormat.VALUE.field]); String tname = parts[ElanFormat.TIER.field]; String file = parts[ElanFormat.FILE.field].replaceAll(".eaf", ""); Matcher m = pa.matcher(file); String vp = file; String condition = "?"; String annotator = "?"; String participantID = vp; if (m.find()) { vp = m.group("V"); if (format.indexOf("<A>") > 0) { annotator = m.group("A"); } if (format.indexOf("<C>") > 0) { condition = m.group("C"); } } participantID = vp + ";" + annotator; if (!participants.containsKey(participantID)) { participants.put(participantID, new Participant(vp, condition, annotator)); } Participant p = participants.get(participantID); if (!p.tiers.containsKey(tname)) { p.tiers.put(tname, new Tier(tname)); } p.tiers.get(tname).annotations.add(a); } Map<String, Map<String, Number>> values = new HashMap<>(); Set<String> rownames = new HashSet<>(); String allCountKey = "c: all values"; String allDurationKey = "d: all values"; String allMeanKey = "m: all values"; for (Map.Entry<String, Participant> e : participants.entrySet()) { // System.out.println(e); Tier t = e.getValue().tiers.get(tier); String participantID = e.getKey(); if (!values.containsKey(participantID)) { values.put(participantID, new HashMap<String, Number>()); } Map<String, Number> row = values.get(participantID); //participant id if (t != null) { row.put(allCountKey, 0l); row.put(allDurationKey, 0l); row.put(allMeanKey, 0l); for (Annotation a : t.annotations) { long countAll = (long) row.get(allCountKey) + 1; long durationAll = (long) row.get(allDurationKey) + a.duration; long meanAll = durationAll / countAll; row.put(allCountKey, countAll); row.put(allDurationKey, durationAll); row.put(allMeanKey, meanAll); if (!numeric) { String countKey = "c: " + a.value; String durationKey = "d: " + a.value; String meanKey = "m: " + a.value; if (!row.containsKey(countKey)) { row.put(countKey, 0l); } if (!row.containsKey(durationKey)) { row.put(durationKey, 0l); } if (!row.containsKey(meanKey)) { row.put(meanKey, 0d); } long count = (long) row.get(countKey) + 1; long duration = (long) row.get(durationKey) + a.duration; double mean = duration * 1.0 / count; row.put(countKey, count); row.put(durationKey, duration); row.put(meanKey, mean); rownames.add(countKey); rownames.add(durationKey); rownames.add(meanKey); } else { String countKey = "c: " + t.name; String sumKey = "s: " + t.name; String meanKey = "m: " + t.name; if (!row.containsKey(countKey)) { row.put(countKey, 0l); } if (!row.containsKey(sumKey)) { row.put(sumKey, 0d); } if (!row.containsKey(meanKey)) { row.put(meanKey, 0d); } double d = 0; try { d = Double.valueOf(a.value); } catch (NumberFormatException ex) { } long count = (long) row.get(countKey) + 1; double sum = (double) row.get(sumKey) + d; double mean = sum / count; row.put(countKey, count); row.put(sumKey, sum); row.put(meanKey, mean); rownames.add(countKey); rownames.add(sumKey); rownames.add(meanKey); } } } } ArrayList<String> list = new ArrayList(rownames); Collections.sort(list); StringBuilder header = new StringBuilder("ID;Annotator;"); header.append(allCountKey); header.append(";"); header.append(allDurationKey); header.append(";"); header.append(allMeanKey); header.append(";"); for (String l : list) { header.append(l); header.append(";"); } System.out.println(header); for (Map.Entry<String, Map<String, Number>> e : values.entrySet()) { StringBuilder row = new StringBuilder(e.getKey()); row.append(";"); if (e.getValue().containsKey(allCountKey)) { row.append(e.getValue().get(allCountKey)); } else { row.append("0"); } row.append(";"); if (e.getValue().containsKey(allDurationKey)) { row.append(e.getValue().get(allDurationKey)); } else { row.append("0"); } row.append(";"); if (e.getValue().containsKey(allMeanKey)) { row.append(e.getValue().get(allMeanKey)); } else { row.append("0"); } row.append(";"); for (String l : list) { if (e.getValue().containsKey(l)) { row.append(e.getValue().get(l)); } else { row.append("0"); } row.append(";"); } System.out.println(row); } }