Example usage for java.util.regex Matcher find

List of usage examples for java.util.regex Matcher find

Introduction

In this page you can find the example usage for java.util.regex Matcher find.

Prototype

public boolean find() 

Source Link

Document

Attempts to find the next subsequence of the input sequence that matches the pattern.

Usage

From source file:it.unipd.dei.ims.falcon.CmdLine.java

public static void main(String[] args) {

    // last argument is always index path
    Options options = new Options();
    // one of these actions has to be specified
    OptionGroup actionGroup = new OptionGroup();
    actionGroup.addOption(new Option("i", true, "perform indexing")); // if dir, all files, else only one file
    actionGroup.addOption(new Option("q", true, "perform a single query"));
    actionGroup.addOption(new Option("b", false, "perform a query batch (read from stdin)"));
    actionGroup.setRequired(true);/*from w  ww  .  jav a 2s  .  c o m*/
    options.addOptionGroup(actionGroup);

    // other options
    options.addOption(new Option("l", "segment-length", true, "length of a segment (# of chroma vectors)"));
    options.addOption(
            new Option("o", "segment-overlap", true, "overlap portion of a segment (# of chroma vectors)"));
    options.addOption(new Option("Q", "quantization-level", true, "quantization level for chroma vectors"));
    options.addOption(new Option("k", "min-kurtosis", true, "minimum kurtosis for indexing chroma vectors"));
    options.addOption(new Option("s", "sub-sampling", true, "sub-sampling of chroma features"));
    options.addOption(new Option("v", "verbose", false, "verbose output (including timing info)"));
    options.addOption(new Option("T", "transposition-estimator-strategy", true,
            "parametrization for the transposition estimator strategy"));
    options.addOption(new Option("t", "n-transp", true,
            "number of transposition; if not specified, no transposition is performed"));
    options.addOption(new Option("f", "force-transp", true, "force transposition by an amount of semitones"));
    options.addOption(new Option("p", "pruning", false,
            "enable query pruning; if -P is unspecified, use default strategy"));
    options.addOption(new Option("P", "pruning-custom", true, "custom query pruning strategy"));

    // parse
    HelpFormatter formatter = new HelpFormatter();
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
        if (cmd.getArgs().length != 1)
            throw new ParseException("no index path was specified");
    } catch (ParseException ex) {
        System.err.println("ERROR - parsing command line:");
        System.err.println(ex.getMessage());
        formatter.printHelp("falcon -{i,q,b} [options] index_path", options);
        return;
    }

    // default values
    final float[] DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY = new float[] { 0.65192807f, 0.0f, 0.0f, 0.0f,
            0.3532628f, 0.4997167f, 0.0f, 0.41703504f, 0.0f, 0.16297342f, 0.0f, 0.0f };
    final String DEFAULT_QUERY_PRUNING_STRATEGY = "ntf:0.340765*[0.001694,0.995720];ndf:0.344143*[0.007224,0.997113];"
            + "ncf:0.338766*[0.001601,0.995038];nmf:0.331577*[0.002352,0.997884];"; // TODO not the final one

    int hashes_per_segment = Integer.parseInt(cmd.getOptionValue("l", "150"));
    int overlap_per_segment = Integer.parseInt(cmd.getOptionValue("o", "50"));
    int nranks = Integer.parseInt(cmd.getOptionValue("Q", "3"));
    int subsampling = Integer.parseInt(cmd.getOptionValue("s", "1"));
    double minkurtosis = Float.parseFloat(cmd.getOptionValue("k", "-100."));
    boolean verbose = cmd.hasOption("v");
    int ntransp = Integer.parseInt(cmd.getOptionValue("t", "1"));
    TranspositionEstimator tpe = null;
    if (cmd.hasOption("t")) {
        if (cmd.hasOption("T")) {
            // TODO this if branch is yet to test
            Pattern p = Pattern.compile("\\d\\.\\d*");
            LinkedList<Double> tokens = new LinkedList<Double>();
            Matcher m = p.matcher(cmd.getOptionValue("T"));
            while (m.find())
                tokens.addLast(new Double(cmd.getOptionValue("T").substring(m.start(), m.end())));
            float[] strategy = new float[tokens.size()];
            if (strategy.length != 12) {
                System.err.println("invalid transposition estimator strategy");
                System.exit(1);
            }
            for (int i = 0; i < strategy.length; i++)
                strategy[i] = new Float(tokens.pollFirst());
        } else {
            tpe = new TranspositionEstimator(DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY);
        }
    } else if (cmd.hasOption("f")) {
        int[] transps = parseIntArray(cmd.getOptionValue("f"));
        tpe = new ForcedTranspositionEstimator(transps);
        ntransp = transps.length;
    }
    QueryPruningStrategy qpe = null;
    if (cmd.hasOption("p")) {
        if (cmd.hasOption("P")) {
            qpe = new StaticQueryPruningStrategy(cmd.getOptionValue("P"));
        } else {
            qpe = new StaticQueryPruningStrategy(DEFAULT_QUERY_PRUNING_STRATEGY);
        }
    }

    // action
    if (cmd.hasOption("i")) {
        try {
            Indexing.index(new File(cmd.getOptionValue("i")), new File(cmd.getArgs()[0]), hashes_per_segment,
                    overlap_per_segment, subsampling, nranks, minkurtosis, tpe, verbose);
        } catch (IndexingException ex) {
            Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (cmd.hasOption("q")) {
        String queryfilepath = cmd.getOptionValue("q");
        doQuery(cmd, queryfilepath, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp,
                minkurtosis, qpe, verbose);
    }
    if (cmd.hasOption("b")) {
        try {
            long starttime = System.currentTimeMillis();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String line = null;
            while ((line = in.readLine()) != null && !line.trim().isEmpty())
                doQuery(cmd, line, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp,
                        minkurtosis, qpe, verbose);
            in.close();
            long endtime = System.currentTimeMillis();
            System.out.println(String.format("total time: %ds", (endtime - starttime) / 1000));
        } catch (IOException ex) {
            Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.baifendian.swordfish.execserver.job.AbstractYarnJob.java

public static void main(String[] args) {
    String msg = "INFO  : Starting Job = job_1499151077551_0548, Tracking URL = http://bgsbtsp0006-dqf:8088/proxy/application_1499151077551_0548/\n";

    //  application id
    Matcher matcher = APPLICATION_REGEX.matcher(msg);

    while (matcher.find()) {
        System.out.println(matcher.group());
    }// w  w  w  .  j a  v  a  2s.  com

    //  job id
    matcher = JOB_REGEX.matcher(msg);

    while (matcher.find()) {
        System.out.println(matcher.group());
    }

    // ? msg
    msg = "sh.execserver.runner.node.NodeRunner:application[147] -  hive execute log : INFO  : Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0";

    //  application id
    matcher = APPLICATION_REGEX.matcher(msg);

    while (matcher.find()) {
        System.out.println(matcher.group());
    }

    //  job id
    matcher = JOB_REGEX.matcher(msg);

    while (matcher.find()) {
        System.out.println(matcher.group());
    }
}

From source file:de.mpg.escidoc.services.cone.util.CCCrawler.java

public static void main(String[] args) throws Exception {
    HttpClient httpClient = new HttpClient();

    querier = QuerierFactory.newQuerier(false);

    // field_commercial
    for (YesNo fieldCommercial : YesNo.values()) {
        // field_derivatives
        for (YesNo fieldDerivatives : YesNo.values()) {
            // field_derivatives
            for (Jurisdiction fieldJurisdiction : Jurisdiction.values()) {
                String licenceUrl = ccUrl + "&field_commercial=" + fieldCommercial.toString()
                        + "&field_derivatives=" + fieldDerivatives.toString() + "&field_jurisdiction="
                        + fieldJurisdiction.toString() + "&lang=de_DE";
                System.out.println(licenceUrl);
                GetMethod method = new GetMethod(licenceUrl);
                ProxyHelper.executeMethod(httpClient, method);

                if (method.getStatusCode() == 200) {
                    TreeFragment fragment = new TreeFragment();

                    String key1 = "urn:cone:commercial";
                    String key3 = "urn:cone:jurisdiction";

                    List<LocalizedTripleObject> list = new ArrayList<LocalizedTripleObject>();
                    list.add(new LocalizedString(fieldCommercial.toBoolean()));
                    fragment.put(key1, list);

                    List<LocalizedTripleObject> list2 = new ArrayList<LocalizedTripleObject>();
                    list2.add(new LocalizedString(fieldDerivatives.toBoolean()));
                    fragment.put("urn:cone:derivatives", list2);

                    List<LocalizedTripleObject> list3 = new ArrayList<LocalizedTripleObject>();
                    list3.add(new LocalizedString(fieldJurisdiction.toString()));
                    fragment.put(key3, list3);

                    String codeToCopy = extractCode(method);

                    Pattern urlPattern = Pattern.compile("href=\"([^\"]+)\"");
                    Matcher urlMatcher = urlPattern.matcher(codeToCopy);
                    if (urlMatcher.find()) {
                        String url = urlMatcher.group(1);
                        fragment.setSubject(url);

                        Pattern versionPattern = Pattern.compile("/(\\d+\\.\\d+)/[^/]+/$");
                        Matcher versionMatcher = versionPattern.matcher(url);
                        if (versionMatcher.find()) {
                            list = new ArrayList<LocalizedTripleObject>();
                            list.add(new LocalizedString(versionMatcher.group(1)));
                            fragment.put("urn:cone:version", list);
                        }//from  w  ww  . j ava 2s. c o  m

                        Pattern imgPattern = Pattern.compile("src=\"([^\"]+)\"");
                        Matcher imgMatcher = imgPattern.matcher(codeToCopy);
                        if (imgMatcher.find()) {
                            list = new ArrayList<LocalizedTripleObject>();
                            list.add(new LocalizedString(imgMatcher.group(1)));
                            fragment.put("http://xmlns.com/foaf/0.1/depiction", list);
                        }

                        GetMethod method2 = new GetMethod(url);
                        ProxyHelper.executeMethod(httpClient, method2);
                        String page = method2.getResponseBodyAsString();

                        Pattern namePattern = Pattern.compile("<h2 property=\"dc:title\">([^<]+)</h2>");
                        Matcher nameMatcher = namePattern.matcher(page);
                        if (nameMatcher.find()) {
                            list = new ArrayList<LocalizedTripleObject>();
                            list.add(new LocalizedString(nameMatcher.group(1)));
                            fragment.put("http://purl.org/dc/elements/1.1/title", list);
                        }

                        List<LocalizedTripleObject> languages = extractLanguages(page, url);

                        fragment.put("urn:cone:translation", languages);

                        querier.delete("cclicences", url);
                        querier.create("cclicences", url, fragment);
                    }

                } else {
                    System.out.println("Not found: " + licenceUrl);
                }
            }
        }
    }
    querier.release();
}

From source file:RegExpExample.java

public static void main(String args[]) {
    String fileName = "RETestSource.java";

    String unadornedClassRE = "^\\s*class (\\w+)";
    String doubleIdentifierRE = "\\b(\\w+)\\s+\\1\\b";

    Pattern classPattern = Pattern.compile(unadornedClassRE);
    Pattern doublePattern = Pattern.compile(doubleIdentifierRE);
    Matcher classMatcher, doubleMatcher;

    int lineNumber = 0;

    try {//from   w ww . ja v  a 2s . com
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String line;

        while ((line = br.readLine()) != null) {
            lineNumber++;

            classMatcher = classPattern.matcher(line);
            doubleMatcher = doublePattern.matcher(line);

            if (classMatcher.find()) {
                System.out.println("The class [" + classMatcher.group(1) + "] is not public");
            }

            while (doubleMatcher.find()) {
                System.out.println("The word \"" + doubleMatcher.group(1) + "\" occurs twice at position "
                        + doubleMatcher.start() + " on line " + lineNumber);
            }
        }
    } catch (IOException ioe) {
        System.out.println("IOException: " + ioe);
        ioe.printStackTrace();
    }
}

From source file:com.bigdata.rdf.sail.webapp.AbstractProtocolTest.java

/**
 * Sanity check the {@link #charset} pattern
 * @param argv//from w  ww  .  j  a  v  a2 s  .com
 */
public static void main(String argv[]) {
    for (final String t : new String[] { "text/html ; charset=iso-8856-1",
            "text/html ; charset=iso-8856-1; foo = bar", "text/html ;charset=iso-8856-1; foo = bar",
            "text/html ; charset= \"iso-8856-1\"", "text/html ; charset=iso-8856-1; foo = bar",
            "text/html ; charset = iso-8856-1; foo = bar", "text/html ; foo = bar", "text/html",

    }) {
        final Matcher m = charset.matcher(t);
        System.err.println(t + " ====> " + (m.find() ? m.group(1) : ""));
    }
}

From source file:uk.ac.ebi.intact.editor.controller.misc.MyNotesController.java

public static void main(String[] args) {
    Pattern p = Pattern.compile("\\{(\\w+):(\\w+)\\s(.+)\\}");

    Matcher matcher = p.matcher(
            "{query:Lalalala select exp from Experiment exp where exp.bioSource.cvTissue.ac = 'EBI-2609142'}");

    while (matcher.find()) {
        System.out.println(matcher.group(1));
        System.out.println(matcher.group(2));
        System.out.println(matcher.group(3));
    }//w  w  w.  j  a va2  s  .c  o m
}

From source file:net.cloudkit.relaxation.HttpClientTest.java

public static void main(String[] args) throws Exception {

    InetAddress[] addresss = InetAddress.getAllByName("google.com");
    for (InetAddress address : addresss) {

        System.out.println(address);

    }//from   w  ww.j  a v  a 2 s.  c  o  m

    CloseableHttpClient httpclient = HttpClients.createDefault();

    String __VIEWSTATE = "";
    String __EVENTVALIDATION = "";

    HttpGet httpGet = new HttpGet("http://query.customs.gov.cn/MNFTQ/MRoadQuery.aspx?" + Math.random() * 1000);
    httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    httpGet.setHeader("Accept-Encoding", "gzip, deflate, sdch");
    httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6");
    httpGet.setHeader("Cache-Control", "no-cache");
    // httpGet.setHeader("Connection", "keep-alive");
    httpGet.setHeader("Host", "query.customs.gov.cn");
    httpGet.setHeader("Pragma", "no-cache");
    httpGet.setHeader("Upgrade-Insecure-Requests", "1");
    httpGet.setHeader("User-Agent",
            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");

    HttpClientContext context = HttpClientContext.create();
    // CloseableHttpResponse response1 = httpclient.execute(httpGet, context);
    CloseableHttpResponse response1 = httpclient.execute(httpGet);
    // Header[] headers = response1.getHeaders(HttpHeaders.CONTENT_TYPE);
    // System.out.println("context cookies:" + context.getCookieStore().getCookies());
    // String setCookie = response1.getFirstHeader("Set-Cookie").getValue();
    // System.out.println("context cookies:" + setCookie);

    try {
        System.out.println(response1.getStatusLine());
        HttpEntity entity1 = response1.getEntity();
        // do something useful with the response body and ensure it is fully consumed

        String result = IOUtils.toString(entity1.getContent(), "GBK");
        // System.out.println(result);

        Matcher m1 = Pattern.compile(
                "<input type=\\\"hidden\\\" name=\\\"__VIEWSTATE\\\" id=\\\"__VIEWSTATE\\\" value=\\\"(.*)\\\" />")
                .matcher(result);
        __VIEWSTATE = m1.find() ? m1.group(1) : "";
        Matcher m2 = Pattern.compile(
                "<input type=\\\"hidden\\\" name=\\\"__EVENTVALIDATION\\\" id=\\\"__EVENTVALIDATION\\\" value=\\\"(.*)\\\" />")
                .matcher(result);
        __EVENTVALIDATION = m2.find() ? m2.group(1) : "";

        System.out.println(__VIEWSTATE);
        System.out.println(__EVENTVALIDATION);

        /*
        File storeFile = new File("D:\\customs\\customs"+ i +".jpg");
        FileOutputStream output = new FileOutputStream(storeFile);
        IOUtils.copy(input, output);
        output.close();
        */
        EntityUtils.consume(entity1);
    } finally {
        response1.close();
    }

    HttpPost httpPost = new HttpPost(
            "http://query.customs.gov.cn/MNFTQ/MRoadQuery.aspx?" + Math.random() * 1000);
    httpPost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    httpPost.setHeader("Accept-Encoding", "gzip, deflate");
    httpPost.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6");
    httpPost.setHeader("Cache-Control", "no-cache");
    // httpPost.setHeader("Connection", "keep-alive");
    httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    httpPost.setHeader("Cookie", "ASP.NET_SessionId=t1td453hcuy4oqiplekkqe55");
    httpPost.setHeader("Host", "query.customs.gov.cn");
    httpPost.setHeader("Origin", "http://query.customs.gov.cn");
    httpPost.setHeader("Pragma", "no-cache");
    httpPost.setHeader("Referer", "http://query.customs.gov.cn/MNFTQ/MRoadQuery.aspx");
    httpPost.setHeader("Upgrade-Insecure-Requests", "1");
    httpPost.setHeader("User-Agent",
            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("__VIEWSTATE", __VIEWSTATE));
    nvps.add(new BasicNameValuePair("__EVENTVALIDATION", __EVENTVALIDATION));
    nvps.add(new BasicNameValuePair("ScrollTop", ""));
    nvps.add(new BasicNameValuePair("__essVariable", ""));
    nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$txtManifestID", "5100312462240"));
    nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$txtBillNo", "7PH650021105"));
    nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$txtCode", "a778"));
    nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$btQuery", "   "));
    nvps.add(new BasicNameValuePair("select", ""));
    nvps.add(new BasicNameValuePair("select1", ""));
    nvps.add(new BasicNameValuePair("select2", ""));
    nvps.add(new BasicNameValuePair("select3", ""));
    nvps.add(new BasicNameValuePair("select4", ""));
    nvps.add(new BasicNameValuePair("select5", "??"));
    nvps.add(new BasicNameValuePair("select6", ""));
    nvps.add(new BasicNameValuePair("select7", ""));
    nvps.add(new BasicNameValuePair("select8", ""));

    httpPost.setEntity(new UrlEncodedFormEntity(nvps, "GBK"));

    CloseableHttpResponse response2 = httpclient.execute(httpPost);

    try {
        System.out.println(response2.getStatusLine());
        HttpEntity entity2 = response2.getEntity();
        // do something useful with the response body
        // and ensure it is fully consumed
        // System.out.println(entity2.getContent());
        System.out.println(IOUtils.toString(response2.getEntity().getContent(), "GBK"));

        EntityUtils.consume(entity2);
    } finally {
        response2.close();
    }

}

From source file:org.roda.core.common.SeleniumUtils.java

/**
 * /*from  ww w.  j  ava 2 s .c  o  m*/
 * @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: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   w  w w.j  a  v a2  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);
    }
}

From source file:edu.ku.brc.web.ParsePaleo.java

/**
 * @param args/*  ww  w . java2  s. com*/
 */
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();
    }
}