com.aliasi.symbol
Interface SymbolTable

All Known Implementing Classes:
MapSymbolTable, SymbolTableCompiler

public interface SymbolTable

Interface mapping symbols as strings to integer identifiers and vice-versa. In addition to the mapping, the symbol table provides interfaces for optional operations of removing a symbol or clearing the entire symbol, as well as adding a symbol to the table.

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

Field Summary
static int UNKNOWN_SYMBOL_ID
          The value returned for a symbol that is not in the symbol table, namely -1.
 
Method Summary
 void clear()
          Removes all the symbols from the symbol table.
 int getOrAddSymbol(String symbol)
          Returns the identifier for the specified symbol.
 String idToSymbol(int id)
          Return the symbol corresponding to the specified identifier.
 int numSymbols()
          Returns the number of symbols in this symbol table.
 int removeSymbol(String symbol)
          Removes the specified symbol from the symbol table if it was in the table and returns its identifier.
 int symbolToID(String symbol)
          Return the identifier corresponding to the specified symbol, -1 if the symbol does not exist.
 

Field Detail

UNKNOWN_SYMBOL_ID

static final int UNKNOWN_SYMBOL_ID
The value returned for a symbol that is not in the symbol table, namely -1.

See Also:
Constant Field Values
Method Detail

symbolToID

int symbolToID(String symbol)
Return the identifier corresponding to the specified symbol, -1 if the symbol does not exist. The constant -1 is available as the value of UNKNOWN_SYMBOL_ID.

Parameters:
symbol - Symbol whose identifier is returned.
Returns:
Identifier corresponding to specified symbol or -1 if the symbol does not exist.

idToSymbol

String idToSymbol(int id)
Return the symbol corresponding to the specified identifier. Symbols exist for identifiers between 0 and the number of symbols in the table minus one, inclusive. Raises an index out of bounds exception for identifiers out of range.

Parameters:
id - Identifier whose symbol is returned.
Returns:
Symbol corresponding to the specified identifier.
Throws:
IndexOutOfBoundsException - If there is no symbol for the specified identifier.

numSymbols

int numSymbols()
Returns the number of symbols in this symbol table.

Returns:
Number of symbols in this table.

getOrAddSymbol

int getOrAddSymbol(String symbol)
Returns the identifier for the specified symbol. If the symbol is not in the table before the call to this method, it is added and its identifier returned. Optional operation.

Parameters:
symbol - Symbol whose identifier is returned.
Returns:
Integer identifier for specified symbol.
Throws:
UnsupportedOperationException - If this operation is not supproted.

removeSymbol

int removeSymbol(String symbol)
Removes the specified symbol from the symbol table if it was in the table and returns its identifier. If the symbol was not in the table, -1, or UNKNOWN_SYMBOL_ID is returned. Optional operation.

Parameters:
symbol - Symbol to remove.
Returns:
Previous identifier for the symbol, or -1 if it didn't exist.
Throws:
UnsupportedOperationException - If this operation is not supported by this implementation.

clear

void clear()
Removes all the symbols from the symbol table.

If an implementing class does not allow removal, it may throw an unsupported operation exception for this method. OPtional operationl.

Throws:
UnsupportedOperationException - If this operation is not supported by this implementation.