use of java.util.regex.Matcher in project cucumber-jvm by cucumber.
the class ArgumentPattern method replaceMatchWith.
private String replaceMatchWith(String name, String replacement) {
Matcher matcher = pattern.matcher(name);
String quotedReplacement = Matcher.quoteReplacement(replacement);
return matcher.replaceAll(quotedReplacement);
}
use of java.util.regex.Matcher in project cucumber-jvm by cucumber.
the class SnippetGenerator method patternFor.
String patternFor(String stepName) {
String pattern = stepName;
for (Pattern escapePattern : ESCAPE_PATTERNS) {
Matcher m = escapePattern.matcher(pattern);
String replacement = Matcher.quoteReplacement(escapePattern.toString());
pattern = m.replaceAll(replacement);
}
for (ArgumentPattern argumentPattern : argumentPatterns()) {
pattern = argumentPattern.replaceMatchesWithGroups(pattern);
}
if (snippet.namedGroupStart() != null) {
pattern = withNamedGroups(pattern);
}
return "^" + pattern + "$";
}
use of java.util.regex.Matcher in project cucumber-jvm by cucumber.
the class Shellwords method parse.
public static List<String> parse(String cmdline) {
List<String> matchList = new ArrayList<String>();
Matcher shellwordsMatcher = SHELLWORDS_PATTERN.matcher(cmdline);
while (shellwordsMatcher.find()) {
if (shellwordsMatcher.group(1) != null) {
matchList.add(shellwordsMatcher.group(1));
} else {
matchList.add(shellwordsMatcher.group());
}
}
return matchList;
}
use of java.util.regex.Matcher in project cucumber-jvm by cucumber.
the class MetaStepdef method matches.
public boolean matches(String text) {
Pattern p = pattern();
Matcher m = p.matcher(text);
return m.matches() || m.hitEnd();
}
use of java.util.regex.Matcher in project lucida by claritylab.
the class EnglishFeatureExtractor method addSyntacticFeatures.
private static void addSyntacticFeatures(MutableInstance instance, List<Term> terms, String parseTree, Term focusTerm) {
if (parseTree == null) {
log.error("Syntactic parse of the question is null.");
return;
}
Tree tree = TreeHelper.buildTree(parseTree, Tree.ENGLISH);
// MAIN_VERB
TreeHelper.markHeadNode(tree);
String mainVerb = tree.getHeadWord();
//mainVerb = WordnetInterface.getLemma("VERB",mainVerb);
try {
IndexWord word = Dictionary.getInstance().lookupIndexWord(POS.VERB, mainVerb);
String lemma = null;
if (word != null)
lemma = word.getLemma();
if (lemma != null)
mainVerb = lemma;
} catch (Exception e) {
log.warn("Failed to get lemma for verb '" + mainVerb + "'", e);
}
if (mainVerb == null)
mainVerb = "-";
instance.addBinary(new Feature("MAIN_VERB" + "." + mainVerb));
// WH_DET
if (focusTerm != null && focusTerm.getText() != null) {
String focus = focusTerm.getText();
String question = "";
for (Term term : terms) question += term.getText() + " ";
question = question.trim();
for (String ptrn : whPtrns) {
Matcher m = Pattern.compile(ptrn + SPACE_PTRN + focus + REST_PTRN).matcher(question);
if (m.matches()) {
instance.addBinary(new Feature("WH_DET" + ".+"));
break;
}
}
}
// FOCUS_ADJ
Tree focusNode = TreeHelper.findFirstPreterminalWithPrecedingPreterminal(tree, "RB|JJ", "WRB");
if (focusNode != null)
instance.addBinary(new Feature("FOCUS_ADJ" + "." + focusNode.getHeadWord()));
}
Aggregations