standup.lexicon
Class LexemeSet

java.lang.Object
  extended by standup.lexicon.LexemeSet
All Implemented Interfaces:
XMLizable
Direct Known Subclasses:
CustomLexicon

public class LexemeSet
extends Object
implements XMLizable

A LexemeSet is, appropriately enough, a set of Lexemes.

Author:
Ruli Manurung

Field Summary
protected  HashSet<Lexeme> set
          The actual set of Lexemes.
 
Constructor Summary
LexemeSet()
          Constructor method for the creation of a new, empty, LexemeSet.
LexemeSet(Collection<Lexeme> words)
          Constructor method for the creation of a new LexemeSet populated with the given Lexemes.
LexemeSet(Element e)
          Constructor method for the loading of an existing LexemeSet specified within an XML file.
 
Method Summary
 boolean add(Lexeme l)
          Tries to add the given Lexeme to this LexemeSet.
 boolean add(LexemeSet ls)
          Tries to add the Lexemes contained within the given LexemeSet to this LexemeSet, effectively making this LexemeSet the union of the two.
(package private)  void addLexemesFromXML(Element element)
          Adds all Lexemes specified within the given XML Element to this LexemeSet.
 boolean contains(Lexeme lx)
          Returns true if this LexemeSet contains the given Lexeme, and false otherwise.
 LexemeSet duplicate()
          Returns a duplicate of this LexemeSet.
 boolean equals(Object obj)
           
 int getLexemeCount()
          Returns the number of Lexemes in this object.
 HashSet<Lexeme> getLexemes()
          Returns the Lexemes in this object as a HashSet<Lexeme>.
 Iterator<Lexeme> getLexemesIterator()
          Returns the Lexemes in this object as an Iterator<Lexeme>.
 Lexeme getRandom()
          Returns a randomly selected Lexeme from this LexemeSet.
 Hashtable<String,LexemeSet> getSpelledClusters()
          Creates a Hashtable that clusters the Lexemes contained in this LexemeSet by orthography.
 LexemeSet getSpelledLexemes(WordForm w)
          Returns a LexemeSet that is a subset of this LexemeSet containing Lexemes whose form is the given WordForm.
 LexemeSet getSpelledLexemes(WordSequence ws)
          Returns a LexemeSet that is a subset of this LexemeSet containing Lexemes whose spelling is the same as the given WordSequence.
 int hashCode()
           
 boolean isEmpty()
          Returns true if this LexemeSet contains no Lexemes, and false otherwise.
 boolean remove(Lexeme l)
          Tries to remove the given Lexeme from this LexemeSet.
 boolean remove(LexemeSet ls)
          Tries to remove the Lexemes contained within the given LexemeSet from this LexemeSet.
 Lexeme removeRandom()
          Returns a randomly removed Lexeme from this LexemeSet.
 String toString()
           
 void writeXML(Writer out, String indent)
          Implementation of XMLizable.writeXML(Writer, String).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

set

protected HashSet<Lexeme> set
The actual set of Lexemes. It should only ever be accessed/updated using the provided accessor functions (add, remove, etc.).

Constructor Detail

LexemeSet

public LexemeSet()
Constructor method for the creation of a new, empty, LexemeSet.


LexemeSet

public LexemeSet(Collection<Lexeme> words)
Constructor method for the creation of a new LexemeSet populated with the given Lexemes.

Parameters:
words - the Lexemes to be added to the new LexemeSet

LexemeSet

public LexemeSet(Element e)
Constructor method for the loading of an existing LexemeSet specified within an XML file.

Parameters:
e - the XML Element containing the LexemeSet details. It should have been the output of writeXML(Writer, String).
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

duplicate

public LexemeSet duplicate()
Returns a duplicate of this LexemeSet.


add

public boolean add(Lexeme l)
Tries to add the given Lexeme to this LexemeSet.

Parameters:
l - the Lexeme to be added to this object
Returns:
true if the addition was successful, or false if the Lexeme already exists in this object

add

public boolean add(LexemeSet ls)
Tries to add the Lexemes contained within the given LexemeSet to this LexemeSet, effectively making this LexemeSet the union of the two.

Parameters:
ls - the LexemeSet to be added to this object
Returns:
true if this object changed as a result, or false if all the Lexemes in the given LexemeSet already exist in this object

remove

public boolean remove(Lexeme l)
Tries to remove the given Lexeme from this LexemeSet.

Parameters:
l - the Lexeme to be removed from this object
Returns:
true if the removal was succesful, or false if the Lexeme did not previously exist in this object

remove

public boolean remove(LexemeSet ls)
Tries to remove the Lexemes contained within the given LexemeSet from this LexemeSet.

Parameters:
ls - the LexemeSet to be removed from this object
Returns:
true if this object changed as a result, or false if all the Lexemes in the given LexemeSet did not previously exist in this object

getRandom

public Lexeme getRandom()
Returns a randomly selected Lexeme from this LexemeSet. Does not modify this object.

Returns:
A randomly selected Lexeme

removeRandom

public Lexeme removeRandom()
Returns a randomly removed Lexeme from this LexemeSet. Note that it modifies this object.

Returns:
A randomly removed Lexeme

contains

public boolean contains(Lexeme lx)
Returns true if this LexemeSet contains the given Lexeme, and false otherwise.

Returns:

isEmpty

public boolean isEmpty()
Returns true if this LexemeSet contains no Lexemes, and false otherwise.

Returns:

getLexemesIterator

public Iterator<Lexeme> getLexemesIterator()
Returns the Lexemes in this object as an Iterator<Lexeme>.

Returns:
Iterator of the Collection of Lexemes.

getLexemes

public HashSet<Lexeme> getLexemes()
Returns the Lexemes in this object as a HashSet<Lexeme>.

Returns:

getLexemeCount

public int getLexemeCount()
Returns the number of Lexemes in this object.

Returns:

getSpelledClusters

public Hashtable<String,LexemeSet> getSpelledClusters()
Creates a Hashtable that clusters the Lexemes contained in this LexemeSet by orthography.

A Hashtable key k is a Strings of orthographic spelling, and the value v is a LexemeSets of all Lexemes contained in this LexemeSet that are spelt k.

Returns:

getSpelledLexemes

public LexemeSet getSpelledLexemes(WordForm w)
Returns a LexemeSet that is a subset of this LexemeSet containing Lexemes whose form is the given WordForm.

Parameters:
w -
Returns:
a LexemeSet, possibly empty, or null if w is null.

getSpelledLexemes

public LexemeSet getSpelledLexemes(WordSequence ws)
Returns a LexemeSet that is a subset of this LexemeSet containing Lexemes whose spelling is the same as the given WordSequence.

Parameters:
ws -
Returns:
a LexemeSet, possibly empty, or null if ws is null.

writeXML

public void writeXML(Writer out,
                     String indent)
              throws IOException,
                     XMLException
Implementation of XMLizable.writeXML(Writer, String).

Specified by:
writeXML in interface XMLizable
Parameters:
out - The output stream for the XML file, which is assumed to be already opened and writable.
indent - A string to be prepended before every line written by this method. If passed appropriate white space, e.g. XMLUtils.xmlIndent, it can be used to control indentation.
Throws:
IOException
XMLException

addLexemesFromXML

void addLexemesFromXML(Element element)
Adds all Lexemes specified within the given XML Element to this LexemeSet.

Parameters:
element -