Example usage for java.util.regex Matcher groupCount

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

Introduction

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

Prototype

public int groupCount() 

Source Link

Document

Returns the number of capturing groups in this matcher's pattern.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.textnormalizer.ReplacementFileNormalizer.java

@Override
protected Map<Integer, List<SofaChangeAnnotation>> createSofaChangesMap(JCas jcas) {
    Map<Integer, List<SofaChangeAnnotation>> changesMap = new TreeMap<Integer, List<SofaChangeAnnotation>>();
    int mapKey = 1;

    String coveredText = jcas.getDocumentText().toLowerCase();

    List<SofaChangeAnnotation> scaChangesList = new ArrayList<SofaChangeAnnotation>();
    for (Map.Entry<String, String> entry : replacementMap.entrySet()) {
        String replacementKey = entry.getKey().toLowerCase();
        String replacementValue = targetSurroundings + entry.getValue() + targetSurroundings;

        String regex = srcSurroundingsStart + "(" + Pattern.quote(replacementKey) + ")" + srcSurroundingsEnd;
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(coveredText);

        int groupNumberOfKey = (matcher.groupCount() == 1) ? 1 : 2;

        while (matcher.find()) {
            int start = matcher.start(groupNumberOfKey);
            int end = matcher.end(groupNumberOfKey);

            SofaChangeAnnotation sca = new SofaChangeAnnotation(jcas);
            sca.setBegin(start);//from   www  .  j  av  a  2s. c o m
            sca.setEnd(end);
            sca.setOperation(OP_REPLACE);
            sca.setValue(replacementValue);
            scaChangesList.add(sca);

            System.out.println(matcher.group(0));
        }

    }
    changesMap.put(mapKey++, scaChangesList);

    return changesMap;
}

From source file:org.apache.maven.plugin.cxx.VisualStudioMojo.java

protected String buildVersionExtension() {
    Pattern p = Pattern.compile("(\\d+\\.)+\\d+((-[^-\\s]+)+)");
    Matcher m = p.matcher(buildVersion);
    if (m.matches() && m.groupCount() >= 3) {
        String versionExtension = m.group(2);
        getLog().debug("Visual Studio compatible Extension version is " + versionExtension);
        if (versionExtension.contains("SNAPSHOT")) {
            return versionExtension.replaceAll("SNAPSHOT",
                    (new SimpleDateFormat("yyyyMMdd.HHmmss")).format(new Date()));
        } else {//from   www .ja  va  2 s  .c  o  m
            return versionExtension;
        }
    } else {
        getLog().debug("Visual Studio compatible Extension version is empty");
        return "\"\\0\""; // this \0 will go through batch script, env var and C++/RCC preprocessor
    }
}

From source file:org.betaconceptframework.astroboa.resourceapi.utility.BinaryChannelFileAccessInfoProcessor.java

private void logGroups(Matcher uriMatcher) {

    if (logger.isDebugEnabled()) {
        for (int j = 1; j <= uriMatcher.groupCount(); j++) {
            logger.debug("Group {} {}", j, uriMatcher.group(j));
        }/*w  ww  . j a  v  a2s .  c  o  m*/
    }

}

From source file:org.alfresco.repo.security.person.RegexHomeFolderProvider.java

@Override
public List<String> getHomeFolderPath(NodeRef person) {
    List<String> path = new ArrayList<String>();
    String key = FileNameValidator
            .getValidFileName(getHomeFolderManager().getPersonProperty(person, propertyName));
    if (pattern != null) {
        Matcher matcher = pattern.matcher(key);

        if (matcher.find()) {
            int groupCount = matcher.groupCount();
            if (!groupOrder.isEmpty()) {
                for (int group : groupOrder) {
                    if (group > groupCount) {
                        throw new PersonException("groupOrdering value " + group + " is out of range.");
                    }//from  w  w w.j  ava 2 s.  c o m
                    addFolderToPath(path, matcher, group);
                }
            } else // "natural" group ordering, i.e as they appear in the regex
            {
                for (int group = 1; group <= groupCount; group++) {
                    addFolderToPath(path, matcher, group);
                }
            }
        }
    }
    path.add(key);

    if (logger.isDebugEnabled()) {
        logger.debug("returning " + path + " for key: " + key);
    }

    return path;
}

From source file:com.mewmew.fairy.v1.book.Cut.java

public void each(String input, Output<Map<String, Object>> mapOutput) throws IOException {
    if (regex != null) {
        Matcher matcher = regex.matcher(input);
        if (matcher.matches()) {
            Map<String, Object> map = new HashMap<String, Object>();
            for (int i = 1; i <= matcher.groupCount(); i++) {
                putValue(map, i - 1, matcher.group(i));
            }//from  w  w w.ja  v  a 2s. co  m
            if (!map.isEmpty()) {
                mapOutput.output(map);
            }
        }
    } else {
        String[] values = input.split(delimiter);
        Map<String, Object> map = new HashMap<String, Object>();
        if (values.length > 0) {
            for (int i = 0; i < values.length; i++) {
                putValue(map, i, values[i]);
            }
            mapOutput.output(map);
        }
    }
}

From source file:com.microsoft.alm.plugin.idea.ui.simplecheckout.SimpleCheckoutModel.java

protected SimpleCheckoutModel(final Project project, final CheckoutProvider.Listener listener,
        final String gitUrl) {
    super();//from w w w  .j ava2 s.  c o m
    this.project = project;
    this.listener = listener;
    this.gitUrl = gitUrl;

    this.parentDirectory = PluginServiceProvider.getInstance().getPropertyService()
            .getProperty(PropertyService.PROP_REPO_ROOT);
    // use default root if no repo root is found
    if (StringUtils.isEmpty(this.parentDirectory)) {
        this.parentDirectory = DEFAULT_SOURCE_PATH;
    }

    // try and parse for the repo name to use as the directory name
    final Matcher matcher = GIT_URL_PATTERN.matcher(gitUrl);
    if (matcher.find() && matcher.groupCount() == 1) {
        this.directoryName = matcher.group(1);
    } else {
        this.directoryName = StringUtils.EMPTY;
    }
}

From source file:com.tacitknowledge.util.migration.jdbc.SqlScriptMigrationTaskSource.java

/**
 * Returns the order for the file./*from  ww w.j  ava  2  s .  c o m*/
 *
 * @param p              a Pattern defining the file name pattern
 * @param script         the Script
 * @param scriptFileName the name of the file
 * @return an int indicating the order
 * @throws MigrationException in case the file name is invalid
 */
private int getOrder(Pattern p, String script, String scriptFileName) throws MigrationException {
    Matcher matcher = p.matcher(scriptFileName);
    if (!matcher.matches() || matcher.groupCount() != 2) {
        throw new MigrationException("Invalid SQL script name: " + script);
    }
    int order = Integer.parseInt(matcher.group(1));
    return order;
}

From source file:com.aliyun.openservices.tablestore.hadoop.Endpoint.java

public Endpoint(String endpoint) {
    Preconditions.checkNotNull(endpoint, "endpoint should not be null.");
    this.endpoint = endpoint;
    Matcher m = kInstPattern.matcher(endpoint);
    Preconditions.checkArgument(m.matches(), "cannot parse instance from endpoint: " + endpoint);
    Preconditions.checkArgument(m.groupCount() == 2, "cannot parse instance from endpoint: " + endpoint);
    this.instance = m.group(2);
}

From source file:com.mapr.synth.samplers.ArrivalSampler.java

@SuppressWarnings("UnusedDeclaration")
public void setRate(String rate) {
    Matcher m = ratePattern.matcher(rate);
    if (m.matches()) {
        // group(1) is the number, group(2) is either empty (default to /s) or /d or some such.
        TimeUnit sourceUnit = (m.groupCount() > 1) ? unitMap.get(m.group(2).substring(1)) : TimeUnit.SECONDS;
        double count = Double.parseDouble(m.group(1));
        this.meanInterval = TimeUnit.MILLISECONDS.convert(1, sourceUnit) / count;
    } else {// w ww  . j  a v  a2 s.  co m
        throw new IllegalArgumentException(String.format("Invalid rate argument: %s", rate));
    }
}

From source file:org.apache.zeppelin.interpreter.install.InstallInterpreter.java

private void readAvailableInterpreters() throws IOException {
    if (!interpreterListFile.isFile()) {
        System.err.println("Can't find interpreter list " + interpreterListFile.getAbsolutePath());
        return;//  ww  w. j a  v  a2  s .c  o  m
    }
    String text = FileUtils.readFileToString(interpreterListFile);
    String[] lines = text.split("\n");

    Pattern pattern = Pattern.compile("(\\S+)\\s+(\\S+)\\s+(.*)");

    int lineNo = 0;
    for (String line : lines) {
        lineNo++;
        if (line == null || line.length() == 0 || line.startsWith("#")) {
            continue;
        }

        Matcher match = pattern.matcher(line);
        if (match.groupCount() != 3) {
            System.err.println("Error on line " + lineNo + ", " + line);
            continue;
        }

        match.find();

        String name = match.group(1);
        String artifact = match.group(2);
        String description = match.group(3);

        availableInterpreters.add(new AvailableInterpreterInfo(name, artifact, description));
    }
}