Search in sources :

Example 6 with ParseException

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);
    }
}
Also used : RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) ParseException(com.yahoo.searchlib.rankingexpression.parser.ParseException)

Example 7 with ParseException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) ParseException(com.yahoo.searchlib.rankingexpression.parser.ParseException)

Example 8 with ParseException

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;
}
Also used : ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) ArrayList(java.util.ArrayList) RankingExpressionParser(com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParser) TokenMgrError(com.yahoo.searchlib.rankingexpression.parser.TokenMgrError) ParseException(com.yahoo.searchlib.rankingexpression.parser.ParseException)

Aggregations

ParseException (com.yahoo.searchlib.rankingexpression.parser.ParseException)8 RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)6 ArrayList (java.util.ArrayList)2 ExpressionFunction (com.yahoo.searchlib.rankingexpression.ExpressionFunction)1 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)1 RankingExpressionParser (com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParser)1 TokenMgrError (com.yahoo.searchlib.rankingexpression.parser.TokenMgrError)1 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)1 TensorType (com.yahoo.tensor.TensorType)1 Rename (com.yahoo.tensor.functions.Rename)1 TensorFunction (com.yahoo.tensor.functions.TensorFunction)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1