kylm.util
Class SymbolSet

java.lang.Object
  extended by kylm.util.SymbolSet
All Implemented Interfaces:
java.io.Serializable

public class SymbolSet
extends java.lang.Object
implements java.io.Serializable

A class that holds a mapping from vocabulary to integers

Author:
neubig
See Also:
Serialized Form

Field Summary
 java.util.HashMap<java.lang.String,java.lang.Integer> ids
           
 java.util.Vector<java.lang.String> syms
           
 
Constructor Summary
SymbolSet()
          Create a new symbol set
 
Method Summary
 void addAlias(java.lang.String sym, int id)
          Add an alias to the vocabulary.
 int addSymbol(java.lang.String sym)
           
 int addSymbol(java.lang.String sym, boolean overrideAlias)
          Add a symbol to the vocabulary.
 void addSymbols(java.lang.String[] symbols)
          Add multiple symbols to the vocabulary
 boolean equals(java.lang.Object obj)
           
 java.lang.Integer getId(java.lang.String s)
          Get the ID associated with a symbol
 int getSize()
          Get the size of the symbol set.
 java.lang.String getSymbol(int id)
          Get the symbol associated with the ID.
 java.lang.String[] getSymbols()
          Return every symbol in the symbol set.
static SymbolSet readFromFile(java.lang.String fileName)
          Read a symbol set from a file
The format can either be one symbol per line, or one symbol followed by its ID per line, in which case the lines must be in ascending order starting with symbol number one
 void writeToFile(java.lang.String string, boolean writeNumbers)
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ids

public java.util.HashMap<java.lang.String,java.lang.Integer> ids

syms

public java.util.Vector<java.lang.String> syms
Constructor Detail

SymbolSet

public SymbolSet()
Create a new symbol set

Method Detail

addSymbol

public int addSymbol(java.lang.String sym,
                     boolean overrideAlias)
Add a symbol to the vocabulary. If it doesn't exist, or exists only as an alias, it is added. If it does exist, it is not added, but it's number is returned.

Parameters:
sym - The symbol to be added.
overrideAlias - Whether or not to delete aliases.
Returns:
The ID assigned to the added symbol.

addSymbol

public int addSymbol(java.lang.String sym)

addSymbols

public void addSymbols(java.lang.String[] symbols)
Add multiple symbols to the vocabulary

Parameters:
symbols - The symbols to add

addAlias

public void addAlias(java.lang.String sym,
                     int id)
Add an alias to the vocabulary.

Parameters:
sym - The symbol of the alias.
id - The id number that the alias should point to.

getSymbol

public java.lang.String getSymbol(int id)
Get the symbol associated with the ID.

Parameters:
id - The ID to search for.
Returns:
The symbol that is associated with id.

getSize

public int getSize()
Get the size of the symbol set.

Returns:
The size.

getSymbols

public java.lang.String[] getSymbols()
Return every symbol in the symbol set.

Returns:
An array containing every symbol in the symbol set

getId

public java.lang.Integer getId(java.lang.String s)
Get the ID associated with a symbol

Parameters:
s - The symbol
Returns:
The id, or null if the symbol doesn't exist

equals

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

readFromFile

public static SymbolSet readFromFile(java.lang.String fileName)
                              throws java.io.IOException
Read a symbol set from a file
The format can either be one symbol per line, or one symbol followed by its ID per line, in which case the lines must be in ascending order starting with symbol number one

Parameters:
fileName - The name of the file to read from
Returns:
The symbol set read from that file
Throws:
java.io.IOException - If there is a problem with the input or the file is not in the proper format

writeToFile

public void writeToFile(java.lang.String string,
                        boolean writeNumbers)
                 throws java.io.IOException
Throws:
java.io.IOException