public abstract class AbstractSentenceModel extends Object implements SentenceModel
AbstractSentenceModel implements a sentence model
in terms of the method that adds indices to the collection.
Subclasses must only implement the method boundaryIndices(String[],String[],int,int,Collection), which adds
an Integer to the collection for each token index
which is sentence final.
The abstract model also adds
the method boundaryIndices(String[],String[],int,int) for
operating over slices of parallel arrays of tokens and whitespaces.
The static utility methods verifyBounds(String[],String[],int,int)
and verifyTokensWhitespaces(String[],String[]) may be used
by subclasses to verify that the inputs to the sentence detection
methods are legal.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSentenceModel()
Construct an abstract sentence model.
|
| Modifier and Type | Method and Description |
|---|---|
int[] |
boundaryIndices(String[] tokens,
String[] whitespaces)
Returns an array of indices of sentence-final tokens.
|
int[] |
boundaryIndices(String[] tokens,
String[] whitespaces,
int start,
int length)
Returns an array of indices of sentence-final tokens
for the slice of the token and whitespace arrays specified.
|
abstract void |
boundaryIndices(String[] tokens,
String[] whitespaces,
int start,
int length,
Collection<Integer> indices)
Adds the sentence final token indices as
Integer
instances to the specified collection, only considering tokens
between index start and end-1
inclusive. |
protected static void |
verifyBounds(String[] tokens,
String[] whitespaces,
int start,
int length)
Throws an illegal argument exception if the arrays of tokens is
not as long as the start plus length, or if the array of
whitespaces is not at least one element longer than the start
plus length.
|
protected static void |
verifyTokensWhitespaces(String[] tokens,
String[] whitespaces)
Throws an illegal argument exception if the array of whitespaces
is not one longer than the array of tokens.
|
protected AbstractSentenceModel()
public int[] boundaryIndices(String[] tokens, String[] whitespaces)
If this method is overridden in a subclass, the static
method verifyTokensWhitespaces(String[],String[]) should
be called to verify that the arguments are valid.
boundaryIndices in interface SentenceModeltokens - Array of tokens to annotate.whitespaces - Array of whitespaces to annotate.IllegalArgumentException - If the array of whitespaces is
not one element longer than the array of tokens.public int[] boundaryIndices(String[] tokens, String[] whitespaces, int start, int length)
If this method is overridden in a subclass, the static
method verifyBounds(String[],String[],int,int) should
be called by implementations to verify that the arguments are
valid.
tokens - Array of tokens to annotate.whitespaces - Array of whitespaces to annotate.start - Index of first token to annotate.length - Number of tokens to annotate.IllegalArgumentException - If the array of whitespaces is
not one element longer than the array of tokens.public abstract void boundaryIndices(String[] tokens, String[] whitespaces, int start, int length, Collection<Integer> indices)
Integer
instances to the specified collection, only considering tokens
between index start and end-1
inclusive.
The abstract implementations provide an array list for the collection of indices, and results will be returned in the order they are added to the collection.
The static method verifyBounds(String[],String[],int,int) should be called by
implementations to verify that the arguments are valid.
boundaryIndices in interface SentenceModeltokens - Array of tokens to annotate.whitespaces - Array of whitespaces to annotate.start - Index of first token to annotate.length - Number of tokens to annotate.indices - Collection into which to write the boundary
indices.IllegalArgumentException - If the array of whitespaces
and tokens is not long enough for the start and length parameters.protected static void verifyBounds(String[] tokens, String[] whitespaces, int start, int length)
tokens - Array of tokens to annotate.whitespaces - Array of whitespaces to annotate.start - Index of first token to annotate.length - Number of tokens to annotate.IllegalArgumentException - If the array of whitespaces
and tokens is not long enough for the start and length parameters.protected static void verifyTokensWhitespaces(String[] tokens, String[] whitespaces)
tokens - Array of tokens to annotate.whitespaces - Array of whitespaces to annotate.IllegalArgumentException - If the array of whitespaces
is not one longer than the array of tokens.Copyright © 2019 Alias-i, Inc.. All rights reserved.