Search in sources :

Example 76 with Pattern

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

the class TextProcessor method parseAsWeek.

/** 
	 *  Returns the date range string by parsing s as a week. 
	 *
	 *  @param s String representing the result of the annotation pipeline
	 *  @param text String representing the original query
	 */
private String[] parseAsWeek(String s, String text) {
    // Check whether s is like "2016-W23" representing the previous week (a bug in coreNLP?).
    Pattern pattern_week = Pattern.compile("[0-9]{4,4}-[0-9]{2,2}-W[0-9]{2,2}");
    Matcher matcher_week = pattern_week.matcher(s);
    if (matcher_week.find()) {
        String[] s_parsed = matcher_week.group(0).split("W");
        int week_num = Integer.parseInt(s_parsed[s_parsed.length - 1]);
        return new String[] { getDateFromWeek(week_num + 1), getDateFromWeek(week_num + 2) };
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 77 with Pattern

use of java.util.regex.Pattern 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 78 with Pattern

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

the class FormatterMissingLifecycleMethods method ensure_name_with_spaces_works_with_args.

@Test
public void ensure_name_with_spaces_works_with_args() {
    RuntimeOptions options = new RuntimeOptions("--name 'some Name'");
    Pattern actualPattern = (Pattern) options.getFilters().iterator().next();
    assertEquals("some Name", actualPattern.pattern());
}
Also used : Pattern(java.util.regex.Pattern) Test(org.junit.Test)

Example 79 with Pattern

use of java.util.regex.Pattern 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 80 with Pattern

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

the class FormatterMissingLifecycleMethods method ensure_name_with_spaces_works_with_cucumber_options.

@Test
public void ensure_name_with_spaces_works_with_cucumber_options() {
    Properties properties = new Properties();
    properties.setProperty("cucumber.options", "--name 'some Name'");
    RuntimeOptions options = new RuntimeOptions(new Env(properties), Collections.<String>emptyList());
    Pattern actualPattern = (Pattern) options.getFilters().iterator().next();
    assertEquals("some Name", actualPattern.pattern());
}
Also used : Pattern(java.util.regex.Pattern) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Pattern (java.util.regex.Pattern)2745 Matcher (java.util.regex.Matcher)1806 ArrayList (java.util.ArrayList)334 Test (org.junit.Test)209 IOException (java.io.IOException)206 File (java.io.File)172 HashMap (java.util.HashMap)144 Field (java.lang.reflect.Field)118 BufferedReader (java.io.BufferedReader)108 Map (java.util.Map)97 PatternSyntaxException (java.util.regex.PatternSyntaxException)97 List (java.util.List)81 HashSet (java.util.HashSet)69 InputStreamReader (java.io.InputStreamReader)59 FileInputStream (java.io.FileInputStream)40 InputStream (java.io.InputStream)39 FileReader (java.io.FileReader)36 SmallTest (android.test.suitebuilder.annotation.SmallTest)31 URL (java.net.URL)29 LinkedHashMap (java.util.LinkedHashMap)28