com.aliasi.chunk
Class ChunkAndCharSeq

java.lang.Object
  extended by com.aliasi.chunk.ChunkAndCharSeq
All Implemented Interfaces:
Scored

public class ChunkAndCharSeq
extends Object
implements Scored

The ChunkAndCharSeq is an immutable composite of a chunk and a character sequence. This class also implements the Scored interface based on chunk score (see score()), so that elements may be sorted by score.

Equality for the composite is based on object equality. This means that two chunk and character sequences may have the same span over the same character sequence with the same type and same score and still be different.

Instances of this class are returned in the sets produced by a ChunkingEvaluation and in a SentenceEvaluation.

Since:
LingPipe2.1
Version:
2.1.1
Author:
Mitzi Morris

Field Summary
 
Fields inherited from interface com.aliasi.util.Scored
REVERSE_SCORE_COMPARATOR, SCORE_COMPARATOR
 
Constructor Summary
ChunkAndCharSeq(Chunk chunk, CharSequence cSeq)
          Construct a composite of the specified chunk and sequence.
 
Method Summary
 String charSequence()
          Return the underlying character sequence for this chunk.
 Chunk chunk()
          Return the chunk underlying this compositie chunk and character sequence.
 boolean equals(Object that)
          Returns true if the specified object is a chunk and character sequence structurally equivalent to this one.
 int hashCode()
          Returns the cached hash code for this chunk and character sequence.
 double score()
          Return the underlying chunk's score.
 String span()
          Return the characters spanned by this chunk.
 CharSequence spanEndContext(int contextLength)
          Return a span of characters centered around the end of this chunk plus or minus the context length.
 CharSequence spanStartContext(int contextLength)
          Return a span of characters centered around the start of this chunk plus or minus the context length.
 String toString()
          Returns a string-based representation of this chunk and character sequence.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChunkAndCharSeq

public ChunkAndCharSeq(Chunk chunk,
                       CharSequence cSeq)
Construct a composite of the specified chunk and sequence.

Parameters:
chunk - The underlying chunk.
cSeq - The character sequence for the chunk.
Throws:
IllegalArgumentException - If the chunk bounds exceed the sequence length.
Method Detail

hashCode

public int hashCode()
Returns the cached hash code for this chunk and character sequence.

Overrides:
hashCode in class Object
Returns:
The hash code for this chunk and character sequence.

equals

public boolean equals(Object that)
Returns true if the specified object is a chunk and character sequence structurally equivalent to this one. For equality, the character sequences must be equivalent and the chunks must be equivalent.

Overrides:
equals in class Object
Parameters:
that - Object to test for equality.
Returns:
true if equivalent to this object.

span

public String span()
Return the characters spanned by this chunk. Note that this is the subsequence of the character sequence, sequence(), running from this chunk's start index, chunk().start(), up to but not including the chunk's end index, chunk().end().

Returns:
The characters spanned by this chunk.

spanStartContext

public CharSequence spanStartContext(int contextLength)
Return a span of characters centered around the start of this chunk plus or minus the context length. If there isn't sufficient context, the returned string will be padded so that the chunk start is at position contextLen. Note that this is the subsequence of the character sequence, sequence(), running from this chunk's start index - contextLen, chunk().start(), up to not including start index + contextLen.

Parameters:
contextLength - The number of characters before and after the chunk start to retrieve.
Returns:
The characters centered around the start of this chunk.
Throws:
IllegalArgumentException - If the contextLength < 1.

spanEndContext

public CharSequence spanEndContext(int contextLength)
Return a span of characters centered around the end of this chunk plus or minus the context length. If there isn't sufficient context, the returned string will be padded so that the chunk end is at position contextLength. Note that this is the subsequence of the character sequence, sequence(), running from this chunk's end index - contextLength, chunk().end(), up to not including end index + contextLength.

Parameters:
contextLength - The number of characters before and after the chunk end to retrieve.
Returns:
The characters centered around the end of this chunk.
Throws:
IllegalArgumentException - If the contextLength < 1.

charSequence

public String charSequence()
Return the underlying character sequence for this chunk.

Returns:
The underlying character sequence for this chunk.

chunk

public Chunk chunk()
Return the chunk underlying this compositie chunk and character sequence.


score

public double score()
Return the underlying chunk's score.

Specified by:
score in interface Scored
Returns:
The underlying chunk's score.

toString

public String toString()
Returns a string-based representation of this chunk and character sequence.

Implementation Note: This representation is of the form "start-end/span:type".

Overrides:
toString in class Object