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