aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/component/SignificanceModelRegistry.java
blob: 693eebd75a8de42d91a0a608672cf558f25e79ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.component;

import com.yahoo.config.ModelReference;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.search.significance.config.SignificanceConfig;
import com.yahoo.text.XML;
import org.w3c.dom.Element;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import static com.yahoo.vespa.model.container.xml.ModelIdResolver.SIGNIFICANCE_MODEL;

/**
 * A registry for significance models.
 *
 * @author MariusArhaug
 *
 */
public class SignificanceModelRegistry extends SimpleComponent implements SignificanceConfig.Producer {

    private static final String CLASS = "com.yahoo.language.significance.impl.DefaultSignificanceModelRegistry";
    private static final String BUNDLE = null;

    private final List<SignificanceModelConfig> configList = new ArrayList<>();

    public SignificanceModelRegistry(DeployState deployState, Element spec) {
        super(new ComponentModel(BundleInstantiationSpecification.fromStrings(CLASS, CLASS, BUNDLE)));
        if (spec != null) {

            for (Element modelElement : XML.getChildren(spec, "model")) {
                addConfig(Model.fromXml(deployState, modelElement, Set.of(SIGNIFICANCE_MODEL)).modelReference());
            }
        }
    }


    public void addConfig(ModelReference path) {
        configList.add(
                new SignificanceModelConfig(path)
        );
    }


    @Override
    public void getConfig(SignificanceConfig.Builder builder) {
        builder.model(
                configList.stream()
                .map(config -> new SignificanceConfig.Model.Builder()
                        .path(config.path)
                ).toList()
        );
    }


    static class SignificanceModelConfig {
        private final ModelReference path;

        public SignificanceModelConfig(ModelReference path) {
            this.path = path;
        }

    }
}