From a6d524a04c36132e848454f7b60585fd3aed7da1 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 12 Jun 2023 10:50:59 +0200 Subject: Delete unused class --- .../yahoo/vespa/model/container/search/QrsCache.java | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 config-model/src/main/java/com/yahoo/vespa/model/container/search/QrsCache.java (limited to 'config-model') diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/QrsCache.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/QrsCache.java deleted file mode 100644 index 64b3e67b616..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/QrsCache.java +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.model.container.search; - -/** - * A helper class to wrap a set of QRS cache settings. - * - * @author Steinar Knutsen - */ -public class QrsCache { - - public final Integer size; - - public QrsCache(Integer size) { - this.size = size; - } - -} -- cgit v1.2.3 From 06213d2c019d05bcbe6ee7d2b4c3e82f8425961c Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 12 Jun 2023 10:57:46 +0200 Subject: Move builder into SemanticRules --- .../com/yahoo/config/model/deploy/DeployState.java | 4 +- .../model/container/search/PageTemplates.java | 5 +- .../search/RankProfilesEvaluatorComponent.java | 1 - .../container/search/SemanticRuleBuilder.java | 87 ---------------------- .../model/container/search/SemanticRules.java | 75 +++++++++++++++++++ .../model/container/search/SemanticRulesTest.java | 1 + 6 files changed, 79 insertions(+), 94 deletions(-) delete mode 100644 config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRuleBuilder.java (limited to 'config-model') diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java index b8d63ba3778..4df7a76031a 100644 --- a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java +++ b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java @@ -24,7 +24,6 @@ import com.yahoo.config.model.api.ValidationParameters; import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.model.provision.HostsXmlProvisioner; -import com.yahoo.config.model.provision.InMemoryProvisioner; import com.yahoo.config.model.provision.SingleNodeProvisioner; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.DockerImage; @@ -41,7 +40,6 @@ import com.yahoo.vespa.config.ConfigDefinitionKey; import com.yahoo.vespa.documentmodel.DocumentModel; import com.yahoo.vespa.model.container.search.QueryProfiles; import com.yahoo.vespa.model.container.search.QueryProfilesBuilder; -import com.yahoo.vespa.model.container.search.SemanticRuleBuilder; import com.yahoo.vespa.model.container.search.SemanticRules; import java.io.File; @@ -60,6 +58,8 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutorService; +import static com.yahoo.vespa.model.container.search.SemanticRules.SemanticRuleBuilder; + /** * Contains various state during deploy that should be available in all builders of a {@link com.yahoo.config.model.ConfigModel} * diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/PageTemplates.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/PageTemplates.java index dc9a9f127ed..d186008b998 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/PageTemplates.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/PageTemplates.java @@ -20,11 +20,8 @@ import java.util.List; */ public class PageTemplates implements Serializable, PageTemplatesConfig.Producer { - private List pages = new ArrayList<>(); + private final List pages = new ArrayList<>(); - /** The number of pages in this, for reporting */ - //private int pages=0; - /** Validates page templates in an application package. The passed readers will be closed. */ public static void validate(ApplicationPackage applicationPackage) { List pageTemplateFiles=null; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/RankProfilesEvaluatorComponent.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/RankProfilesEvaluatorComponent.java index 75a2802ee53..47ed2ea99f7 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/RankProfilesEvaluatorComponent.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/RankProfilesEvaluatorComponent.java @@ -8,7 +8,6 @@ import com.yahoo.vespa.config.search.RankProfilesConfig; import com.yahoo.vespa.config.search.core.OnnxModelsConfig; import com.yahoo.vespa.config.search.core.RankingConstantsConfig; import com.yahoo.vespa.config.search.core.RankingExpressionsConfig; -import com.yahoo.vespa.model.container.ContainerModelEvaluation; import com.yahoo.vespa.model.container.PlatformBundles; import com.yahoo.vespa.model.container.component.Component; import com.yahoo.vespa.model.search.DocumentDatabase; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRuleBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRuleBuilder.java deleted file mode 100644 index 4923c41224e..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRuleBuilder.java +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.model.container.search; - -import com.yahoo.config.application.api.ApplicationPackage; -import com.yahoo.io.IOUtils; -import com.yahoo.io.reader.NamedReader; -import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.prelude.semantics.RuleBase; -import com.yahoo.prelude.semantics.RuleImporter; -import com.yahoo.prelude.semantics.SemanticRulesConfig; -import com.yahoo.prelude.semantics.parser.ParseException; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Reads the semantic rules from the application package by delegating to SemanticRules. - * - * @author bratseth - */ -// TODO: Move into SemanticRules -public class SemanticRuleBuilder { - - /** Builds the semantic rules for an application package and validates them */ - public SemanticRules build(ApplicationPackage applicationPackage) { - var ruleFiles = applicationPackage.getFiles(ApplicationPackage.RULES_DIR, "sr"); - var rules = new SemanticRules(ruleFiles.stream().map(this::toRuleBaseConfigView).toList()); - - // Create config to make sure rules are valid, config is validated in call to toMap() below - var builder = new SemanticRulesConfig.Builder(); - rules.getConfig(builder); - SemanticRulesConfig config = builder.build(); - try { - toMap(config); // validates config - ensureZeroOrOneDefaultRule(config); - } catch (ParseException | IOException e) { - throw new RuntimeException(e); - } - return rules; - } - - private SemanticRules.RuleBase toRuleBaseConfigView(NamedReader reader) { - try { - String ruleBaseString = IOUtils.readAll(reader.getReader()); - boolean isDefault = ruleBaseString.contains("@default"); - return new SemanticRules.RuleBase(toName(reader.getName()), isDefault, ruleBaseString); - } - catch (IOException e) { - throw new IllegalArgumentException("Could not load rules bases", e); - } - } - - private String toName(String fileName) { - String shortName = new File(fileName).getName(); - return shortName.substring(0, shortName.length() - ".sr".length()); - } - - private void ensureZeroOrOneDefaultRule(SemanticRulesConfig config) { - String defaultName = null; - for (SemanticRulesConfig.Rulebase ruleBase : config.rulebase()) { - if (defaultName != null && ruleBase.isdefault()) { - List defaultRules = new ArrayList<>(List.of(defaultName, ruleBase.name())); - defaultRules.sort(String::compareTo); - throw new IllegalArgumentException("Rules " + defaultRules + " are both marked as the default rule, there can only be one"); - } - if (ruleBase.isdefault()) - defaultName = ruleBase.name(); - } - } - - static Map toMap(SemanticRulesConfig config) throws ParseException, IOException { - RuleImporter ruleImporter = new RuleImporter(config, true, new SimpleLinguistics()); - Map ruleBaseMap = new HashMap<>(); - for (SemanticRulesConfig.Rulebase ruleBaseConfig : config.rulebase()) { - RuleBase ruleBase = ruleImporter.importConfig(ruleBaseConfig); - if (ruleBaseConfig.isdefault()) - ruleBase.setDefault(true); - ruleBaseMap.put(ruleBase.getName(), ruleBase); - } - return ruleBaseMap; - } - -} diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRules.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRules.java index 0083fc6b886..a77c2c98380 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRules.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/SemanticRules.java @@ -1,9 +1,21 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.container.search; +import com.yahoo.config.application.api.ApplicationPackage; +import com.yahoo.io.IOUtils; +import com.yahoo.io.reader.NamedReader; +import com.yahoo.language.simple.SimpleLinguistics; +import com.yahoo.prelude.semantics.RuleImporter; import com.yahoo.prelude.semantics.SemanticRulesConfig; +import com.yahoo.prelude.semantics.parser.ParseException; + +import java.io.File; +import java.io.IOException; import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Returns the semantic rules config from a set of rule bases. @@ -48,4 +60,67 @@ public class SemanticRules implements Serializable, SemanticRulesConfig.Producer } + public static class SemanticRuleBuilder { + + /** Builds the semantic rules for an application package and validates them */ + public SemanticRules build(ApplicationPackage applicationPackage) { + var ruleFiles = applicationPackage.getFiles(ApplicationPackage.RULES_DIR, "sr"); + var rules = new SemanticRules(ruleFiles.stream().map(this::toRuleBaseConfigView).toList()); + + // Create config to make sure rules are valid, config is validated in call to toMap() below + var builder = new SemanticRulesConfig.Builder(); + rules.getConfig(builder); + SemanticRulesConfig config = builder.build(); + try { + toMap(config); // validates config + ensureZeroOrOneDefaultRule(config); + } catch (ParseException | IOException e) { + throw new RuntimeException(e); + } + return rules; + } + + private RuleBase toRuleBaseConfigView(NamedReader reader) { + try { + String ruleBaseString = IOUtils.readAll(reader.getReader()); + boolean isDefault = ruleBaseString.contains("@default"); + return new RuleBase(toName(reader.getName()), isDefault, ruleBaseString); + } + catch (IOException e) { + throw new IllegalArgumentException("Could not load rules bases", e); + } + } + + private String toName(String fileName) { + String shortName = new File(fileName).getName(); + return shortName.substring(0, shortName.length() - ".sr".length()); + } + + private void ensureZeroOrOneDefaultRule(SemanticRulesConfig config) { + String defaultName = null; + for (SemanticRulesConfig.Rulebase ruleBase : config.rulebase()) { + if (defaultName != null && ruleBase.isdefault()) { + List defaultRules = new ArrayList<>(List.of(defaultName, ruleBase.name())); + defaultRules.sort(String::compareTo); + throw new IllegalArgumentException("Rules " + defaultRules + " are both marked as the default rule, there can only be one"); + } + if (ruleBase.isdefault()) + defaultName = ruleBase.name(); + } + } + + static Map toMap(SemanticRulesConfig config) throws ParseException, IOException { + RuleImporter ruleImporter = new RuleImporter(config, true, new SimpleLinguistics()); + Map ruleBaseMap = new HashMap<>(); + for (SemanticRulesConfig.Rulebase ruleBaseConfig : config.rulebase()) { + com.yahoo.prelude.semantics.RuleBase ruleBase = ruleImporter.importConfig(ruleBaseConfig); + if (ruleBaseConfig.isdefault()) + ruleBase.setDefault(true); + ruleBaseMap.put(ruleBase.getName(), ruleBase); + } + return ruleBaseMap; + } + + } + } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/search/SemanticRulesTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/search/SemanticRulesTest.java index da6e055724a..544acc81b8d 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/search/SemanticRulesTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/search/SemanticRulesTest.java @@ -11,6 +11,7 @@ import java.io.File; import java.io.IOException; import java.util.Map; +import static com.yahoo.vespa.model.container.search.SemanticRules.SemanticRuleBuilder; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -- cgit v1.2.3