Search in sources :

Example 81 with Matcher

use of java.util.regex.Matcher in project lucida by claritylab.

the class AnswerPattern method replaceNeTags.

/**
	 * Replaces NE tags by regular expressions that match NE tags with at least
	 * one of the NE types.
	 * 
	 * @param expr pattern descriptor
	 * @return descriptor with regular expressions for NE tags
	 */
private String replaceNeTags(String expr) {
    Matcher m = Pattern.compile("<(NE[^>]*+)>").matcher(expr);
    while (m.find()) {
        // find next NE tag
        // get NE types
        String[] neTypes = m.group(1).split("_");
        // build regular expression
        // reluctant
        String regex = "<(?:NE[a-zA-Z0-9]*+_)*?";
        if (neTypes.length > 1)
            regex += "(?:";
        regex += neTypes[0];
        for (int i = 1; i < neTypes.length; i++) regex += "|" + neTypes[i];
        if (neTypes.length > 1)
            regex += ")";
        // possessive
        regex += "[^>]*+>";
        // replace NE tag
        expr = expr.replace(m.group(0), regex);
    }
    return expr;
}
Also used : Matcher(java.util.regex.Matcher)

Example 82 with Matcher

use of java.util.regex.Matcher in project lucida by claritylab.

the class CutKeywordsFilter method apply.

/**
	 * Cut the leading news agency acronym and city from a snippet, for instance
	 * from 'MOSCOW (ITAR-TAS) ... some useful information ...', in order to not
	 * waste result length
	 * 
	 * @param result a <code>Result</code> object
	 * @return the same <code>Result</code> object
	 */
public Result apply(Result result) {
    String text = result.getAnswer().trim();
    boolean changed = true;
    Matcher matcher;
    while (changed) {
        changed = false;
        matcher = KEYWORDS.matcher(text);
        if (matcher.matches()) {
            text = text.substring(matcher.group(1).length()).trim();
            changed = true;
        }
        matcher = BRACKETS.matcher(text);
        if (matcher.matches()) {
            text = text.substring(matcher.group(1).length()).trim();
            changed = true;
        }
    }
    result.setAnswer(text);
    return result;
}
Also used : Matcher(java.util.regex.Matcher)

Example 83 with Matcher

use of java.util.regex.Matcher in project cucumber-jvm by cucumber.

the class JdkPatternArgumentMatcher method argumentsFrom.

public List<Argument> argumentsFrom(String stepName) {
    Matcher matcher = pattern.matcher(stepName);
    if (matcher.lookingAt()) {
        List<Argument> arguments = new ArrayList<Argument>(matcher.groupCount());
        for (int i = 1; i <= matcher.groupCount(); i++) {
            int startIndex = matcher.start(i);
            arguments.add(new Argument(startIndex == -1 ? null : startIndex, matcher.group(i)));
        }
        return arguments;
    } else {
        return null;
    }
}
Also used : Argument(gherkin.formatter.Argument) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 84 with Matcher

use of java.util.regex.Matcher in project cucumber-jvm by cucumber.

the class MethodFormat method format.

public String format(Method method) {
    String signature = method.toGenericString();
    Matcher matcher = METHOD_PATTERN.matcher(signature);
    if (matcher.find()) {
        String M = matcher.group(1);
        String r = matcher.group(2);
        String qc = matcher.group(3);
        String m = matcher.group(4);
        String qa = matcher.group(5);
        String qe = matcher.group(6);
        String c = qc.replaceAll(PACKAGE_PATTERN, "");
        String a = qa.replaceAll(PACKAGE_PATTERN, "");
        String e = qe.replaceAll(PACKAGE_PATTERN, "");
        String s = getCodeSource(method);
        return format.format(new Object[] { M, r, qc, m, qa, qe, c, a, e, s });
    } else {
        throw new CucumberException("Cucumber bug: Couldn't format " + signature);
    }
}
Also used : Matcher(java.util.regex.Matcher)

Example 85 with Matcher

use of java.util.regex.Matcher in project cucumber-jvm by cucumber.

the class PluginFactory method getPluginClass.

private static Class getPluginClass(String name) {
    Matcher pluginWithFile = PLUGIN_WITH_FILE_PATTERN.matcher(name);
    String pluginName;
    if (pluginWithFile.matches()) {
        pluginName = pluginWithFile.group(1);
    } else {
        pluginName = name;
    }
    return pluginClass(pluginName);
}
Also used : Matcher(java.util.regex.Matcher)

Aggregations

Matcher (java.util.regex.Matcher)12473 Pattern (java.util.regex.Pattern)5010 ArrayList (java.util.ArrayList)1516 IOException (java.io.IOException)904 HashMap (java.util.HashMap)565 File (java.io.File)487 Test (org.junit.Test)442 BufferedReader (java.io.BufferedReader)428 Map (java.util.Map)363 List (java.util.List)287 InputStreamReader (java.io.InputStreamReader)266 HashSet (java.util.HashSet)236 MalformedURLException (java.net.MalformedURLException)163 URL (java.net.URL)155 Date (java.util.Date)152 InputStream (java.io.InputStream)147 Field (java.lang.reflect.Field)130 PatternSyntaxException (java.util.regex.PatternSyntaxException)128 ParseException (java.text.ParseException)127 LinkedHashMap (java.util.LinkedHashMap)120