Class Span

    • Constructor Detail

      • Span

        public Span​(int s,
                    int e,
                    String type)
        Initializes a new Span. Sets the prob to 0 as default.
        Parameters:
        s - The start position of a Span. Must be equal to or greater than 0. Must not be greater than e.
        e - The end position of a Span, which is +1 more than the last element in the span. Must be equal to or greater than 0.
        type - the type of the span
        Throws:
        IllegalArgumentException - Thrown if given parameters are invalid.
      • Span

        public Span​(int s,
                    int e,
                    String type,
                    double prob)
        Initializes a new Span.
        Parameters:
        s - The start position of a Span. Must be equal to or greater than 0. Must not be greater than e.
        e - The end position of a Span, which is +1 more than the last element in the span. Must be equal to or greater than 0.
        type - The type of the Span
        prob - The probability of the Span.
        Throws:
        IllegalArgumentException - Thrown if given parameters are invalid.
      • Span

        public Span​(int s,
                    int e)
        Initializes a new Span. Sets the prob to 0 as default.
        Parameters:
        s - The start position of a Span. Must be equal to or greater than 0. Must not be greater than e.
        e - The end position of a Span, which is +1 more than the last element in the span. Must be equal to or greater than 0.
        Throws:
        IllegalArgumentException - Thrown if given parameters are invalid.
      • Span

        public Span​(int s,
                    int e,
                    double prob)
        Initializes a new Span. Sets the prob to 0 as default.
        Parameters:
        s - The start position of a Span. Must be equal to or greater than 0. Must not be greater than e.
        e - The end position of a Span, which is +1 more than the last element in the span. Must be equal to or greater than 0.
        prob - The probability of the Span
        Throws:
        IllegalArgumentException - Thrown if given parameters are invalid.
      • Span

        public Span​(Span span,
                    int offset)
        Initializes a new Span with an existing Span which is shifted by an offset.
        Parameters:
        span - The existing Span.
        offset - The positive or negative shift offset.
        Throws:
        IllegalArgumentException - Thrown if given parameters are invalid.
      • 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 probability.
        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.
        Throws:
        IllegalArgumentException - Thrown if given parameters are invalid.
    • Method Detail

      • getStart

        public int getStart()
        Returns:
        Retrieves the start of a Span. Guaranteed to be greater than 0.
      • getEnd

        public int getEnd()
        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:
        Retrieves the end of a Span. Guaranteed to be greater than 0.
      • getType

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

        public int length()
        Returns:
        Returns the length of a Span. Guaranteed to be greater than 0.
      • contains

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

        public boolean contains​(int index)
        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)
        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)
        Checks 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)
        Checks if the specified Span crosses this span.
        Parameters:
        s - The Span to compare with this span.
        Returns:
        true is the given Span overlaps this span and contains a non-overlapping section, false otherwise.
      • getCoveredText

        public CharSequence getCoveredText​(CharSequence text)
        Parameters:
        text - The text to analyze.
        Returns:
        Retrieves the (sub)string covered by the current Span of the specified text.
        Throws:
        IllegalArgumentException - Thrown if parameters violated a constraint.
      • trim

        public Span trim​(CharSequence text)
        Parameters:
        text - The text to analyze.
        Returns:
        A copy of this Span with leading and trailing white spaces removed, or the same object if already trimmed.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Overrides:
        toString in class Object
        Returns:
        A human-readable representation of this Span.
      • spansToStrings

        public static String[] spansToStrings​(Span[] spans,
                                              CharSequence s)
        Converts an array of spans to an array of String.
        Parameters:
        spans - The array used as input.
        s - The CharSequence used to compute covered text.
        Returns:
        The converted array of strings.
      • spansToStrings

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

        public double getProb()
        Returns:
        Retrieves the probability represented by a Span.