Search in sources :

Example 6 with Value

use of com.yahoo.searchlib.rankingexpression.evaluation.Value in project vespa by vespa-engine.

the class Simplifier method transform.

private void transform(ArithmeticOperator operator, List<ExpressionNode> children, List<ArithmeticOperator> operators) {
    int i = 0;
    while (i < children.size() - 1) {
        if (!operators.get(i).equals(operator)) {
            i++;
            continue;
        }
        ExpressionNode child1 = children.get(i);
        ExpressionNode child2 = children.get(i + 1);
        if (isConstant(child1) && isConstant(child2) && hasPrecedence(operators, i)) {
            Value evaluated = new ArithmeticNode(child1, operators.remove(i), child2).evaluate(null);
            children.set(i, new ConstantNode(evaluated.freeze()));
            children.remove(i + 1);
        } else {
            // try the next index
            i++;
        }
    }
}
Also used : ArithmeticNode(com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode) ConstantNode(com.yahoo.searchlib.rankingexpression.rule.ConstantNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) Value(com.yahoo.searchlib.rankingexpression.evaluation.Value)

Example 7 with Value

use of com.yahoo.searchlib.rankingexpression.evaluation.Value in project vespa by vespa-engine.

the class ComparisonNode method evaluate.

@Override
public Value evaluate(Context context) {
    Value leftValue = leftCondition.evaluate(context);
    Value rightValue = rightCondition.evaluate(context);
    return leftValue.compare(operator, rightValue);
}
Also used : Value(com.yahoo.searchlib.rankingexpression.evaluation.Value)

Example 8 with Value

use of com.yahoo.searchlib.rankingexpression.evaluation.Value in project vespa by vespa-engine.

the class FunctionNode method evaluate.

@Override
public Value evaluate(Context context) {
    if (arguments.expressions().size() == 0)
        return DoubleValue.zero.function(function, DoubleValue.zero);
    Value argument1 = arguments.expressions().get(0).evaluate(context);
    if (arguments.expressions().size() == 1)
        return argument1.function(function, DoubleValue.zero);
    Value argument2 = arguments.expressions().get(1).evaluate(context);
    return argument1.function(function, argument2);
}
Also used : DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) Value(com.yahoo.searchlib.rankingexpression.evaluation.Value)

Example 9 with Value

use of com.yahoo.searchlib.rankingexpression.evaluation.Value in project vespa by vespa-engine.

the class ElementCompleteness method compute.

/**
 * Computes the following elementCompleteness features:
 * <ul>
 *     <li><code>completeness</code>
 *     <li><code>fieldCompleteness</code>
 *     <li><code>queryCompleteness</code>
 *     <li><code>elementWeight</code>
 * </ul>
 *
 * @param queryTerms the query terms with associated weights to compute over
 * @param field a set of weighted field values, where each is taken to be a space-separated string of tokens
 * @return a features object containing the values listed above
 */
public static Features compute(Map<String, Integer> queryTerms, Item[] field) {
    double completeness = 0;
    double fieldCompleteness = 0;
    double queryCompleteness = 0;
    double elementWeight = 0;
    double queryTermWeightSum = sum(queryTerms.values());
    for (Item item : field) {
        String[] itemTokens = item.value().split(" ");
        int matchCount = 0;
        int matchWeightSum = 0;
        for (String token : itemTokens) {
            Integer weight = queryTerms.get(token);
            if (weight == null)
                continue;
            matchCount++;
            matchWeightSum += weight;
        }
        double itemFieldCompleteness = (double) matchCount / itemTokens.length;
        double itemQueryCompleteness = matchWeightSum / queryTermWeightSum;
        double itemCompleteness = fieldCompletenessImportance * itemFieldCompleteness + (1 - fieldCompletenessImportance) * itemQueryCompleteness;
        if (itemCompleteness > completeness) {
            completeness = itemCompleteness;
            fieldCompleteness = itemFieldCompleteness;
            queryCompleteness = itemQueryCompleteness;
            elementWeight = item.weight();
        }
    }
    Map<String, Value> features = new HashMap<>();
    features.put("completeness", new DoubleValue(completeness));
    features.put("fieldCompleteness", new DoubleValue(fieldCompleteness));
    features.put("queryCompleteness", new DoubleValue(queryCompleteness));
    features.put("elementWeight", new DoubleValue(elementWeight));
    return new Features(features);
}
Also used : HashMap(java.util.HashMap) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) Value(com.yahoo.searchlib.rankingexpression.evaluation.Value)

Aggregations

Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)9 DoubleValue (com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue)4 HashMap (java.util.HashMap)3 TensorValue (com.yahoo.searchlib.rankingexpression.evaluation.TensorValue)2 RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)1 ArithmeticNode (com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode)1 ConstantNode (com.yahoo.searchlib.rankingexpression.rule.ConstantNode)1 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)1 NameNode (com.yahoo.searchlib.rankingexpression.rule.NameNode)1 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)1 Tensor (com.yahoo.tensor.Tensor)1 Test (org.junit.Test)1