Package opennlp.tools.util
Class Span
java.lang.Object
opennlp.tools.util.Span
- All Implemented Interfaces:
Serializable
,Comparable<Span>
Class for storing start and end integer offsets.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSpan
(int s, int e) Initializes a new Span Object.Span
(int s, int e, double prob) Initializes a new Span Object.Initializes a new Span Object.Creates a new immutable span based on an existing span, where the existing span did not include the probInitializes a new Span object with an existing Span which is shifted by an offset. -
Method Summary
Modifier and TypeMethodDescriptionint
Compares the specified span to the current span.boolean
contains
(int index) Returns true if the specified index is contained inside this span.boolean
Returns true if the specified span is contained by this span.boolean
Returns true is the specified span crosses this span.boolean
Checks if the specified span is equal to the current span.getCoveredText
(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.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) 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.toString()
Generates a human readable string.trim
(CharSequence text) Return a copy of this span with leading and trailing white spaces removed.
-
Constructor Details
-
Span
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
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 spanprob
- 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
Initializes a new Span object with an existing Span which is shifted by an offset.- Parameters:
span
-offset
-
-
Span
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 generatedprob
- the probability of the span
-
-
Method Details
-
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
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
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
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
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
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
Retrieves the string covered by the current span of the specified text.- Parameters:
text
-- Returns:
- the substring covered by the current span
-
trim
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
Compares the specified span to the current span.- Specified by:
compareTo
in interfaceComparable<Span>
-
hashCode
public int hashCode()Generates a hash code of the current span. -
equals
Checks if the specified span is equal to the current span. -
toString
Generates a human readable string. -
spansToStrings
- Parameters:
spans
-s
-- Returns:
- the strings
-
spansToStrings
-
getProb
public double getProb()
-