Search in sources :

Example 76 with Matcher

use of java.util.regex.Matcher in project zeppelin by apache.

the class Input method extractSimpleQueryParam.

public static Map<String, Input> extractSimpleQueryParam(String script) {
    Map<String, Input> params = new HashMap<>();
    if (script == null) {
        return params;
    }
    String replaced = script;
    Matcher match = VAR_PTN.matcher(replaced);
    while (match.find()) {
        Input param = getInputForm(match);
        params.put(param.name, param);
    }
    params.remove("pql");
    return params;
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher)

Example 77 with Matcher

use of java.util.regex.Matcher in project zeppelin by apache.

the class NotebookServer method restoreFolder.

private void restoreFolder(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
    String folderId = (String) fromMessage.get("id");
    if (folderId == null) {
        return;
    }
    Folder folder = notebook.getFolder(folderId);
    if (folder != null && folder.isTrash()) {
        String restoreName = folder.getId().replaceFirst(Folder.TRASH_FOLDER_ID + "/", "").trim();
        // if the folder had conflict when it had moved to trash before
        Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
        Matcher m = p.matcher(restoreName);
        restoreName = m.replaceAll("").trim();
        fromMessage.put("name", restoreName);
        renameFolder(conn, userAndRoles, notebook, fromMessage, "restore");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Folder(org.apache.zeppelin.notebook.Folder)

Example 78 with Matcher

use of java.util.regex.Matcher in project zeppelin by apache.

the class MongoNotebookRepo method printDuplicatedException.

/**
   * MongoBulkWriteException contains error messages that inform
   * which documents were duplicated. This method catches those ID and print them.
   * @param e
   */
private void printDuplicatedException(MongoBulkWriteException e) {
    List<BulkWriteError> errors = e.getWriteErrors();
    for (BulkWriteError error : errors) {
        String msg = error.getMessage();
        // regex for note ID
        Pattern pattern = Pattern.compile("[A-Z0-9]{9}");
        Matcher matcher = pattern.matcher(msg);
        if (matcher.find()) {
            // if there were a note ID
            String noteId = matcher.group();
            LOG.warn("Note " + noteId + " not inserted since already exists in MongoDB");
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BulkWriteError(com.mongodb.bulk.BulkWriteError)

Example 79 with Matcher

use of java.util.regex.Matcher in project GCViewer by chewiebug.

the class AbstractDataReaderSun method extractTypeFromParsedString.

protected ExtendedType extractTypeFromParsedString(String typeName) throws UnknownGcTypeException {
    ExtendedType extendedType = null;
    String lookupTypeName = typeName.endsWith("--") ? typeName.substring(0, typeName.length() - 2) : typeName;
    AbstractGCEvent.Type gcType = AbstractGCEvent.Type.lookup(lookupTypeName);
    // the gcType may be null because there was a PrintGCCause flag enabled - if so, reparse it with the first paren set stripped
    if (gcType == null) {
        // try to parse it again with the parens removed
        Matcher parenMatcher = parenthesesPattern.matcher(lookupTypeName);
        if (parenMatcher.find()) {
            gcType = AbstractGCEvent.Type.lookup(parenMatcher.replaceFirst(""));
        }
    }
    if (gcType != null) {
        extendedType = ExtendedType.lookup(gcType, typeName);
    }
    return extendedType;
}
Also used : Matcher(java.util.regex.Matcher) AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent) ExtendedType(com.tagtraum.perf.gcviewer.model.AbstractGCEvent.ExtendedType)

Example 80 with Matcher

use of java.util.regex.Matcher 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)

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