Class Interpretation

java.lang.Object
com.yahoo.text.interpretation.Interpretation

public class Interpretation extends 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:
  • Field Details

    • INTERPRETATION_CLASS

      public static final AnnotationClass INTERPRETATION_CLASS
  • Constructor Details

    • Interpretation

      public 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

      public Interpretation(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 Details

    • 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(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(String annotationClass, String key, 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 annotation
      key - key of the property to set on the annotation
      value - value of the property to set on the annotation
    • annotate

      public void annotate(AnnotationClass annotationClass, String key, 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 annotation
      key - key of the property to set on the annotation
      value - value of the property to set on the annotation
    • annotate

      public Annotations annotate(int from, int to, String annotationClass)
      Returns the annotation with the given annotationClass (and create it if necessary).
      Parameters:
      from - start of the substring
      to - end of the substring
      annotationClass - 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 substring
      to - end of the substring
      annotationClass - class of the annotation
    • annotate

      public void annotate(int from, int to, String annotationClass, String key, 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 substring
      to - end of the substring
      annotationClass - class of the annotation
      key - key of property to set on annotation
      value - value of property to set on annotation
    • annotate

      public void annotate(int from, int to, AnnotationClass annotationClass, String key, 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 substring
      to - end of the substring
      annotationClass - class of the annotation
      key - key of property to set on annotation
      value - value of property to set on annotation
    • getAll

      public Map<AnnotationClass,List<Annotations>> getAll()
      Gets all annotations mentioned in the query. This will also return all subannotations, even those that override their parents
    • getAll

      public List<Annotations> getAll(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 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(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 Object get(String annotationClass, 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 Object get(AnnotationClass annotationClass, 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, String annotationClass)
      Equivalent to get(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 substring
      to - end of the substring
      annotationClass - class of the annotation
      Returns:
      the anno
    • get

      public Object get(int from, int to, String annotationClass, 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 Set<AnnotationClass> getClasses()
      Gets all the annotationclasses that describes the text.
    • getClasses

      public Set<AnnotationClass> getClasses(int from, int to)
      Gets all annotationclasses that describe a substring
    • getTokens

      public List<Span> getTokens()
      Gets the lowermost spans (usually the spans marked with token).
    • getTermSpans

      public List<Span> getTermSpans(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 String toString()
      Overrides:
      toString in class Object