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;
}
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;
}
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;
}
}
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);
}
}
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);
}
Aggregations