use of com.yahoo.searchlib.rankingexpression.parser.ParseException in project vespa by vespa-engine.
the class EvaluationTester method assertEvaluates.
public RankingExpression assertEvaluates(Value value, String expressionString, Context context, String explanation) {
try {
RankingExpression expression = new RankingExpression(expressionString);
if (!explanation.isEmpty())
explanation = explanation + ": ";
assertEquals(explanation + expression.toString(), value, expression.evaluate(context));
return expression;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
use of com.yahoo.searchlib.rankingexpression.parser.ParseException in project vespa by vespa-engine.
the class Benchmark method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: Benchmark <filename> [<iterations>]");
System.exit(1);
}
int numRuns = 1000;
if (args.length == 2) {
numRuns = Integer.valueOf(args[1]);
}
List<Result> res = new ArrayList<Result>();
try {
BufferedReader in = new BufferedReader(new FileReader(args[0]));
StringBuilder str = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
str.append(line);
}
String exp = str.toString();
res.add(evaluateTree(exp, numRuns));
res.add(evaluateTreeOptimized(exp, numRuns));
res.add(evaluateForestOptimized(exp, numRuns));
} catch (IOException e) {
System.out.println("An error occured while reading the content of file '" + args[0] + "': " + e);
System.exit(1);
} catch (ParseException e) {
System.out.println("An error occured while parsing the content of file '" + args[0] + "': " + e);
System.exit(1);
}
for (Result lhs : res) {
for (Result rhs : res) {
if (lhs.res < rhs.res - 1e-6 || lhs.res > rhs.res + 1e-6) {
System.err.println("Evaluation of '" + lhs.name + "' and '" + rhs.name + "' disagree on result; " + "expected " + lhs.res + ", got " + rhs.res + ".");
System.exit(1);
}
}
System.out.format("%1$-16s : %2$8.04f ms (%3$-6.04f)\n", lhs.name, lhs.millis, res.get(0).millis / lhs.millis);
}
}
use of com.yahoo.searchlib.rankingexpression.parser.ParseException in project vespa by vespa-engine.
the class FeatureList method parse.
/**
* Parses the content of a reader object as a list of feature nodes.
*
* @param reader A reader object that contains an feature list.
* @return A list of those features named in the string.
* @throws ParseException if the string could not be parsed.
*/
private static List<ReferenceNode> parse(Reader reader) throws ParseException {
List<ReferenceNode> lst;
try {
lst = new RankingExpressionParser(reader).featureList();
} catch (TokenMgrError e) {
ParseException t = new ParseException();
throw (ParseException) t.initCause(e);
}
List<ReferenceNode> ret = new ArrayList<ReferenceNode>(lst.size());
for (Object obj : lst) {
if (!(obj instanceof ReferenceNode)) {
throw new IllegalStateException("Feature list contains a " + obj.getClass().getName() + ".");
}
ret.add((ReferenceNode) obj);
}
return ret;
}
Aggregations