com.aliasi.sentences
Class AbstractSentenceModel

java.lang.Object
  extended by com.aliasi.sentences.AbstractSentenceModel
All Implemented Interfaces:
SentenceModel
Direct Known Subclasses:
HeuristicSentenceModel

public abstract class AbstractSentenceModel
extends Object
implements SentenceModel

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

Since:
LingPipe1.0
Version:
3.8
Author:
Bob Carpenter

Constructor Summary
protected AbstractSentenceModel()
          Construct an abstract sentence model.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSentenceModel

protected AbstractSentenceModel()
Construct an abstract sentence model. Because this class is abstract, this constructor may only be called by subclasses.

Method Detail

boundaryIndices

public int[] boundaryIndices(String[] tokens,
                             String[] whitespaces)
Returns an array of indices of sentence-final tokens.

If this method is overridden in a subclass, the static method verifyTokensWhitespaces(String[],String[]) should be called to verify that the arguments are valid.

Specified by:
boundaryIndices in interface SentenceModel
Parameters:
tokens - Array of tokens to annotate.
whitespaces - Array of whitespaces to annotate.
Returns:
Array of integers indicating indices of tokens that are sentence final.
Throws:
IllegalArgumentException - If the array of whitespaces is not one element longer than the array of tokens.

boundaryIndices

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

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.

Parameters:
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.
Returns:
Array of integers indicating indices of tokens that are sentence final.
Throws:
IllegalArgumentException - If the array of whitespaces is not one element longer than the array of tokens.

boundaryIndices

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

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.

Specified by:
boundaryIndices in interface SentenceModel
Parameters:
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.
indices - Collection into which to write the boundary indices.
Throws:
IllegalArgumentException - If the array of whitespaces and tokens is not long enough for the start and length parameters.

verifyBounds

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.

Parameters:
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.
Throws:
IllegalArgumentException - If the array of whitespaces and tokens is not long enough for the start and length parameters.

verifyTokensWhitespaces

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.

Parameters:
tokens - Array of tokens to annotate.
whitespaces - Array of whitespaces to annotate.
Throws:
IllegalArgumentException - If the array of whitespaces is not one longer than the array of tokens.