aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/intent/model/SourceNode.java
blob: 720912e899b7a3c7f022bc3fbccac1e1bbe5d735 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.intent.model;

import java.util.Map;

/**
 * A source node in an intent model tree. Represents a source with an appropriateness score
 * (i.e the score of a source node is called <i>appropriateness</i>).
 * Sources are ordered by decreasing appropriateness.
 *
 * @author bratseth
 */
public class SourceNode extends Node {

    private Source source;

    public SourceNode(Source source,double score) {
        super(score);
        this.source=source;
    }

    /** Sets the source of this node */
    public void setSource(Source source) { this.source=source; }

    /** Returns the source of this node */
    public Source getSource() { return source; }

    @Override void addSources(double weight,Map<Source,SourceNode> sources) {
        SourceNode existing=sources.get(source);
        if (existing!=null)
            existing.increaseScore(weight*getScore());
        else
            sources.put(source,new SourceNode(source,weight*getScore()));
    }

    /** Returns source:appropriateness */
    @Override
    public String toString() {
        return source + ":" + getScore();
    }

}