diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-09-07 15:31:02 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-09-07 15:31:02 +0200 |
commit | 8f38e82a52561c4d6088f381f3c115c2b2976d60 (patch) | |
tree | f520e15c0027730e4d60cc0205796bcd721b27a1 /model-evaluation/src/main | |
parent | 83fec633592486ef694856ece90eb76469a2a5f6 (diff) |
Test with constants
Diffstat (limited to 'model-evaluation/src/main')
-rw-r--r-- | model-evaluation/src/main/java/ai/vespa/models/evaluation/ModelsEvaluator.java | 8 | ||||
-rw-r--r-- | model-evaluation/src/main/java/ai/vespa/models/evaluation/RankProfilesConfigImporter.java | 20 |
2 files changed, 10 insertions, 18 deletions
diff --git a/model-evaluation/src/main/java/ai/vespa/models/evaluation/ModelsEvaluator.java b/model-evaluation/src/main/java/ai/vespa/models/evaluation/ModelsEvaluator.java index 48c71b5a04a..b507c5d7f08 100644 --- a/model-evaluation/src/main/java/ai/vespa/models/evaluation/ModelsEvaluator.java +++ b/model-evaluation/src/main/java/ai/vespa/models/evaluation/ModelsEvaluator.java @@ -3,6 +3,7 @@ package ai.vespa.models.evaluation; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableMap; +import com.google.inject.Inject; import com.yahoo.component.AbstractComponent; import com.yahoo.vespa.config.search.RankProfilesConfig; import com.yahoo.vespa.config.search.core.RankingConstantsConfig; @@ -22,8 +23,13 @@ public class ModelsEvaluator extends AbstractComponent { private final ImmutableMap<String, Model> models; + @Inject public ModelsEvaluator(RankProfilesConfig config, RankingConstantsConfig constantsConfig) { - models = ImmutableMap.copyOf(new RankProfilesConfigImporter().importFrom(config, constantsConfig)); + this(new RankProfilesConfigImporter().importFrom(config, constantsConfig)); + } + + public ModelsEvaluator(Map<String, Model> models) { + this.models = ImmutableMap.copyOf(models); } /** Returns the models of this as an immutable map */ diff --git a/model-evaluation/src/main/java/ai/vespa/models/evaluation/RankProfilesConfigImporter.java b/model-evaluation/src/main/java/ai/vespa/models/evaluation/RankProfilesConfigImporter.java index cd21a0a6813..98634e184bf 100644 --- a/model-evaluation/src/main/java/ai/vespa/models/evaluation/RankProfilesConfigImporter.java +++ b/model-evaluation/src/main/java/ai/vespa/models/evaluation/RankProfilesConfigImporter.java @@ -35,7 +35,7 @@ import java.util.logging.Logger; * * @author bratseth */ -class RankProfilesConfigImporter { +public class RankProfilesConfigImporter { private static final Logger log = Logger.getLogger("CONSTANTS"); @@ -43,7 +43,7 @@ class RankProfilesConfigImporter { * Returns a map of the models contained in this config, indexed on name. * The map is modifiable and owned by the caller. */ - Map<String, Model> importFrom(RankProfilesConfig config, RankingConstantsConfig constantsConfig) { + public Map<String, Model> importFrom(RankProfilesConfig config, RankingConstantsConfig constantsConfig) { try { Map<String, Model> models = new HashMap<>(); for (RankProfilesConfig.Rankprofile profile : config.rankprofile()) { @@ -120,23 +120,9 @@ class RankProfilesConfigImporter { return constants; } - Tensor readTensorFromFile(String name, TensorType type, String fileReference) { + protected Tensor readTensorFromFile(String name, TensorType type, String fileReference) { try { - // TODO: Only allow these two fallbacks in testing mode - if (fileReference.isEmpty()) { // this may be the case in unit tests - log.warning("Got empty file reference for constant '" + name + "', using an empty tensor"); - return Tensor.from(type, "{}"); - } File dir = new File(Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution"), fileReference); - if ( ! dir.exists()) { // this may be the case in unit tests - log.warning("Got reference to nonexisting file " + dir + "e for constant '" + name + - "', using an empty tensor"); - return Tensor.from(type, "{}"); - } - - // TODO: Move these 2 lines to FileReference - - dir = new File(Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution"), fileReference); File file = dir.listFiles()[0]; // directory contains one file having the original name if (file.getName().endsWith(".tbf")) |