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++;
}
}
}
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);
}
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);
}
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);
}
Aggregations