diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-09-10 08:47:00 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-09-10 08:47:00 +0200 |
commit | 48f9a4071b5f6f75114cd1b94eb09bec36f77061 (patch) | |
tree | 4fe427fe2f1aab3f93c476b58e2b743d5543f73b /model-evaluation/src/main | |
parent | 68708408abd1d47bb8f5e5a1d80855739b717c2f (diff) |
Revert "Merge pull request #6859 from vespa-engine/revert-6855-bratseth/test-with-constants"
This reverts commit 68708408abd1d47bb8f5e5a1d80855739b717c2f, reversing
changes made to 56591420e8cb8c6a9085d7327b977c3c5b1971b1.
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 | 28 |
2 files changed, 10 insertions, 26 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..00f60654318 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 @@ -1,15 +1,11 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.models.evaluation; -import com.yahoo.filedistribution.fileacquirer.FileAcquirer; import com.yahoo.io.GrowableByteBuffer; import com.yahoo.io.IOUtils; import com.yahoo.searchlib.rankingexpression.ExpressionFunction; import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.rankingexpression.parser.ParseException; -import com.yahoo.searchlib.rankingexpression.rule.CompositeNode; -import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode; -import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.serialization.TypedBinaryFormat; @@ -21,8 +17,6 @@ import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,15 +29,13 @@ import java.util.logging.Logger; * * @author bratseth */ -class RankProfilesConfigImporter { - - private static final Logger log = Logger.getLogger("CONSTANTS"); +public 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 +112,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")) |