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