summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/intent/model/Node.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-search/src/main/java/com/yahoo/search/intent/model/Node.java
Publish
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/intent/model/Node.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/intent/model/Node.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/intent/model/Node.java b/container-search/src/main/java/com/yahoo/search/intent/model/Node.java
new file mode 100644
index 00000000000..ecd3ec712bb
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/intent/model/Node.java
@@ -0,0 +1,48 @@
+// Copyright 2016 Yahoo Inc. 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 node in the <a href="TODO">intent model tree</a>
+ *
+ * @author <a href="mailto:bratseth@yahoo-inc.com">Jon Bratseth</a>
+ */
+public abstract class Node implements Comparable<Node> {
+
+ /**
+ * The score, unless getScore/setScore is overridden which is the case with interpretations,
+ * so DO NOT ACCESS SCORE DIRECTLY, ALWAYS USE GET/SET
+ */
+ private double score;
+
+ public Node(double score) {
+ this.score=score;
+ }
+
+ /** Returns the normalized (0-1) score of this node */
+ public double getScore() { return score; }
+
+ /** Sets the normalized (0-1) score of this node */
+ public void setScore(double score) { this.score=score; }
+
+ /** Increases this score by an increment and returns the new score */
+ public double increaseScore(double increment) {
+ setScore(getScore()+increment);
+ return getScore();
+ }
+
+ public int compareTo(Node other) {
+ if (this.getScore()<other.getScore()) return 1;
+ if (this.getScore()>other.getScore()) return -1;
+ return 0;
+ }
+
+ /**
+ * Adds the sources at (and beneath) this node to the given
+ * sparsely represented source vector, weighted by the score of this node
+ * times the given weight from the parent path
+ */
+ abstract void addSources(double weight,Map<Source,SourceNode> sources);
+
+}