use of java.util.regex.Matcher in project lucida by claritylab.
the class CorefResolver method isAnswerTypeThing.
/*
* isAnswerTypeThing returns true if AnswerType is thing, else false @param
* stemmed question string @return boolean
*
*/
private static boolean isAnswerTypeThing(String question) {
ArrayList<Pattern> patterns = new ArrayList<Pattern>();
boolean f = false;
String qn = QuestionNormalizer.normalize(question);
String stemmed = QuestionNormalizer.stemVerbsAndNouns(qn);
String[] tokens = new String[1];
tokens[0] = "(what|which)";
for (int i = 0; i < tokens.length; i++) {
patterns.add(Pattern.compile("\\b" + tokens[i] + "\\b", Pattern.CASE_INSENSITIVE));
}
for (int i = 0; i < tokens.length; i++) {
Matcher m = patterns.get(i).matcher(stemmed);
if (m.find()) {
f = true;
}
}
return f;
}
use of java.util.regex.Matcher in project lucida by claritylab.
the class EphyraTREC13To16 method main.
/**
* Runs Ephyra on the TREC questions.
*
* @param args argument 1: questionfile<br>
* [argument 2: tag=runtag (uniquely identifies the run, also
* used as output file name, if not set an
* unambiguous tag is generated automatically)]<br>
* [argument 3: log=logfile (if not set an unambiguous file name
* is generated automatically)]<br>
* [argument 4: lin=input_logfile (specifies a separate logfile
* that is used as a source for answers to some of
* the questions, if not set the standard log file
* is used)]<br>
* [argument 5: lflags=[f][l][o] (answers to these types of
* questions are loaded from the log file instead
* of querying Ephyra, e.g. "flo" for factoid, list
* and other questions)]<br>
* [argument 6: fp=factoid_patternfile]<br>
* [argument 7: lp=list_patternfile]
*/
public static void main(String[] args) {
// enable output of status and error messages
MsgPrinter.enableStatusMsgs(true);
MsgPrinter.enableErrorMsgs(true);
if (args.length < 1) {
MsgPrinter.printUsage("java EphyraTREC13To16 questionfile " + "[tag=runtag] [log=logfile] " + "[lin=input_logfile] " + "[lflags=[f][l][o]] " + "[fp=factoid_patternfile] " + "[lp=list_patternfile]");
System.exit(1);
}
// load targets
targets = TREC13To16Parser.loadTargets(args[0]);
for (int i = 1; i < args.length; i++) if (args[i].matches("tag=.*")) {
// set run tag
runTag = args[i].substring(4);
} else if (args[i].matches("log=.*")) {
// set log file
logFile = args[i].substring(4);
} else if (args[i].matches("lin=.*")) {
// set separate input log file
inputLogFile = args[i].substring(4);
} else if (args[i].matches("lflags=.*")) {
// answers for some question types are loaded from log file
String flags = args[i].substring(7).toLowerCase();
if (flags.contains("f"))
factoidLog = true;
if (flags.contains("l"))
listLog = true;
if (flags.contains("o"))
otherLog = true;
} else if (args[i].matches("fp=.*")) {
// load factoid patterns
factoidPatterns = TREC13To16Parser.loadPatterns(args[i].substring(3));
} else if (args[i].matches("lp=.*")) {
// load list patterns
listPatterns = TREC13To16Parser.loadPatterns(args[i].substring(3));
}
// if run tag or log file not set, generate unambiguous names
if (runTag == null || logFile == null) {
String n = "";
Matcher m = Pattern.compile("\\d++").matcher(args[0]);
if (m.find())
n = m.group(0);
String date = "";
Calendar c = new GregorianCalendar();
date += c.get(Calendar.DAY_OF_MONTH);
if (date.length() == 1)
date = "0" + date;
date = (c.get(Calendar.MONTH) + 1) + date;
if (date.length() == 3)
date = "0" + date;
date = c.get(Calendar.YEAR) + date;
if (runTag == null)
runTag = "TREC" + n + "_" + date + "_out";
if (logFile == null)
logFile = "log/TREC" + n + "_" + date;
}
// if input log file not set, use standard log file
if (inputLogFile == null)
inputLogFile = logFile;
// enable logging
Logger.setLogfile(logFile);
Logger.enableLogging(true);
// run Ephyra on questions, evaluate answers if patterns available
runAndEval();
}
use of java.util.regex.Matcher in project cogtool by cogtool.
the class StandardDrawingEditor method setZoomFromUserInput.
protected void setZoomFromUserInput(String userInput) {
// TODO: this still really isn't the right UI. Instead of validating
// the value entered and then fussing at the user if it's not
// right, we should really be looking after every key press
// or paste operation and only allowing legal values to be
// entered at all.
// TODO: deal with localization here. Number formats are also locale
// specific. When we deal with that in general, it needs to be
// dealt with here. The major issue is the symbol used as a
// radix point. As of right now ZOOM_VALUE_PATTERN can be
// localized, but the call to parseDouble below is not locale-
// sensitive, and needs eventually to be replaced by something
// that is.
Matcher zoomMatcher = ZOOM_VALUE_PATTERN.matcher(userInput);
if (zoomMatcher.matches()) {
try {
double newZoom = Double.parseDouble(zoomMatcher.group(1)) / 100.0;
if (newZoom < MINIMUM_ZOOM) {
// TODO: interact with the user, indicating that the
// value is too small (see comment at top of this
// file regarding likely need for an Interaction).
newZoom = MINIMUM_ZOOM;
} else if (newZoom > MAXIMUM_ZOOM) {
// TODO: interact with the user, indicating that the
// value is too large (see comment at top of this
// file regarding likely need for an Interaction).
newZoom = MAXIMUM_ZOOM;
}
zoomable.performZoom(newZoom);
} catch (NumberFormatException e) {
throw new RcvrUIException("Number format mismatch in zoom value.");
}
} else {
// TODO: interact with the user, indicating that the value is
// not of the expected format; throw exception when
// exception architecture is "completed"
}
}
use of java.util.regex.Matcher in project crate by crate.
the class ExpressionAnalyzer method getQuotedSubscriptLiteral.
@Nullable
protected static String getQuotedSubscriptLiteral(String nodeName) {
Matcher matcher = SUBSCRIPT_SPLIT_PATTERN.matcher(nodeName);
if (matcher.matches()) {
StringBuilder quoted = new StringBuilder();
String group1 = matcher.group(1);
if (!group1.isEmpty()) {
quoted.append("\"").append(group1).append("\"");
} else {
quoted.append(group1);
}
String group2 = matcher.group(2);
String group3 = matcher.group(3);
if (!group2.isEmpty() && !group3.isEmpty()) {
quoted.append(matcher.group(2));
quoted.append("\"").append(group3).append("\"");
} else if (!group2.isEmpty() && group3.isEmpty()) {
return null;
}
quoted.append(matcher.group(4));
return quoted.toString();
} else {
return null;
}
}
use of java.util.regex.Matcher in project elasticsearch by elastic.
the class MetaDataStateFormat method findMaxStateId.
long findMaxStateId(final String prefix, Path... locations) throws IOException {
long maxId = -1;
for (Path dataLocation : locations) {
final Path resolve = dataLocation.resolve(STATE_DIR_NAME);
if (Files.exists(resolve)) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(resolve, prefix + "*")) {
for (Path stateFile : stream) {
final Matcher matcher = stateFilePattern.matcher(stateFile.getFileName().toString());
if (matcher.matches()) {
final long id = Long.parseLong(matcher.group(1));
maxId = Math.max(maxId, id);
}
}
}
}
}
return maxId;
}
Aggregations