Package com.yahoo.text.interpretation
Class Interpretation
java.lang.Object
com.yahoo.text.interpretation.Interpretation
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:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionInterpretation
(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
(String text) Creates a new interpretation and a new modification from the text, with the probability set to the default value(0.0).Interpretation
(String text, double probabilty) Creates a new interpretation and a new modification from the text, with the given probability. -
Method Summary
Modifier and TypeMethodDescriptionannotate
(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, String key, Object value) Sets a key/value pair for an annotation of a substring.Returns the annotation with the given annotationClass (and create it if necessary).void
Sets a key/value pair for an annotation of a substring.annotate
(AnnotationClass annotationClass) Return the annotation with the given annotationclass (and create it if necessary).void
annotate
(AnnotationClass annotationClass, String key, Object value) Sets a key/value pair for an annotation.Return the annotation with the given annotationclass (and create it if necessary).void
Sets a key/value pair for an annotation.get
(int from, int to, AnnotationClass annotationClass) Gets an annotation that is set on a substring.Equivalent toget(from,to,new AnnotationClass(annotationClass))
Get the value of a property set on a substring annotation.get
(AnnotationClass annotationClass) Returns the annotation marked with the annotationClass.get
(AnnotationClass annotationClass, String key) Gets the value of a property set on an annotation.Returns the annotation marked with the annotationClass.Gets the value of a property set on an annotation.getAll()
Gets all annotations mentioned in the query.getAll
(AnnotationClass annotationClass) Returns a list of all annotations of the given class that exists in the text.Returns a list of all annotations of the given class that exists in the text.Gets all the annotationclasses that describes the text.getClasses
(int from, int to) Gets all annotationclasses that describe a substringdouble
The probability that this interpretation is correct.getTermSpans
(String term) Returns all spans that consists of the term given.Gets the lowermost spans (usually the spans marked with token).root()
Returns the root of the tree representation of the interpretationvoid
setProbability
(double probability) Sets he probability that this interpretation is the correct.toString()
-
Field Details
-
INTERPRETATION_CLASS
-
-
Constructor Details
-
Interpretation
Creates a new interpretation and a new modification from the text, with the probability set to the default value(0.0). -
Interpretation
Creates a new interpretation and a new modification from the text, with the given probability. -
Interpretation
Creates a new interpretation based on the modification, with the probability set to the default value(0.0). -
Interpretation
Creates an interpretation based on the modification given.
-
-
Method Details
-
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
Returns the root of the tree representation of the interpretation -
annotate
Return the annotation with the given annotationclass (and create it if necessary).- Parameters:
annotationClass
- The class of the annotation
-
annotate
Return the annotation with the given annotationclass (and create it if necessary).- Parameters:
annotationClass
- The class of the annotation
-
annotate
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
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
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
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
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
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
Gets all annotations mentioned in the query. This will also return all subannotations, even those that override their parents -
getAll
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
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
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
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
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
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
Equivalent toget(from,to,new AnnotationClass(annotationClass))
-
get
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
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
Gets all the annotationclasses that describes the text. -
getClasses
Gets all annotationclasses that describe a substring -
getTokens
Gets the lowermost spans (usually the spans marked with token). -
getTermSpans
Returns all spans that consists of the term given. If no span with that term exists, the empty list is returned. -
toString
-