Package opennlp.tools.util
Class Span
- java.lang.Object
-
- opennlp.tools.util.Span
-
- All Implemented Interfaces:
Serializable
,Comparable<Span>
- Direct Known Subclasses:
LinkedSpan
,MascSentence
,MascToken
,MascWord
public class Span extends Object implements Comparable<Span>, 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 newSpan
.Span(int s, int e, double prob)
Initializes a newSpan
.Span(int s, int e, String type)
Initializes a newSpan
.Span(int s, int e, String type, double prob)
Initializes a newSpan
.Span(Span span, double prob)
Span(Span span, int offset)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Span s)
Compares the specifiedSpan
to the current span.boolean
contains(int index)
An index with the value of end is considered outside theSpan
.boolean
contains(Span s)
Identicalspans
are considered to contain each other.boolean
crosses(Span s)
Checks if the specifiedSpan
crosses this span.boolean
equals(Object o)
CharSequence
getCoveredText(CharSequence text)
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.double
getProb()
int
getStart()
String
getType()
int
hashCode()
boolean
intersects(Span s)
Checks if the specifiedSpan
intersects with this span.int
length()
static String[]
spansToStrings(Span[] spans, CharSequence s)
static String[]
spansToStrings(Span[] spans, String[] tokens)
boolean
startsWith(Span s)
String
toString()
Span
trim(CharSequence text)
-
-
-
Constructor Detail
-
Span
public Span(int s, int e, String type)
Initializes a newSpan
. Sets the prob to0
as default.- Parameters:
s
- The start position of aSpan
. Must be equal to or greater than0
. Must not be greater thane
.e
- The end position of aSpan
, which is+1
more than the last element in the span. Must be equal to or greater than0
.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 newSpan
.- Parameters:
s
- The start position of aSpan
. Must be equal to or greater than0
. Must not be greater thane
.e
- The end position of aSpan
, which is+1
more than the last element in the span. Must be equal to or greater than0
.type
- The type of theSpan
prob
- The probability of theSpan
.- Throws:
IllegalArgumentException
- Thrown if given parameters are invalid.
-
Span
public Span(int s, int e)
Initializes a newSpan
. Sets the prob to0
as default.- Parameters:
s
- The start position of aSpan
. Must be equal to or greater than0
. Must not be greater thane
.e
- The end position of aSpan
, which is+1
more than the last element in the span. Must be equal to or greater than0
.- Throws:
IllegalArgumentException
- Thrown if given parameters are invalid.
-
Span
public Span(int s, int e, double prob)
Initializes a newSpan
. Sets the prob to0
as default.- Parameters:
s
- The start position of aSpan
. Must be equal to or greater than0
. Must not be greater thane
.e
- The end position of aSpan
, which is+1
more than the last element in the span. Must be equal to or greater than0
.prob
- The probability of theSpan
- Throws:
IllegalArgumentException
- Thrown if given parameters are invalid.
-
Span
public Span(Span span, int offset)
- Parameters:
span
- The existingSpan
.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 immutableSpan
based on an existingSpan
, where the existingSpan
did not include the probability.- Parameters:
span
- TheSpan
that has no prob or the prob is incorrect and a newSpan
must be generated.prob
- The probability of theSpan
.- 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 than0
.
-
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 than0
.
-
length
public int length()
- Returns:
- Returns the length of a
Span
. Guaranteed to be greater than0
.
-
contains
public boolean contains(int index)
An index with the value of end is considered outside theSpan
.- Parameters:
index
- the index to test with thisSpan
.- Returns:
true
if the span contains this specified index,false
otherwise.
-
startsWith
public boolean startsWith(Span s)
- Parameters:
s
- TheSpan
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 specifiedSpan
intersects with this span.- Parameters:
s
- TheSpan
to compare with this span.- Returns:
true
is the spans overlap,false
otherwise.
-
getCoveredText
public CharSequence getCoveredText(CharSequence text)
- Parameters:
text
- Thetext
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)
-
compareTo
public int compareTo(Span s)
Compares the specifiedSpan
to the current span.- Specified by:
compareTo
in interfaceComparable<Span>
- Parameters:
s
- TheSpan
instance to compare against.- See Also:
Comparable.compareTo(Object)
-
toString
public String toString()
-
spansToStrings
public static String[] spansToStrings(Span[] spans, CharSequence s)
- Parameters:
spans
- The array used as input.s
- TheCharSequence
used to compute covered text.- Returns:
- The converted array of strings.
-
getProb
public double getProb()
- Returns:
- Retrieves the probability represented by a
Span
.
-
-