Package com.yahoo.text.interpretation
Class Interpretation
- java.lang.Object
-
- com.yahoo.text.interpretation.Interpretation
-
public class Interpretation extends java.lang.Object
An interpretation of a text. This class it the main class to use when when querying and modifying annotations for a text. The interpretation consists of a tree of annotations, with the nodes in tree being Spans. An annotation is defined by its annotationClass ("person"), and by a key/value map of parameters for that annotationClass (if the person is an actor or other notable person). This class is the main class for querying and setting annotations, where modifying the span tree is not needed.- Author:
- Arne Bergene Fossaa
- See Also:
Span
-
-
Field Summary
Fields Modifier and Type Field Description static AnnotationClass
INTERPRETATION_CLASS
-
Constructor Summary
Constructors Constructor Description Interpretation(Modification modification)
Creates a new interpretation based on the modification, with the probability set to the default value(0.0).Interpretation(Modification modification, double probability)
Creates an interpretation based on the modification given.Interpretation(java.lang.String text)
Creates a new interpretation and a new modification from the text, with the probability set to the default value(0.0).Interpretation(java.lang.String text, double probabilty)
Creates a new interpretation and a new modification from the text, with the given probability.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Annotations
annotate(int from, int to, AnnotationClass annotationClass)
Returns the annotation with the given annotationClass (and create it if necessary).void
annotate(int from, int to, AnnotationClass annotationClass, java.lang.String key, java.lang.Object value)
Sets a key/value pair for an annotation of a substring.Annotations
annotate(int from, int to, java.lang.String annotationClass)
Returns the annotation with the given annotationClass (and create it if necessary).void
annotate(int from, int to, java.lang.String annotationClass, java.lang.String key, java.lang.Object value)
Sets a key/value pair for an annotation of a substring.Annotations
annotate(AnnotationClass annotationClass)
Return the annotation with the given annotationclass (and create it if necessary).void
annotate(AnnotationClass annotationClass, java.lang.String key, java.lang.Object value)
Sets a key/value pair for an annotation.Annotations
annotate(java.lang.String annotationClass)
Return the annotation with the given annotationclass (and create it if necessary).void
annotate(java.lang.String annotationClass, java.lang.String key, java.lang.Object value)
Sets a key/value pair for an annotation.Annotations
get(int from, int to, AnnotationClass annotationClass)
Gets an annotation that is set on a substring.Annotations
get(int from, int to, java.lang.String annotationClass)
Equivalent toget(from,to,new AnnotationClass(annotationClass))
java.lang.Object
get(int from, int to, java.lang.String annotationClass, java.lang.String key)
Get the value of a property set on a substring annotation.Annotations
get(AnnotationClass annotationClass)
Returns the annotation marked with the annotationClass.java.lang.Object
get(AnnotationClass annotationClass, java.lang.String key)
Gets the value of a property set on an annotation.Annotations
get(java.lang.String annotationClass)
Returns the annotation marked with the annotationClass.java.lang.Object
get(java.lang.String annotationClass, java.lang.String key)
Gets the value of a property set on an annotation.java.util.Map<AnnotationClass,java.util.List<Annotations>>
getAll()
Gets all annotations mentioned in the query.java.util.List<Annotations>
getAll(AnnotationClass annotationClass)
Returns a list of all annotations of the given class that exists in the text.java.util.List<Annotations>
getAll(java.lang.String annotationClass)
Returns a list of all annotations of the given class that exists in the text.java.util.Set<AnnotationClass>
getClasses()
Gets all the annotationclasses that describes the text.java.util.Set<AnnotationClass>
getClasses(int from, int to)
Gets all annotationclasses that describe a substringModification
getModification()
double
getProbability()
The probability that this interpretation is correct.java.util.List<Span>
getTermSpans(java.lang.String term)
Returns all spans that consists of the term given.java.util.List<Span>
getTokens()
Gets the lowermost spans (usually the spans marked with token).Span
root()
Returns the root of the tree representation of the interpretationvoid
setProbability(double probability)
Sets he probability that this interpretation is the correct.java.lang.String
toString()
-
-
-
Field Detail
-
INTERPRETATION_CLASS
public static final AnnotationClass INTERPRETATION_CLASS
-
-
Constructor Detail
-
Interpretation
public Interpretation(java.lang.String text)
Creates a new interpretation and a new modification from the text, with the probability set to the default value(0.0).
-
Interpretation
public Interpretation(java.lang.String text, double probabilty)
Creates a new interpretation and a new modification from the text, with the given probability.
-
Interpretation
public Interpretation(Modification modification)
Creates a new interpretation based on the modification, with the probability set to the default value(0.0).
-
Interpretation
public Interpretation(Modification modification, double probability)
Creates an interpretation based on the modification given.
-
-
Method Detail
-
getModification
public Modification getModification()
-
getProbability
public double getProbability()
The probability that this interpretation is correct.- Returns:
- a value between 0.0 and 1.0 that gives the probability that this interpretation is correct
-
setProbability
public void setProbability(double probability)
Sets he probability that this interpretation is the correct. The value is not normalized, meaning that it can have a value larger than 1.0. The value is used when sorting interpretations.
-
root
public Span root()
Returns the root of the tree representation of the interpretation
-
annotate
public Annotations annotate(java.lang.String annotationClass)
Return the annotation with the given annotationclass (and create it if necessary).- Parameters:
annotationClass
- The class of the annotation
-
annotate
public Annotations annotate(AnnotationClass annotationClass)
Return the annotation with the given annotationclass (and create it if necessary).- Parameters:
annotationClass
- The class of the annotation
-
annotate
public void annotate(java.lang.String annotationClass, java.lang.String key, java.lang.Object value)
Sets a key/value pair for an annotation. If an annotation of the class does not exist, a new is created. A shortcut for annotate(annotationClass).put(key,value)- Parameters:
annotationClass
- class of the annotationkey
- key of the property to set on the annotationvalue
- value of the property to set on the annotation
-
annotate
public void annotate(AnnotationClass annotationClass, java.lang.String key, java.lang.Object value)
Sets a key/value pair for an annotation. If an annotation of the class does not exist, a new is created. A shortcut for annotate(annotationClass).put(key,value)- Parameters:
annotationClass
- class of the annotationkey
- key of the property to set on the annotationvalue
- value of the property to set on the annotation
-
annotate
public Annotations annotate(int from, int to, java.lang.String annotationClass)
Returns the annotation with the given annotationClass (and create it if necessary).- Parameters:
from
- start of the substringto
- end of the substringannotationClass
- class of the annotation
-
annotate
public Annotations annotate(int from, int to, AnnotationClass annotationClass)
Returns the annotation with the given annotationClass (and create it if necessary).- Parameters:
from
- start of the substringto
- end of the substringannotationClass
- class of the annotation
-
annotate
public void annotate(int from, int to, java.lang.String annotationClass, java.lang.String key, java.lang.Object value)
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)- Parameters:
from
- start of the substringto
- end of the substringannotationClass
- class of the annotationkey
- key of property to set on annotationvalue
- value of property to set on annotation
-
annotate
public void annotate(int from, int to, AnnotationClass annotationClass, java.lang.String key, java.lang.Object value)
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)- Parameters:
from
- start of the substringto
- end of the substringannotationClass
- class of the annotationkey
- key of property to set on annotationvalue
- value of property to set on annotation
-
getAll
public java.util.Map<AnnotationClass,java.util.List<Annotations>> getAll()
Gets all annotations mentioned in the query. This will also return all subannotations, even those that override their parents
-
getAll
public java.util.List<Annotations> getAll(java.lang.String annotationClass)
Returns a list of all annotations of the given class that exists in the text. This will also return all subannotations, even those that override their parents. If there are none, an empty list is returned, never null. The returned list should not be modified.
-
getAll
public java.util.List<Annotations> getAll(AnnotationClass annotationClass)
Returns a list of all annotations of the given class that exists in the text. This will also return all subannotations, even those that override their parent. If there are none, an empty list is returned, never null. The returned list should not be modified.
-
get
public Annotations get(java.lang.String annotationClass)
Returns the annotation marked with the annotationClass. This is different from annotate(annotationClass) because a new annotation will not be created if it does not exist.- Parameters:
annotationClass
- class of the annotation- Returns:
- an annotation with the given class, null if it does not exists
-
get
public Annotations get(AnnotationClass annotationClass)
Returns the annotation marked with the annotationClass. This is different from annotate(annotationClass) because a new annotation will not be created if it does not exist.- Parameters:
annotationClass
- class of the annotation- Returns:
- an annotation with the given class, null if it does not exists
-
get
public java.lang.Object get(java.lang.String annotationClass, java.lang.String key)
Gets the value of a property set on an annotation. If the annotation or the key/value pair does not exists, null is returned.
-
get
public java.lang.Object get(AnnotationClass annotationClass, java.lang.String key)
Gets the value of a property set on an annotation. If the annotation or the key/value pair does not exists, null is returned.
-
get
public Annotations get(int from, int to, java.lang.String annotationClass)
Equivalent toget(from,to,new AnnotationClass(annotationClass))
-
get
public Annotations get(int from, int to, AnnotationClass annotationClass)
Gets an annotation that is set on a substring. This function first tries to find an annotation of annotationClass that describe the range (from,to). If that does not exist, it tries to find the smallest range which both contain (from,to) and has an annotation of annotationClass. If that does not exist, null is returned. For example, if these annotations has been set for the text "new york city": i.annotate(0,3,"token") //new i.annotate(4,8,"token") //york i.annotate(9,13,"city") //tokem i.annotate(0,8,"city") //new york i.annotate(0,13,"city") //new york city then: i.get(0,3,"token") //returns "token" - annotation for"new" i.get(0,3,"city") //returns "city" - annotation for "new york" i.get(9,13,"city") //returns "city" - annotation for "new york city"- Parameters:
from
- start of the substringto
- end of the substringannotationClass
- class of the annotation- Returns:
- the anno
-
get
public java.lang.Object get(int from, int to, java.lang.String annotationClass, java.lang.String key)
Get the value of a property set on a substring annotation. If the annotation or the key/value pair does not exists, null is returned.
-
getClasses
public java.util.Set<AnnotationClass> getClasses()
Gets all the annotationclasses that describes the text.
-
getClasses
public java.util.Set<AnnotationClass> getClasses(int from, int to)
Gets all annotationclasses that describe a substring
-
getTokens
public java.util.List<Span> getTokens()
Gets the lowermost spans (usually the spans marked with token).
-
getTermSpans
public java.util.List<Span> getTermSpans(java.lang.String term)
Returns all spans that consists of the term given. If no span with that term exists, the empty list is returned.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-