Class Span

    • Constructor Summary

      Constructors 
      Constructor Description
      Span​(int s, int e)
      Initializes a new Span Object.
      Span​(int s, int e, double prob)  
      Span​(int s, int e, String type)
      Initializes a new Span Object.
      Span​(int s, int e, String type, double prob)
      Initializes a new Span Object.
      Span​(Span span, double prob)
      Creates a new immutable span based on an existing span, where the existing span did not include the prob
      Span​(Span span, int offset)
      Initializes a new Span object with an existing Span which is shifted by an offset.
    • Constructor Detail

      • Span

        public Span​(int s,
                    int e,
                    String type)
        Initializes a new Span Object. Sets the prob to 0 as default.
        Parameters:
        s - start of span.
        e - end of span, which is +1 more than the last element in the span.
        type - the type of the span
      • Span

        public Span​(int s,
                    int e,
                    String type,
                    double prob)
        Initializes a new Span Object.
        Parameters:
        s - start of span.
        e - end of span, which is +1 more than the last element in the span.
        type - the type of the span
        prob - probability of span.
      • Span

        public Span​(int s,
                    int e)
        Initializes a new Span Object. Sets the prob to 0 as default
        Parameters:
        s - start of span.
        e - end of span.
      • Span

        public Span​(int s,
                    int e,
                    double prob)
        Parameters:
        s - the start of the span (the token index, not the char index)
        e - the end of the span (the token index, not the char index)
        prob -
      • Span

        public Span​(Span span,
                    int offset)
        Initializes a new Span object with an existing Span which is shifted by an offset.
        Parameters:
        span -
        offset -
      • Span

        public Span​(Span span,
                    double prob)
        Creates a new immutable span based on an existing span, where the existing span did not include the prob
        Parameters:
        span - the span that has no prob or the prob is incorrect and a new Span must be generated
        prob - the probability of the span
    • Method Detail

      • getStart

        public int getStart()
        Return the start of a span.
        Returns:
        the start of a span.
      • getEnd

        public int getEnd()
        Return the end of a span. Note: that the returned index is one past the actual end of the span in the text, or the first element past the end of the span.
        Returns:
        the end of a span.
      • getType

        public String getType()
        Retrieves the type of the span.
        Returns:
        the type or null if not set
      • length

        public int length()
        Returns the length of this span.
        Returns:
        the length of the span.
      • contains

        public boolean contains​(Span s)
        Returns true if the specified span is contained by this span. Identical spans are considered to contain each other.
        Parameters:
        s - The span to compare with this span.
        Returns:
        true is the specified span is contained by this span; false otherwise.
      • contains

        public boolean contains​(int index)
        Returns true if the specified index is contained inside this span. An index with the value of end is considered outside the span.
        Parameters:
        index - the index to test with this span.
        Returns:
        true if the span contains this specified index; false otherwise.
      • startsWith

        public boolean startsWith​(Span s)
        Returns true if the specified span is the begin of this span and the specified span is contained in this span.
        Parameters:
        s - The span to compare with this span.
        Returns:
        true if the specified span starts with this span and is contained in this span; false otherwise
      • intersects

        public boolean intersects​(Span s)
        Returns true if the specified span intersects with this span.
        Parameters:
        s - The span to compare with this span.
        Returns:
        true is the spans overlap; false otherwise.
      • crosses

        public boolean crosses​(Span s)
        Returns true is the specified span crosses this span.
        Parameters:
        s - The span to compare with this span.
        Returns:
        true is the specified span overlaps this span and contains a non-overlapping section; false otherwise.
      • getCoveredText

        public CharSequence getCoveredText​(CharSequence text)
        Retrieves the string covered by the current span of the specified text.
        Parameters:
        text -
        Returns:
        the substring covered by the current span
      • trim

        public Span trim​(CharSequence text)
        Return a copy of this span with leading and trailing white spaces removed.
        Parameters:
        text -
        Returns:
        the trimmed span or the same object if already trimmed
      • compareTo

        public int compareTo​(Span s)
        Compares the specified span to the current span.
        Specified by:
        compareTo in interface Comparable<Span>
      • hashCode

        public int hashCode()
        Generates a hash code of the current span.
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object o)
        Checks if the specified span is equal to the current span.
        Overrides:
        equals in class Object
      • toString

        public String toString()
        Generates a human readable string.
        Overrides:
        toString in class Object
      • spansToStrings

        public static String[] spansToStrings​(Span[] spans,
                                              CharSequence s)
        Converts an array of Spans to an array of Strings.
        Parameters:
        spans -
        s -
        Returns:
        the strings
      • spansToStrings

        public static String[] spansToStrings​(Span[] spans,
                                              String[] tokens)
      • getProb

        public double getProb()