diff options
3 files changed, 37 insertions, 36 deletions
diff --git a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/operations/IntermediateOperation.java b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/operations/IntermediateOperation.java index 6378442c6d0..e49ab274b5a 100644 --- a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/operations/IntermediateOperation.java +++ b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/operations/IntermediateOperation.java @@ -280,13 +280,13 @@ public abstract class IntermediateOperation { public void insert(IntermediateOperation operationToInsert, int inputNumber) { if ( operationToInsert.inputs.size() > 0 ) { throw new IllegalArgumentException("Operation to insert to '" + name + "' has " + - "existing inputs which is not supported."); + "existing inputs which is not supported."); } IntermediateOperation previousInputOperation = inputs.get(inputNumber); int outputNumber = findOutputNumber(previousInputOperation, this); if (outputNumber == -1) { throw new IllegalArgumentException("Input '" + previousInputOperation.name + "' to '" + - name + "' does not have '" + name + "' as output."); + name + "' does not have '" + name + "' as output."); } previousInputOperation.outputs.set(outputNumber, operationToInsert); operationToInsert.inputs.add(previousInputOperation); diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java index 33d1def4696..391f8ecc773 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java @@ -33,12 +33,6 @@ public class Reference extends Name implements Comparable<Reference> { private final static Pattern identifierPattern = Pattern.compile("[A-Za-z0-9_@.\"-$]+"); - public static Reference fromIdentifier(String identifier) { - if ( ! identifierPattern.matcher(identifier).matches()) - throw new IllegalArgumentException("Identifiers can only contain [A-Za-z0-9_@.\"-$]+, but was '" + identifier + "'"); - return new Reference(identifier, Arguments.EMPTY, null, true); - } - public Reference(String name, Arguments arguments, String output) { this(name, arguments, output, false); } @@ -57,32 +51,6 @@ public class Reference extends Name implements Comparable<Reference> { public String output() { return output; } - /** - * Creates a reference to a simple feature consisting of a name and a single argument - */ - public static Reference simple(String name, String argumentValue) { - return new Reference(name, new Arguments(new ReferenceNode(argumentValue)), null); - } - - /** - * Returns the given simple feature as a reference, or empty if it is not a valid simple - * feature string on the form name(argument). - */ - public static Optional<Reference> simple(String feature) { - int startParenthesis = feature.indexOf('('); - if (startParenthesis < 0) - return Optional.empty(); - int endParenthesis = feature.lastIndexOf(')'); - String featureName = feature.substring(0, startParenthesis); - if (startParenthesis < 1 || endParenthesis < startParenthesis) return Optional.empty(); - String argument = feature.substring(startParenthesis + 1, endParenthesis); - if (argument.startsWith("'") || argument.startsWith("\"")) - argument = argument.substring(1); - if (argument.endsWith("'") || argument.endsWith("\"")) - argument = argument.substring(0, argument.length() - 1); - return Optional.of(simple(featureName, argument)); - } - /** Returns true if this was created by fromIdentifier. Identifiers have no arguments or outputs. */ public boolean isIdentifier() { return isIdentifier; } @@ -172,4 +140,37 @@ public class Reference extends Name implements Comparable<Reference> { return this.toString().compareTo(o.toString()); } + /** Creates a reference from a simple identifier. */ + public static Reference fromIdentifier(String identifier) { + if ( ! identifierPattern.matcher(identifier).matches()) + throw new IllegalArgumentException("Identifiers can only contain [A-Za-z0-9_@.\"-$]+, but was '" + identifier + "'"); + return new Reference(identifier, Arguments.EMPTY, null, true); + } + + /** + * Creates a reference to a simple feature consisting of a name and a single argument + */ + public static Reference simple(String name, String argumentValue) { + return new Reference(name, new Arguments(new ReferenceNode(argumentValue)), null); + } + + /** + * Returns the given simple feature as a reference, or empty if it is not a valid simple + * feature string on the form name(argument). + */ + public static Optional<Reference> simple(String feature) { + int startParenthesis = feature.indexOf('('); + if (startParenthesis < 0) + return Optional.empty(); + int endParenthesis = feature.lastIndexOf(')'); + String featureName = feature.substring(0, startParenthesis); + if (startParenthesis < 1 || endParenthesis < startParenthesis) return Optional.empty(); + String argument = feature.substring(startParenthesis + 1, endParenthesis); + if (argument.startsWith("'") || argument.startsWith("\"")) + argument = argument.substring(1); + if (argument.endsWith("'") || argument.endsWith("\"")) + argument = argument.substring(0, argument.length() - 1); + return Optional.of(simple(featureName, argument)); + } + } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java index aa6a6df0960..85a12a49958 100755 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java @@ -23,9 +23,9 @@ public final class ReferenceNode extends CompositeNode { private final Reference reference; - /* Creates a node with a simple identifier reference */ + /* Parses this string into a reference */ public ReferenceNode(String name) { - this.reference = Reference.fromIdentifier(name); + this.reference = Reference.simple(name).orElseGet(() -> Reference.fromIdentifier(name)); } public ReferenceNode(String name, List<? extends ExpressionNode> arguments, String output) { |