Search in sources :

Example 1 with NameNode

use of com.yahoo.searchlib.rankingexpression.rule.NameNode in project vespa by vespa-engine.

the class ConstantTensorTransformer method transformConstantReference.

private ExpressionNode transformConstantReference(ReferenceNode node, RankProfileTransformContext context) {
    Value value = context.constants().get(node.getName());
    if (value == null || value.type().rank() == 0) {
        return node;
    }
    TensorValue tensorValue = (TensorValue) value;
    String featureName = CONSTANT + "(" + node.getName() + ")";
    String tensorType = tensorValue.asTensor().type().toString();
    context.rankPropertiesOutput().put(featureName + ".value", tensorValue.toString());
    context.rankPropertiesOutput().put(featureName + ".type", tensorType);
    // TODO: This allows us to reference constant "a" as "a" instead of "constant(a)", but we shouldn't allow that
    return new ReferenceNode(CONSTANT, Arrays.asList(new NameNode(node.getName())), null);
}
Also used : TensorValue(com.yahoo.searchlib.rankingexpression.evaluation.TensorValue) NameNode(com.yahoo.searchlib.rankingexpression.rule.NameNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) TensorValue(com.yahoo.searchlib.rankingexpression.evaluation.TensorValue) Value(com.yahoo.searchlib.rankingexpression.evaluation.Value)

Example 2 with NameNode

use of com.yahoo.searchlib.rankingexpression.rule.NameNode in project vespa by vespa-engine.

the class ReferenceTestCase method testToString.

@Test
public void testToString() {
    assertEquals("foo(arg_1)", new Reference("foo", new Arguments(new ReferenceNode("arg_1")), null).toString());
    assertEquals("foo(arg_1).out", new Reference("foo", new Arguments(new ReferenceNode("arg_1")), "out").toString());
    assertEquals("foo(arg_1).out", new Reference("foo", new Arguments(new NameNode("arg_1")), "out").toString());
    assertEquals("foo", new Reference("foo", new Arguments(), null).toString());
}
Also used : NameNode(com.yahoo.searchlib.rankingexpression.rule.NameNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) Arguments(com.yahoo.searchlib.rankingexpression.rule.Arguments) Test(org.junit.Test)

Example 3 with NameNode

use of com.yahoo.searchlib.rankingexpression.rule.NameNode in project vespa by vespa-engine.

the class MapEvaluationTypeContext method tensorFeatureType.

/**
 * There are two features which returns the (non-empty) tensor type: tensorFromLabels and tensorFromWeightedSet.
 * This returns the type of those features if this is a reference to either of them, or empty otherwise.
 */
private Optional<TensorType> tensorFeatureType(Reference reference) {
    if (!reference.name().equals("tensorFromLabels") && !reference.name().equals("tensorFromWeightedSet"))
        return Optional.empty();
    if (reference.arguments().size() != 1 && reference.arguments().size() != 2)
        throw new IllegalArgumentException(reference.name() + " must have one or two arguments");
    ExpressionNode arg0 = reference.arguments().expressions().get(0);
    if (!(arg0 instanceof ReferenceNode) || !FeatureNames.isSimpleFeature(((ReferenceNode) arg0).reference()))
        throw new IllegalArgumentException("The first argument of " + reference.name() + " must be a simple feature, not " + arg0);
    String dimension;
    if (reference.arguments().size() > 1) {
        ExpressionNode arg1 = reference.arguments().expressions().get(1);
        if ((!(arg1 instanceof ReferenceNode) || !(((ReferenceNode) arg1).reference().isIdentifier())) && (!(arg1 instanceof NameNode)))
            throw new IllegalArgumentException("The second argument of " + reference.name() + " must be a dimension name, not " + arg1);
        dimension = reference.arguments().expressions().get(1).toString();
    } else {
        // default
        dimension = ((ReferenceNode) arg0).reference().arguments().expressions().get(0).toString();
    }
    return Optional.of(new TensorType.Builder().mapped(dimension).build());
}
Also used : NameNode(com.yahoo.searchlib.rankingexpression.rule.NameNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) TensorType(com.yahoo.tensor.TensorType)

Example 4 with NameNode

use of com.yahoo.searchlib.rankingexpression.rule.NameNode in project vespa by vespa-engine.

the class ReferenceTestCase method testSimple.

@Test
public void testSimple() {
    assertTrue(new Reference("foo", new Arguments(new ReferenceNode("arg")), null).isSimple());
    assertTrue(new Reference("foo", new Arguments(new ReferenceNode("arg")), "out").isSimple());
    assertTrue(new Reference("foo", new Arguments(new NameNode("arg")), "out").isSimple());
    assertFalse(new Reference("foo", new Arguments(), null).isSimple());
}
Also used : NameNode(com.yahoo.searchlib.rankingexpression.rule.NameNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) Arguments(com.yahoo.searchlib.rankingexpression.rule.Arguments) Test(org.junit.Test)

Aggregations

NameNode (com.yahoo.searchlib.rankingexpression.rule.NameNode)4 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)4 Arguments (com.yahoo.searchlib.rankingexpression.rule.Arguments)2 Test (org.junit.Test)2 TensorValue (com.yahoo.searchlib.rankingexpression.evaluation.TensorValue)1 Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)1 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)1 TensorType (com.yahoo.tensor.TensorType)1