Search in sources :

Example 86 with Matcher

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);
}
Also used : Matcher(java.util.regex.Matcher)

Example 87 with Matcher

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 + "$";
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 88 with Matcher

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;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 89 with Matcher

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();
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 90 with Matcher

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()));
}
Also used : Matcher(java.util.regex.Matcher) Tree(edu.cmu.lti.chineseNLP.util.Tree) Term(edu.cmu.lti.javelin.qa.Term) IndexWord(net.didion.jwnl.data.IndexWord) Feature(edu.cmu.minorthird.classify.Feature)

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