Class AnnotatedText


  • public class AnnotatedText
    extends java.lang.Object
    Container for text and annotations
    • Constructor Detail

      • AnnotatedText

        public AnnotatedText​(java.lang.String text)
    • Method Detail

      • getText

        public java.lang.String getText()
      • addAnnotation

        public void addAnnotation​(Annotation annotation)
      • getTokens

        public java.util.List<Annotation> getTokens()
      • getCoveredAnnotations

        public java.util.Map<java.lang.String,​java.util.List<Annotation>> getCoveredAnnotations​(Annotation annotation)
        Get all annotations covered by the input annotation's offsets For example, pass in a sentence annotation and to retrieve all annotations within that sentence
        Parameters:
        annotation -
        Returns:
      • getConnectedAnnotations

        public java.util.Map<java.lang.String,​java.util.List<Annotation>> getConnectedAnnotations​(Annotation annotation)
        Get all annotations connected to the input annotation's offsets. For example, pass in a token annotation to retrieve all annotations that include that token.
        Parameters:
        annotation -
        Returns:
      • getTokensBetweenCharOffsets

        public java.util.List<Annotation> getTokensBetweenCharOffsets​(int startCharOffset,
                                                                      int endCharOffset)
        Get all tokens that are completely enclosed by start / end character offsets
        Parameters:
        startCharOffset -
        endCharOffset -
        Returns:
      • getAnnotationsBetweenCharOffsets

        public java.util.Map<java.lang.String,​java.util.List<Annotation>> getAnnotationsBetweenCharOffsets​(int startTokenOffset,
                                                                                                                 int endTokenOffset,
                                                                                                                 boolean enclosed)
      • getAnnotationsBetweenCharOffsetsByType

        public java.util.List<Annotation> getAnnotationsBetweenCharOffsetsByType​(int startTokenOffset,
                                                                                 int endTokenOffset,
                                                                                 java.lang.String type,
                                                                                 boolean enclosed)
        Get all annotations for given type that are either enclosed or connected to supplied start/end token offsets See https://github.com/google/guava/wiki/RangesExplained#interval-operations for difference between enclosed/connected ranges
        Parameters:
        startTokenOffset -
        endTokenOffset -
        type -
        enclosed -
        Returns:
      • getAnnotationsByType

        public java.util.List<Annotation> getAnnotationsByType​(java.lang.String type)
      • getCoveredText

        public java.lang.String getCoveredText​(Annotation annotation)
      • detach

        public AnnotatedText detach​(Annotation inputAnnotation)
        Detach text and annotations covered by inputAnnotation into it's own AnnotatedText instance with annotation offsets correctly set relative to detached text
        Parameters:
        inputAnnotation -
        Returns:
      • getAnnotationsAsList

        public java.util.List<Annotation> getAnnotationsAsList()
        Return all annotations in a flat list Annotations of all types are mixed together and no guarantees are given with regards to order.
        Returns:
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object