summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-02-21 14:41:50 +0100
committerJon Bratseth <bratseth@gmail.com>2021-02-21 14:41:50 +0100
commite5852de9c3fcfd5714aa20512014e1524338c844 (patch)
tree9b09189f6258bec37174ea90b0ef97930232d014 /container-search
parentafe876252b56b5a30735865047d7392958835f6a (diff)
Non-functional changes only
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/ItemHelper.java6
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/SegmentingRule.java5
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/SuffixItem.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/statistics/TimingSearcher.java6
-rw-r--r--container-search/src/main/java/com/yahoo/search/yql/NullItemException.java5
-rw-r--r--container-search/src/main/java/com/yahoo/text/interpretation/Annotations.java15
-rw-r--r--container-search/src/main/java/com/yahoo/text/interpretation/Interpretation.java50
-rw-r--r--container-search/src/main/java/com/yahoo/text/interpretation/Modification.java13
-rw-r--r--container-search/src/main/java/com/yahoo/text/interpretation/Span.java45
-rw-r--r--container-search/src/main/java/com/yahoo/vespa/streamingvisitors/Visitor.java2
-rw-r--r--container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VisitorFactory.java2
11 files changed, 61 insertions, 91 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/ItemHelper.java b/container-search/src/main/java/com/yahoo/prelude/query/ItemHelper.java
index b535ae7b8bd..cbdaa04a49f 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/ItemHelper.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/ItemHelper.java
@@ -5,8 +5,9 @@ import java.util.Iterator;
import java.util.List;
/**
- * Helper function for Item
- * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a>
+ * Helper functions for Item
+ *
+ * @author Arne Bergene Fossaa
*/
public class ItemHelper {
@@ -77,5 +78,4 @@ public class ItemHelper {
}
}
-
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/SegmentingRule.java b/container-search/src/main/java/com/yahoo/prelude/query/SegmentingRule.java
index 2a7089ed20e..891a7628a65 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/SegmentingRule.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/SegmentingRule.java
@@ -7,9 +7,10 @@ package com.yahoo.prelude.query;
* the default is creating a phrase, but for business reasons, some East Asian
* languages use an AND instead.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
- * @since 5.1.28
+ * @author Steinar Knutsen
*/
public enum SegmentingRule {
+
LANGUAGE_DEFAULT, PHRASE, BOOLEAN_AND;
+
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/SuffixItem.java b/container-search/src/main/java/com/yahoo/prelude/query/SuffixItem.java
index 7baca8d60ba..cb87ca85d9a 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/SuffixItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/SuffixItem.java
@@ -5,9 +5,8 @@ package com.yahoo.prelude.query;
/**
* A word that matches a suffix of words instead of a complete word.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
-
public class SuffixItem extends WordItem {
public SuffixItem(String suffix) {
diff --git a/container-search/src/main/java/com/yahoo/search/statistics/TimingSearcher.java b/container-search/src/main/java/com/yahoo/search/statistics/TimingSearcher.java
index 0e1acd66600..f344872955a 100644
--- a/container-search/src/main/java/com/yahoo/search/statistics/TimingSearcher.java
+++ b/container-search/src/main/java/com/yahoo/search/statistics/TimingSearcher.java
@@ -14,16 +14,15 @@ import com.yahoo.search.statistics.TimeTracker.Activity;
import com.yahoo.statistics.Statistics;
import com.yahoo.statistics.Value;
-
/**
* A searcher which is intended to be useful as a general probe for
* measuring time consumption a search chain.
*
- *
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
@Before("rawQuery")
public class TimingSearcher extends PingableSearcher {
+
private Value measurements;
private final boolean measurePing;
private final boolean measureSearch;
@@ -140,5 +139,4 @@ public class TimingSearcher extends PingableSearcher {
super.deconstruct();
}
-
}
diff --git a/container-search/src/main/java/com/yahoo/search/yql/NullItemException.java b/container-search/src/main/java/com/yahoo/search/yql/NullItemException.java
index b451b9c85c5..8502af76858 100644
--- a/container-search/src/main/java/com/yahoo/search/yql/NullItemException.java
+++ b/container-search/src/main/java/com/yahoo/search/yql/NullItemException.java
@@ -4,11 +4,12 @@ package com.yahoo.search.yql;
/**
* Used to communicate a NullItem has been encountered in the query tree.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
-@SuppressWarnings("serial")
public class NullItemException extends RuntimeException {
+
public NullItemException(String message) {
super(message);
}
+
}
diff --git a/container-search/src/main/java/com/yahoo/text/interpretation/Annotations.java b/container-search/src/main/java/com/yahoo/text/interpretation/Annotations.java
index 5afe51d4415..f625bedca19 100644
--- a/container-search/src/main/java/com/yahoo/text/interpretation/Annotations.java
+++ b/container-search/src/main/java/com/yahoo/text/interpretation/Annotations.java
@@ -8,28 +8,26 @@ import java.util.Map;
/**
* An annotation is a description of a an area of text, with a given class. For example, an annotation for the
*
- * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a>
+ * @author Arne Bergene Fossaa
*/
public class Annotations {
-
- private Span span;
+ private final Span span;
protected Map<String,Object> annotations;
-
/**
* Adds an annotation to the the the set of annotations.
*/
public void put(String key,Object o) {
- if(annotations == null) {
+ if (annotations == null) {
annotations = new HashMap<>();
}
annotations.put(key,o);
}
public Map<String,Object> getMap() {
- if(annotations == null) {
+ if (annotations == null) {
return Collections.emptyMap();
} else {
return annotations;
@@ -113,12 +111,11 @@ public class Annotations {
*/
public Boolean getBoolean(String key) {
Object o = getMap().get(key);
- if(o == null || !(o instanceof Boolean)) {
+ if ( ! (o instanceof Boolean)) {
return null;
} else {
- return (Boolean) o;
+ return (Boolean)o;
}
}
-
}
diff --git a/container-search/src/main/java/com/yahoo/text/interpretation/Interpretation.java b/container-search/src/main/java/com/yahoo/text/interpretation/Interpretation.java
index 9a9b8e81633..f662a0a4e7e 100644
--- a/container-search/src/main/java/com/yahoo/text/interpretation/Interpretation.java
+++ b/container-search/src/main/java/com/yahoo/text/interpretation/Interpretation.java
@@ -21,21 +21,19 @@ import java.util.Set;
* is not needed.
*
* @see Span
- * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a>
+ * @author Arne Bergene Fossaa
*/
public class Interpretation {
- private Modification modification;
+ private final Modification modification;
private double probability;
- private Span rootSpan;
+ private final Span rootSpan;
public final static AnnotationClass INTERPRETATION_CLASS = new AnnotationClass("interpretation");
-
/**
* Creates a new interpretation and a new modification from the text,
* with the probability set to the default value(0.0).
-
*/
public Interpretation(String text) {
this(text,0.0);
@@ -48,7 +46,6 @@ public class Interpretation {
this(new Modification(text),probabilty);
}
-
/**
* Creates a new interpretation based on the modification, with the probability set to the default value(0.0).
*/
@@ -65,12 +62,10 @@ public class Interpretation {
setProbability(probability);
}
-
public Modification getModification() {
return modification;
}
-
/**
* The probability that this interpretation is correct.
* @return a value between 0.0 and 1.0 that gives the probability that this interpretation is correct
@@ -98,13 +93,12 @@ public class Interpretation {
/** Returns the root of the tree representation of the interpretation */
public Span root() { return rootSpan; }
-
// Wrapper methods for Span
/**
* Return the annotation with the given annotationclass (and create it if necessary).
- * @param annotationClass The class of the annotation
*
+ * @param annotationClass The class of the annotation
*/
public Annotations annotate(String annotationClass) {
return annotate(new AnnotationClass(annotationClass));
@@ -112,8 +106,8 @@ public class Interpretation {
/**
* Return the annotation with the given annotationclass (and create it if necessary).
- * @param annotationClass The class of the annotation
*
+ * @param annotationClass The class of the annotation
*/
public Annotations annotate(AnnotationClass annotationClass) {
return rootSpan.annotate(annotationClass);
@@ -124,6 +118,7 @@ public class Interpretation {
* exist, a new is created.
*
* A shortcut for annotate(annotationClass).put(key,value)
+ *
* @param annotationClass class of the annotation
* @param key key of the property to set on the annotation
* @param value value of the property to set on the annotation
@@ -137,6 +132,7 @@ public class Interpretation {
* exist, a new is created.
*
* A shortcut for annotate(annotationClass).put(key,value)
+ *
* @param annotationClass class of the annotation
* @param key key of the property to set on the annotation
* @param value value of the property to set on the annotation
@@ -147,6 +143,7 @@ public class Interpretation {
/**
* Returns the annotation with the given annotationClass (and create it if necessary).
+ *
* @param from start of the substring
* @param to end of the substring
* @param annotationClass class of the annotation
@@ -157,6 +154,7 @@ public class Interpretation {
/**
* Returns the annotation with the given annotationClass (and create it if necessary).
+ *
* @param from start of the substring
* @param to end of the substring
* @param annotationClass class of the annotation
@@ -169,7 +167,8 @@ public class Interpretation {
* Sets a key/value pair for an annotation of a substring. If an annotation of the class
* does not exist, a new is created.
*
- * A shortcut for annotate(from, to, annotationClass, key, value
+ * A shortcut for annotate(from, to, annotationClass, key, value)
+ *
* @param from start of the substring
* @param to end of the substring
* @param annotationClass class of the annotation
@@ -184,7 +183,8 @@ public class Interpretation {
* Sets a key/value pair for an annotation of a substring. If an annotation of the class
* does not exist, a new is created.
*
- * A shortcut for annotate(from, to, annotationClass, key, value
+ * A shortcut for annotate(from, to, annotationClass, key, value)
+ *
* @param from start of the substring
* @param to end of the substring
* @param annotationClass class of the annotation
@@ -219,12 +219,7 @@ public class Interpretation {
*/
public List<Annotations> getAll(AnnotationClass annotationClass) {
// TODO: This implementation is very inefficient because it unnecessarily collects for all classes
- Map<AnnotationClass,List<Annotations>> all = getAll();
- if(all.containsKey(annotationClass)){
- return all.get(annotationClass);
- } else {
- return Collections.emptyList();
- }
+ return getAll().getOrDefault(annotationClass, List.of());
}
/**
@@ -256,7 +251,7 @@ public class Interpretation {
/**
* Gets the value of a property set on an annotation.
* If the annotation or the key/value pair does not exists, null
- * is returned
+ * is returned.
*/
public Object get(String annotationClass,String key) {
return get(new AnnotationClass(annotationClass),key);
@@ -265,7 +260,7 @@ public class Interpretation {
/**
* Gets the value of a property set on an annotation.
* If the annotation or the key/value pair does not exists, null
- * is returned
+ * is returned.
*/
public Object get(AnnotationClass annotationClass,String key) {
Annotations annotations = get(annotationClass);
@@ -280,7 +275,7 @@ public class Interpretation {
* Equivalent to <code>get(from,to,new AnnotationClass(annotationClass))</code>
*/
public Annotations get(int from, int to, String annotationClass) {
- return get(from,to,new AnnotationClass(annotationClass));
+ return get(from, to, new AnnotationClass(annotationClass));
}
/**
@@ -310,7 +305,7 @@ public class Interpretation {
* @return the anno
*/
public Annotations get(int from, int to, AnnotationClass annotationClass ) {
- return rootSpan.getAnnotation(from,to,annotationClass);
+ return rootSpan.getAnnotation(from, to, annotationClass);
}
/**
@@ -320,9 +315,9 @@ public class Interpretation {
* is returned.
*
*/
- public Object get(int from,int to,String annotationClass,String key) {
- Annotations annotations = get(from,to,annotationClass);
- if(annotations != null) {
+ public Object get(int from, int to, String annotationClass, String key) {
+ Annotations annotations = get(from, to, annotationClass);
+ if (annotations != null) {
return annotations.get(key);
} else {
return null;
@@ -331,7 +326,6 @@ public class Interpretation {
/**
* Gets all the annotationclasses that describes the text.
-
*/
public Set<AnnotationClass> getClasses() {
return rootSpan.getClasses();
@@ -399,7 +393,7 @@ public class Interpretation {
}
}
sb.append("}");
-
}
}
+
}
diff --git a/container-search/src/main/java/com/yahoo/text/interpretation/Modification.java b/container-search/src/main/java/com/yahoo/text/interpretation/Modification.java
index e2fd5a5ec5c..28cf11c62b1 100644
--- a/container-search/src/main/java/com/yahoo/text/interpretation/Modification.java
+++ b/container-search/src/main/java/com/yahoo/text/interpretation/Modification.java
@@ -9,21 +9,14 @@ import java.util.HashMap;
* This class represents a possible rewrite of an original text. Reasons for rewrite may be due to possible
* spelling errors in the text or to query expansion.
*
- * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a>
+ * @author Arne Bergene Fossaa
*/
public class Modification extends HashMap<String,Object>{
- /**
- *
- */
- private static final long serialVersionUID = -8522335044460396296L;
-
-
public final static AnnotationClass MODIFICATION_CLASS = new AnnotationClass("modification");
-
- private String text;
- private Annotations annotations;
+ private final String text;
+ private final Annotations annotations;
public Modification(String text) {
this.text = text;
diff --git a/container-search/src/main/java/com/yahoo/text/interpretation/Span.java b/container-search/src/main/java/com/yahoo/text/interpretation/Span.java
index 6ade5e323e7..90cc6231d48 100644
--- a/container-search/src/main/java/com/yahoo/text/interpretation/Span.java
+++ b/container-search/src/main/java/com/yahoo/text/interpretation/Span.java
@@ -22,7 +22,7 @@ import java.util.Set;
* <p>
* A span will usually be used indirectly through Interpretation.
*
- * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a>
+ * @author Arne Bergene Fossaa
*/
public class Span {
@@ -33,7 +33,6 @@ public class Span {
private final int from;
private final int to;
-
/**
* Creates a new root span based on the modfication
*/
@@ -44,7 +43,7 @@ public class Span {
this.to = modification.getText().length();
}
- //This constructor is private to ensure that all child spans for a span is contained inside it.
+ // This constructor is private to ensure that all child spans for a span is contained inside it.
private Span(int from, int to, Span parent) {
this.parent = parent;
this.modification = parent.modification;
@@ -52,8 +51,6 @@ public class Span {
this.to = to;
}
-
-
/**
* Returns the text that this spans is
*/
@@ -61,12 +58,11 @@ public class Span {
return modification.getText().substring(from, to);
}
-
+ @Override
public String toString() {
return "SPAN: " + getText();
}
-
public Annotations annotate(AnnotationClass clazz) {
Annotations annotations = this.annotations.get(clazz);
if (!this.annotations.containsKey(clazz)) {
@@ -83,7 +79,6 @@ public class Span {
return addAnnotation(from, to, clazz);
}
-
/**
* Returns all annotations that are contained in either this subspan or in any of its subannotations
*/
@@ -124,7 +119,7 @@ public class Span {
* @throws RuntimeException if (from,to) is not contained in the span
*/
public Annotations getAnnotation(int from, int to, AnnotationClass clazz) {
- if(from < this.from || to > this.to) {
+ if (from < this.from || to > this.to) {
throw new RuntimeException("Trying to get a range that is outside this span");
}
if (this.parent != null) {
@@ -140,13 +135,12 @@ public class Span {
*/
public Set<AnnotationClass> getClasses() {
return getClasses(from, to);
-
}
/**
* Returns all AnnotationClasses that are defined for the range (from,to).
*
- * @throws RuntimeException if (from,to) is not contained in the span
+ * @throws RuntimeException if (from, to) is not contained in the span
*/
public Set<AnnotationClass> getClasses(int from, int to) {
if(from < this.from || to > this.to) {
@@ -161,8 +155,6 @@ public class Span {
}
}
-
-
/**
* Returns an unmodifiable list of all spans below this span that is a leaf node
*/
@@ -191,26 +183,25 @@ public class Span {
/** hack */
public int getFrom() { return from; }
+
/** hack */
public int getTo() { return to; }
- //Needed by addAnnotation
+ // Needed by addAnnotation
private List<Span> getRemovableSubSpan() {
return subSpans == null ?
Collections.<Span>emptyList() :
subSpans;
}
-
private void addSubSpan(Span span) {
- if(subSpans == null) {
+ if (subSpans == null) {
subSpans = new ArrayList<>();
}
subSpans.add(span);
}
-
- /*
+ /**
* How this works:
*
* First we check if any excisting subannotation can contain this annotation. If so, we leave it to them to add
@@ -222,7 +213,7 @@ public class Span {
*/
private Annotations addAnnotation(int from, int to, AnnotationClass clazz) {
if (equalsRange(from, to)) {
- //We simply add everything from the new span to this
+ // We simply add everything from the new span to this
if (annotations.containsKey(clazz)) {
return annotations.get(clazz);
} else {
@@ -232,7 +223,7 @@ public class Span {
}
}
- //We then check if any of the children intersects
+ // We then check if any of the children intersects
for (Span subSpan : getSubSpans()) {
if (subSpan.intersects(from, to)) {
throw new RuntimeException("Trying to add span that intersects already excisting span");
@@ -241,14 +232,13 @@ public class Span {
}
}
- //We now know that we have to add the new span to this span
+ // We now know that we have to add the new span to this span
Span span = new Span(from, to, this);
Annotations nAnnotations = new Annotations(span);
span.annotations.put(clazz,nAnnotations);
addSubSpan(span);
-
- //We then add any subannotation that is inside the span
+ // We then add any subannotation that is inside the span
Iterator<Span> subIterator = getRemovableSubSpan().iterator();
while (subIterator.hasNext()) {
@@ -256,7 +246,7 @@ public class Span {
if (subSpan.contains(from, to)) {
return subSpan.addAnnotation(from, to, clazz);
} else if (subSpan.isInside(from, to)) {
- //Overtake the subannotation
+ // Take over the subannotation
subSpan.parent = span;
span.addSubSpan(subSpan);
subIterator.remove();
@@ -265,7 +255,6 @@ public class Span {
return nAnnotations;
}
-
private boolean contains(int from, int to) {
return this.from <= from && this.to >= to;
}
@@ -274,12 +263,9 @@ public class Span {
return this.from >= from && this.to <= to;
}
-
private boolean intersects(int from, int to) {
return (this.from < from && this.to > from && this.to < to)
|| (this.from < to && this.to > to && this.from > from);
-
-
}
private boolean equalsRange(int from, int to) {
@@ -336,7 +322,7 @@ public class Span {
if (!contains(from, to)) {
return null;
}
- //First yourself, then the subs
+ // First yourself, then the subs
Annotations annotations = this.annotations.get(clazz);
for (Span subSpan : getSubSpans()) {
Annotations subAnnotations = subSpan.getBestAnnotation(from, to, clazz);
@@ -346,4 +332,5 @@ public class Span {
}
return annotations;
}
+
}
diff --git a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/Visitor.java b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/Visitor.java
index e8b83495c69..8065f71c1f0 100644
--- a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/Visitor.java
+++ b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/Visitor.java
@@ -15,7 +15,7 @@ import java.util.Map;
/**
* Visitor for performing searches and accessing results.
*
- * @author <a href="mailto:ulf@yahoo-inc.com">Ulf Carlin</a>
+ * @author Ulf Carlin
*/
interface Visitor {
diff --git a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VisitorFactory.java b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VisitorFactory.java
index 7ce323a2f2b..421a36dbc63 100644
--- a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VisitorFactory.java
+++ b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VisitorFactory.java
@@ -7,7 +7,7 @@ import com.yahoo.search.Query;
/**
* A factory that creates Visitors.
*
- * @author <a href="mailto:ulf@yahoo-inc.com">Ulf Carlin</a>
+ * @author Ulf Carlin
*/
interface VisitorFactory {