Class Span

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Span>

    public class Span
    extends java.lang.Object
    implements java.lang.Comparable<Span>, java.io.Serializable
    Class for storing start and end integer offsets.
    See Also:
    Serialized Form
    • 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, java.lang.String type)
      Initializes a new Span Object.
      Span​(int s, int e, java.lang.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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Span s)
      Compares the specified span to the current span.
      boolean contains​(int index)
      Returns true if the specified index is contained inside this span.
      boolean contains​(Span s)
      Returns true if the specified span is contained by this span.
      boolean crosses​(Span s)
      Returns true is the specified span crosses this span.
      boolean equals​(java.lang.Object o)
      Checks if the specified span is equal to the current span.
      java.lang.CharSequence getCoveredText​(java.lang.CharSequence text)
      Retrieves the string covered by the current span of the specified text.
      int getEnd()
      Return the end of a span.
      double getProb()  
      int getStart()
      Return the start of a span.
      java.lang.String getType()
      Retrieves the type of the span.
      int hashCode()
      Generates a hash code of the current span.
      boolean intersects​(Span s)
      Returns true if the specified span intersects with this span.
      int length()
      Returns the length of this span.
      static java.lang.String[] spansToStrings​(Span[] spans, java.lang.CharSequence s)
      Converts an array of Spans to an array of Strings.
      static java.lang.String[] spansToStrings​(Span[] spans, java.lang.String[] tokens)  
      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.
      java.lang.String toString()
      Generates a human readable string.
      Span trim​(java.lang.CharSequence text)
      Return a copy of this span with leading and trailing white spaces removed.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Span

        public Span​(int s,
                    int e,
                    java.lang.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,
                    java.lang.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 java.lang.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 java.lang.CharSequence getCoveredText​(java.lang.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​(java.lang.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 java.lang.Comparable<Span>
      • hashCode

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

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

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

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

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

        public double getProb()