edu.cmu.minorthird.text
Class BasicSpan

java.lang.Object
  extended by edu.cmu.minorthird.text.BasicSpan
All Implemented Interfaces:
Span, Visible, java.io.Serializable, java.lang.Comparable<Span>
Direct Known Subclasses:
SubSpan

public class BasicSpan
extends java.lang.Object
implements Span, java.io.Serializable, Visible

Implements the Span interface.

Author:
William Cohen
See Also:
Serialized Form

Field Summary
 int hiCharIndex
           
 int loCharIndex
           
 int loTextTokenIndex
           
 
Constructor Summary
BasicSpan(java.lang.String documentId, TextToken[] textTokens, int loTextTokenIndex, int spanLen, java.lang.String documentGroupId)
          Constructor assumes that the textTokens are all from the documentId.
 
Method Summary
 java.lang.String asString()
          Find the string contained in a Span.
 Span charIndexProperSubSpan(int lo, int hi)
          Create a the largest Span containing TextToken's which are contained in the character boundaries charLo, charHi of this span.
 Span charIndexSubSpan(int lo, int hi)
          Create a new Span containing TextToken's which are as close as possible to the character boundaries charLo, charHi of thisspan.
 int compareTo(Span other)
           
 boolean contains(Span other)
          Check containment
 Span documentSpan()
          A larger span containing this span.
 int documentSpanStartIndex()
          The index of this span in the home span.
 boolean equals(java.lang.Object o)
           
 int getCharOffset()
           
 java.lang.String getDocumentContents()
          Return a string containing the entire content of the document that this span lives in.
 java.lang.String getDocumentGroupId()
          Return the id of the group of documents this span belongs to
 java.lang.String getDocumentId()
          Return the name of the document for these TextToken's.
 int getHiChar()
          Returns how many characters there are up to and including the span
 Span getLeftBoundary()
          A length-zero span for the left boundary
 int getLoChar()
          Returns how many characters are before the span in the document
 int getLoTextToken()
          Returns the low text token
 Span getRightBoundary()
          A length-zero span for the left boundary
 TextToken getTextToken(int i)
          Retrieves the ith TextToken in the span
 Token getToken(int i)
          Retrieves the ith TextToken in the span
 int hashCode()
           
 boolean overlaps(Span other)
          Check overlap
 void setCharOffset(int charOffset)
           
 int size()
          Returns the number of tokens in the span.
 Span subSpan(int start, int len)
          Create a new BasicSpan, covering the indicated TextToken's.
 SubSpan subSpan(int startIndex, int start, int len)
          Create a SubSpan of this span, covering the indicated TextToken's.
 Viewer toGUI()
          Create a view of this object
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

loTextTokenIndex

public int loTextTokenIndex

loCharIndex

public int loCharIndex

hiCharIndex

public int hiCharIndex
Constructor Detail

BasicSpan

public BasicSpan(java.lang.String documentId,
                 TextToken[] textTokens,
                 int loTextTokenIndex,
                 int spanLen,
                 java.lang.String documentGroupId)
Constructor assumes that the textTokens are all from the documentId.

Method Detail

getDocumentId

public java.lang.String getDocumentId()
Description copied from interface: Span
Return the name of the document for these TextToken's.

Specified by:
getDocumentId in interface Span

getDocumentGroupId

public java.lang.String getDocumentGroupId()
Description copied from interface: Span
Return the id of the group of documents this span belongs to

Specified by:
getDocumentGroupId in interface Span

getDocumentContents

public java.lang.String getDocumentContents()
Description copied from interface: Span
Return a string containing the entire content of the document that this span lives in.

Note: this differs subtly from documentSpan().asString(), which returns the string between the beginning of the first token and the end of the last token in the containing document.

Specified by:
getDocumentContents in interface Span

size

public int size()
Returns the number of tokens in the span.

Specified by:
size in interface Span

getTextToken

public TextToken getTextToken(int i)
Retrieves the ith TextToken in the span

Specified by:
getTextToken in interface Span

getToken

public Token getToken(int i)
Retrieves the ith TextToken in the span

Specified by:
getToken in interface Span

subSpan

public Span subSpan(int start,
                    int len)
Create a new BasicSpan, covering the indicated TextToken's.

Specified by:
subSpan in interface Span

subSpan

public SubSpan subSpan(int startIndex,
                       int start,
                       int len)
Create a SubSpan of this span, covering the indicated TextToken's.


documentSpan

public Span documentSpan()
A larger span containing this span.

Specified by:
documentSpan in interface Span

documentSpanStartIndex

public int documentSpanStartIndex()
The index of this span in the home span.

Specified by:
documentSpanStartIndex in interface Span

contains

public boolean contains(Span other)
Description copied from interface: Span
Check containment

Specified by:
contains in interface Span

overlaps

public boolean overlaps(Span other)
Description copied from interface: Span
Check overlap

Specified by:
overlaps in interface Span

asString

public java.lang.String asString()
Find the string contained in a Span.

Specified by:
asString in interface Span

getLeftBoundary

public Span getLeftBoundary()
A length-zero span for the left boundary

Specified by:
getLeftBoundary in interface Span

getRightBoundary

public Span getRightBoundary()
A length-zero span for the left boundary

Specified by:
getRightBoundary in interface Span

compareTo

public int compareTo(Span other)
Specified by:
compareTo in interface java.lang.Comparable<Span>

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

charIndexSubSpan

public Span charIndexSubSpan(int lo,
                             int hi)
Description copied from interface: Span
Create a new Span containing TextToken's which are as close as possible to the character boundaries charLo, charHi of thisspan.

Specified by:
charIndexSubSpan in interface Span

charIndexProperSubSpan

public Span charIndexProperSubSpan(int lo,
                                   int hi)
Description copied from interface: Span
Create a the largest Span containing TextToken's which are contained in the character boundaries charLo, charHi of this span.

Specified by:
charIndexProperSubSpan in interface Span

setCharOffset

public void setCharOffset(int charOffset)
Specified by:
setCharOffset in interface Span

getCharOffset

public int getCharOffset()
Specified by:
getCharOffset in interface Span

getLoTextToken

public int getLoTextToken()
Description copied from interface: Span
Returns the low text token

Specified by:
getLoTextToken in interface Span

getLoChar

public int getLoChar()
Returns how many characters are before the span in the document

Specified by:
getLoChar in interface Span

getHiChar

public int getHiChar()
Returns how many characters there are up to and including the span

Specified by:
getHiChar in interface Span

toGUI

public Viewer toGUI()
Description copied from interface: Visible
Create a view of this object

Specified by:
toGUI in interface Visible