Package com.yahoo.text.interpretation
Class Span
- java.lang.Object
-
- com.yahoo.text.interpretation.Span
-
public class Span extends Object
Span is a description of a part of a text, modeled as a tree. A span is defined by the range (from,to) and by a set of annotations on that range. It also contains a set of child nodes that all have the restrictionchild.from >= parent.from && child.to <= parent.to && (child.to-child.from) < (parent.to-parent.from)
This means that all spans on a text can be modeled as a tree, where all child spans are guaranteed to be contained inside its parent span.A span will usually be used indirectly through Interpretation.
- Author:
- Arne Bergene Fossaa
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Annotations
annotate(int from, int to, AnnotationClass clazz)
This will either create or get the annotation of the class annotationAnnotations
annotate(AnnotationClass clazz)
Map<AnnotationClass,List<Annotations>>
getAllAnnotations()
Returns all annotations that are contained in either this subspan or in any of its subannotationsAnnotations
getAnnotation(int from, int to, AnnotationClass clazz)
Returns the annotations with a specific class for the area defined by (from,to).Annotations
getAnnotation(AnnotationClass clazz)
Returns the annotations with a specific class for the area defined by this spanSet<AnnotationClass>
getClasses()
Returns all AnnotationClasses that are defined for this span and any of its superspans.Set<AnnotationClass>
getClasses(int from, int to)
Returns all AnnotationClasses that are defined for the range (from,to).int
getFrom()
hackList<Span>
getSubSpans()
Returns all spans that are directly childrens of this span.List<Span>
getTermSpans(String term)
Returns all spans, either this or any of the spans that are inherits this span that match the given termString
getText()
Returns the text that this spans isint
getTo()
hackList<Span>
getTokens()
Returns an unmodifiable list of all spans below this span that is a leaf nodeboolean
hasClass(AnnotationClass clazz)
Returns true if this classString
toString()
-
-
-
Method Detail
-
getText
public String getText()
Returns the text that this spans is
-
annotate
public Annotations annotate(AnnotationClass clazz)
-
annotate
public Annotations annotate(int from, int to, AnnotationClass clazz)
This will either create or get the annotation of the class annotation
-
getAllAnnotations
public Map<AnnotationClass,List<Annotations>> getAllAnnotations()
Returns all annotations that are contained in either this subspan or in any of its subannotations
-
getTermSpans
public List<Span> getTermSpans(String term)
Returns all spans, either this or any of the spans that are inherits this span that match the given term
-
getAnnotation
public Annotations getAnnotation(AnnotationClass clazz)
Returns the annotations with a specific class for the area defined by this spanThis function will query its parent to find any annotation that is set for an area that this span is contained in. If there are conflicts (several annotations defined with the same annotation class), the annotation that is defined for the smallest area (furthest down in the tree), is used.
-
getAnnotation
public Annotations getAnnotation(int from, int to, AnnotationClass clazz)
Returns the annotations with a specific class for the area defined by (from,to). This function will query its parent to find any annotation that is set for an area that this span is contained in. If there are conflicts (several annotations defined with the same annotation class), the annotation that is defined for the smallest area (furthest down in the tree), is used.- Throws:
RuntimeException
- if (from,to) is not contained in the span
-
getClasses
public Set<AnnotationClass> getClasses()
Returns all AnnotationClasses that are defined for this span and any of its superspans.
-
getClasses
public Set<AnnotationClass> getClasses(int from, int to)
Returns all AnnotationClasses that are defined for the range (from,to).- Throws:
RuntimeException
- if (from, to) is not contained in the span
-
getTokens
public List<Span> getTokens()
Returns an unmodifiable list of all spans below this span that is a leaf node
-
hasClass
public boolean hasClass(AnnotationClass clazz)
Returns true if this class
-
getSubSpans
public List<Span> getSubSpans()
Returns all spans that are directly childrens of this span. If the span is a leaf, the empty list will be returned. The list is unmodifable.
-
getFrom
public int getFrom()
hack
-
getTo
public int getTo()
hack
-
-