opennlp.tools.util
Class Span

java.lang.Object
  extended by opennlp.tools.util.Span
All Implemented Interfaces:
Comparable<Span>

public class Span
extends Object
implements Comparable<Span>

Class for storing start and end integer offsets.


Constructor Summary
Span(int s, int e)
          Initializes a new Span Object.
Span(int s, int e, String type)
          Initializes a new Span Object.
Span(Span span, int offset)
          Initializes a new Span object with an existing Span which is shifted by an offset.
 
Method Summary
 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(Object o)
          Checks if the specified span is equal to the current span.
 CharSequence getCoveredText(CharSequence text)
          Retrieves the string covered by the current span of the specified text.
 int getEnd()
          Return the end of a span.
 int getStart()
          Return the start of a span.
 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 String[] spansToStrings(Span[] spans, CharSequence s)
          Converts an array of Spans to an array of Strings.
static String[] spansToStrings(Span[] spans, 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.
 String toString()
          Generates a human readable string.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Span

public Span(int s,
            int e,
            String type)
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

Span

public Span(int s,
            int e)
Initializes a new Span Object.

Parameters:
s - start of span.
e - end of span.

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 -
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

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)


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.