org.apache.lucene.mark
Class BasicWordIter

Object
  extended by BasicWordIter
All Implemented Interfaces:
Cloneable, WordIter
Direct Known Subclasses:
BoundedWordIter, ChunkedWordIter

public class BasicWordIter
extends Object
implements WordIter, Cloneable

Utility class used to iterate either forward or backward through the tokens in a single string of text.

Created: Dec 13, 2004

Author:
Martin Haye

Field Summary
protected  int maxWordPos
          Word position of the last token
protected  String text
          The original text to which the tokens refer
protected  Token[] tokens
          Array of tokens, holding words from the current chunk
protected  int tokNum
          Current token this iterator is pointed at
protected  int wordPos
          Word position of the curren token
 
Fields inherited from interface WordIter
FIELD_END, FIELD_START, TERM_END, TERM_END_PLUS, TERM_START
 
Constructor Summary
protected BasicWordIter()
          Do-nothing constructor - should only be used by derived classes that perform their own initialization.
  BasicWordIter(String text, TokenStream stream)
          Construct the iterator and read in tokens from the given stream.
 
Method Summary
 Object clone()
          Make an exact, independent, copy of this iterator
 MarkPos getPos(int startOrEnd)
          Retrieve the start or end of the current position.
 void getPos(MarkPos pos, int startOrEnd)
          Replace the position within a MarkPos created by WordIter.getPos(int) using the iterator's current position.
 boolean next(boolean force)
          Advance to the next word.
 boolean prev(boolean force)
          Back up to the previous word.
 void seekFirst(int targetPos, boolean force)
          Reposition the iterator at the first word whose position is greater than or equal to 'wordPos'.
 void seekLast(int targetPos, boolean force)
          Reposition the iterator at the last word whose position is less than or equal to 'wordPos'.
 String term()
          Retrieve the text of the term at the current position
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

text

protected String text
The original text to which the tokens refer


tokens

protected Token[] tokens
Array of tokens, holding words from the current chunk


tokNum

protected int tokNum
Current token this iterator is pointed at


wordPos

protected int wordPos
Word position of the curren token


maxWordPos

protected int maxWordPos
Word position of the last token

Constructor Detail

BasicWordIter

public BasicWordIter(String text,
                     TokenStream stream)
              throws IOException
Construct the iterator and read in tokens from the given stream.

Parameters:
text - text represented by the tokens
stream - stream of tokens from the text
Throws:
IOException - If something goes wrong reading from 'stream'

BasicWordIter

protected BasicWordIter()
Do-nothing constructor - should only be used by derived classes that perform their own initialization.

Method Detail

clone

public Object clone()
Description copied from interface: WordIter
Make an exact, independent, copy of this iterator

Specified by:
clone in interface WordIter
Overrides:
clone in class Object

next

public boolean next(boolean force)
Description copied from interface: WordIter
Advance to the next word. If 'force' is set, ignore any section boundary between this word and the next.

Specified by:
next in interface WordIter
Parameters:
force - true to ignore section boundaries
Returns:
true if there was another word to advance to, false if we've reached then end (or, if 'force' is false, a section boundary).

prev

public boolean prev(boolean force)
Description copied from interface: WordIter
Back up to the previous word. If 'force' is set, ignore any section boundary between this word and the previous.

Specified by:
prev in interface WordIter
Parameters:
force - true to ignore section boundaries
Returns:
true if there was room to back up, false if we've reached the start (or, if 'force' is false, a section boundary).

seekFirst

public void seekFirst(int targetPos,
                      boolean force)
Description copied from interface: WordIter
Reposition the iterator at the first word whose position is greater than or equal to 'wordPos'.

Specified by:
seekFirst in interface WordIter
Parameters:
targetPos - Position to seek to
force - true to ignore section boundaries

seekLast

public void seekLast(int targetPos,
                     boolean force)
Description copied from interface: WordIter
Reposition the iterator at the last word whose position is less than or equal to 'wordPos'.

Specified by:
seekLast in interface WordIter
Parameters:
targetPos - Position to seek to
force - true to ignore section boundaries

getPos

public MarkPos getPos(int startOrEnd)
Description copied from interface: WordIter
Retrieve the start or end of the current position.

Specified by:
getPos in interface WordIter
Parameters:
startOrEnd - FIELD_START for the very start of the field; TERM_START for the first character of the word; TERM_END for the last character of the word; TERM_END_PLUS for the last character plus any trailing punctuation and/or spaces; FIELD_END for the very last end of the field.

getPos

public void getPos(MarkPos pos,
                   int startOrEnd)
Description copied from interface: WordIter
Replace the position within a MarkPos created by WordIter.getPos(int) using the iterator's current position.

Specified by:
getPos in interface WordIter
startOrEnd - FIELD_START for the very start of the field; TERM_START for the first character of the word; TERM_END for the last character of the word; TERM_END_PLUS for the last character plus any trailing punctuation and/or spaces; FIELD_END for the very last end of the field.

term

public final String term()
Description copied from interface: WordIter
Retrieve the text of the term at the current position

Specified by:
term in interface WordIter