Package org.apache.uima.internal.util
Class SymbolTable
java.lang.Object
org.apache.uima.internal.util.SymbolTable
The SymbolTable class provides a generic symbol table. A symbol table is a bijective mapping
between strings and integers. Symbol numbering starts at a point defined by the user, which is 0
by default. A SymbolTable provides quick access to symbol numbers (code points) through a hash
table. The reverse map is facilitated through a separate vector of the symbols. This is memory
intensive, but much faster than searching through the hashtable.
-
Constructor Summary
ConstructorDescriptionDefault constructorSymbolTable
(int start) Use this constructor if you need your symbol numbering to start at a different point than 0.SymbolTable
(String[] names) Init the symbol table from an array of strings, where code points correspond to array positions. -
Method Summary
Modifier and TypeMethodDescriptionboolean
copy()
Perform a deep copy.int
Get value of symbol in table.int
getStart()
Get the starting number of the symbol table.getSymbol
(int i) Find the symbol corresponding to a value.static SymbolTable
readFromFile
(String filename) Read a file line by line, and create an entry for each line.int
Create new symbol in table.int
size()
Returns number of symbols in table.toString()
Returns the string representation of the internal hash table.
-
Constructor Details
-
SymbolTable
public SymbolTable(int start) Use this constructor if you need your symbol numbering to start at a different point than 0.- Parameters:
start
- The code point of the first symbol added to the table. Subsequent symbols will have larger code points.
-
SymbolTable
public SymbolTable()Default constructor -
SymbolTable
Init the symbol table from an array of strings, where code points correspond to array positions. Warning: if the array contains duplicate strings, the numbering will be off!- Parameters:
names
- The String array containing the symbols.
-
-
Method Details
-
contains
-
getStart
public int getStart()Get the starting number of the symbol table.- Returns:
- The start of the table.
-
copy
Perform a deep copy.- Returns:
- A copy of
this
.
-
set
Create new symbol in table. If the symbol already exists, only the symbol's number is returned. Use get() if you need to find out if the symbol is already in the table.- Parameters:
symbol
- the input string to be put in the table.- Returns:
- the symbol's number.
-
get
Get value of symbol in table.- Parameters:
symbol
- the input string.- Returns:
- the symbol's number, if the symbol is in the table, and
start-1
, else (wherestart
is the code point of the first symbol).
-
getSymbol
Find the symbol corresponding to a value.- Parameters:
i
- the number that we want to get the string value for.- Returns:
- the symbol corresponding to the input number, if it exists, and null, else.
-
size
public int size()Returns number of symbols in table.- Returns:
- The number of symbols in the table.
-
toString
Returns the string representation of the internal hash table. -
readFromFile
Read a file line by line, and create an entry for each line. Empty lines are ignored. Lines containing only whitespace are not.- Parameters:
filename
- The name of the file to be read in.- Returns:
- The SymbolTable created from the file.
- Throws:
IOException
- Errors reading in the file.
-