de.fu_berlin.ties.text
Class TokenCounter

java.lang.Object
  extended byde.fu_berlin.ties.text.TokenCounter

public class TokenCounter
extends Object

A simple container that keeps track of the tokens in a document. This class differs from TokenContainer by not doing any tokenization itself, relying on external tokenization instead.

Instances of this class are not thread-safe; if you want to share a single instance between different thread, you have to ensure proper synchronization.

Version:
$Revision: 1.2 $, $Date: 2004/04/08 16:38:18 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
TokenCounter()
          Creates a new instance.
 
Method Summary
 void add(boolean whitespaceBefore, String token)
          Adds a token to this instance.
 void addWhitespace()
          Adds whitespace to this instance, setting isWhitespaceAfterLast() to true.
 int getCount(String token)
          Returns the cardinality of the given token in this container.
 String getLast()
          Returns the last added token.
 int getLastRep()
          Returns the repetition of the last added token in the original text (counting start with 0, as the first occurrence is the "0th repetition").
 boolean isWhitespaceAfterLast()
          Whether there is whitespace after the last added token.
 boolean isWhitespaceBeforeLast()
          Whether there is whitespace before the last added token.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TokenCounter

public TokenCounter()
Creates a new instance.

Method Detail

add

public void add(boolean whitespaceBefore,
                String token)
Adds a token to this instance.

Parameters:
whitespaceBefore - whether there is whitespace before the token
token - the token to add

addWhitespace

public void addWhitespace()
Adds whitespace to this instance, setting isWhitespaceAfterLast() to true.


getCount

public int getCount(String token)
Returns the cardinality of the given token in this container.

Parameters:
token - the token to check
Returns:
the number of copies of the specified token in this container, >= 0

getLastRep

public int getLastRep()
Returns the repetition of the last added token in the original text (counting start with 0, as the first occurrence is the "0th repetition").

Returns:
the value of the attribute

getLast

public String getLast()
Returns the last added token.

Returns:
the value of the attribute

isWhitespaceAfterLast

public boolean isWhitespaceAfterLast()
Whether there is whitespace after the last added token.

Returns:
true iff there is whitespace after the token

isWhitespaceBeforeLast

public boolean isWhitespaceBeforeLast()
Whether there is whitespace before the last added token.

Returns:
true iff there is whitespace before the token

toString

public String toString()
Returns a string representation of this object.

Returns:
a textual representation


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.