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
Class for storing start and end integer offsets.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares the specifiedSpanto the current span.booleancontains(int index) An index with the value of end is considered outside theSpan.booleanIdenticalspansare considered to contain each other.booleanChecks if the specifiedSpancrosses this span.booleangetCoveredText(CharSequence text) intgetEnd()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.doublegetProb()intgetStart()getType()inthashCode()booleanintersects(Span s) Checks if the specifiedSpanintersects with this span.intlength()static String[]spansToStrings(Span[] spans, CharSequence s) static String[]spansToStrings(Span[] spans, String[] tokens) booleanstartsWith(Span s) toString()trim(CharSequence text)
-
Constructor Details
-
Span
Initializes a newSpan. Sets the prob to0as 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+1more 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
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+1more than the last element in the span. Must be equal to or greater than0.type- The type of theSpanprob- 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 to0as 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+1more 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 to0as 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+1more 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
- Parameters:
span- The existingSpan.offset- The positive or negative shift offset.- Throws:
IllegalArgumentException- Thrown if given parameters are invalid.
-
Span
Creates a new immutableSpanbased on an existingSpan, where the existingSpandid not include the probability.- Parameters:
span- TheSpanthat has no prob or the prob is incorrect and a newSpanmust be generated.prob- The probability of theSpan.- Throws:
IllegalArgumentException- Thrown if given parameters are invalid.
-
-
Method Details
-
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.
-
getType
- Returns:
- Retrieves the type of a
Spanornullif not set.
-
length
public int length()- Returns:
- Returns the length of a
Span. Guaranteed to be greater than0.
-
contains
Identicalspansare considered to contain each other. -
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:
trueif the span contains this specified index,falseotherwise.
-
startsWith
- Parameters:
s- TheSpanto compare with this span.- Returns:
trueif the specified span starts with this span and is contained in this span,falseotherwise
-
intersects
Checks if the specifiedSpanintersects with this span.- Parameters:
s- TheSpanto compare with this span.- Returns:
trueis the spans overlap,falseotherwise.
-
crosses
Checks if the specifiedSpancrosses this span. -
getCoveredText
- Parameters:
text- Thetextto analyze.- Returns:
- Retrieves the (sub)string covered by the current
Spanof the specified text. - Throws:
IllegalArgumentException- Thrown if parameters violated a constraint.
-
trim
-
compareTo
Compares the specifiedSpanto the current span.- Specified by:
compareToin interfaceComparable<Span>- Parameters:
s- TheSpaninstance to compare against.- See Also:
-
hashCode
public int hashCode() -
equals
-
toString
-
spansToStrings
- Parameters:
spans- The array used as input.s- TheCharSequenceused to compute covered text.- Returns:
- The converted array of strings.
-
spansToStrings
-
getProb
public double getProb()- Returns:
- Retrieves the probability represented by a
Span.
-