summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-12-17 11:42:21 +0100
committerJon Bratseth <bratseth@verizonmedia.com>2019-12-17 11:42:21 +0100
commit3a84c90423e86bb95c9a620c1c9ccc1a055b2d37 (patch)
treebd7ffc5edc8b4f7216a2403e86001755efaf953f /vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
parentcbcd468e0f19421876a52ba1bd74f33fda73b855 (diff)
Allow quoted labels in tensors
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/TensorType.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorType.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
index ca3f8ff28a4..58cb151875e 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
@@ -2,9 +2,9 @@
package com.yahoo.tensor;
import com.google.common.collect.ImmutableList;
+import com.yahoo.text.Ascii7BitMatcher;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -15,6 +15,8 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
+import static com.yahoo.text.Ascii7BitMatcher.charsAndNumbers;
+
/**
* A tensor type with its dimensions. This is immutable.
* <p>
@@ -25,6 +27,8 @@ import java.util.stream.Collectors;
*/
public class TensorType {
+ static Ascii7BitMatcher labelMatcher = new Ascii7BitMatcher("-_@" + charsAndNumbers(), "_@$" + charsAndNumbers());
+
/** The permissible cell value types. Default is double. */
public enum Value {
@@ -292,8 +296,7 @@ public class TensorType {
private final String name;
private Dimension(String name) {
- Objects.requireNonNull(name, "A tensor name cannot be null");
- this.name = name;
+ this.name = requireIdentifier(name);
}
public final String name() { return name; }
@@ -361,6 +364,14 @@ public class TensorType {
return new MappedDimension(name);
}
+ static private String requireIdentifier(String name) {
+ if (name == null)
+ throw new IllegalArgumentException("A dimension name cannot be null");
+ if ( ! TensorType.labelMatcher.matches(name))
+ throw new IllegalArgumentException("A dimension name must be an identifier or integer, not '" + name + "'");
+ return name;
+ }
+
}
public static class IndexedBoundDimension extends TensorType.Dimension {