use of edu.stanford.nlp.io.NumberRangesFileFilter in project CoreNLP by stanfordnlp.
the class ArgUtils method getWeightedTreebankDescription.
public static Triple<String, FileFilter, Double> getWeightedTreebankDescription(String[] args, int argIndex, String flag) {
String path = null;
FileFilter filter = null;
Double weight = 1.0;
// the next arguments are the treebank path and maybe the range for testing
int numSubArgs = numSubArgs(args, argIndex);
if (numSubArgs > 0 && numSubArgs < 4) {
argIndex++;
path = args[argIndex++];
boolean hasWeight = false;
if (numSubArgs > 1 && DOUBLE_PATTERN.matcher(args[argIndex + numSubArgs - 2]).matches()) {
weight = Double.parseDouble(args[argIndex + numSubArgs - 2]);
hasWeight = true;
numSubArgs--;
}
if (numSubArgs == 2) {
filter = new NumberRangesFileFilter(args[argIndex++], true);
} else if (numSubArgs == 3) {
try {
int low = Integer.parseInt(args[argIndex]);
int high = Integer.parseInt(args[argIndex + 1]);
filter = new NumberRangeFileFilter(low, high, true);
argIndex += 2;
} catch (NumberFormatException e) {
// maybe it's a ranges expression?
filter = new NumberRangesFileFilter(args[argIndex++], true);
}
}
if (hasWeight) {
argIndex++;
}
} else {
throw new IllegalArgumentException("Bad arguments after " + flag);
}
return Triple.makeTriple(path, filter, weight);
}
Aggregations