com.aliasi.dict
Class MapDictionary<C>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<DictionaryEntry<C>>
          extended by com.aliasi.dict.AbstractDictionary<C>
              extended by com.aliasi.dict.MapDictionary<C>
Type Parameters:
C - the type of object stored in this dictionary
All Implemented Interfaces:
Dictionary<C>, Compilable, Serializable, Iterable<DictionaryEntry<C>>, Collection<DictionaryEntry<C>>, Set<DictionaryEntry<C>>

public class MapDictionary<C>
extends AbstractDictionary<C>
implements Compilable, Serializable

A MapDictionary uses an underlying map from phrases to their set of dictionary entries. Map-based dictionaries are compilable if their underlying entries are compilable, which requires every category object to implement either the LingPipe interface Compilable or the Java interface Serializable

The result is a fast implementation of addEntry(DictionaryEntry), iterator() and phraseEntryIt(String).

Serialization and Compilation

Serializing or compiling a dictionary writes out a compact representation of the dictionary. When read back in, the dictionary will be the same as the one written.

The dictionary entries must be serializable or compilable.

Since:
LingPipe2.3.1
Version:
3.8.1
Author:
Bob Carpenter
See Also:
Serialized Form

Constructor Summary
MapDictionary()
          Construct an empty map-based dictionary.
 
Method Summary
 void addEntry(DictionaryEntry<C> entry)
          Adds the specified dictionary entry to the dictionary.
 void compileTo(ObjectOutput out)
          Serializes the object to the specified output.
 Iterator<DictionaryEntry<C>> iterator()
          Return an iterator over the dictionary entries in this dictionary.
 Iterator<DictionaryEntry<C>> phraseEntryIt(String phrase)
          Returns an iterator over the dictionary entries with the specified phrase.
 
Methods inherited from class com.aliasi.dict.AbstractDictionary
categoryEntries, categoryEntryIt, categoryEntryList, entries, entryList, phraseEntries, phraseEntryList, size
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

MapDictionary

public MapDictionary()
Construct an empty map-based dictionary.

Method Detail

addEntry

public void addEntry(DictionaryEntry<C> entry)
Description copied from class: AbstractDictionary
Adds the specified dictionary entry to the dictionary. This method must be overridden by subclasses that allow the addition of dictionary entries.

Specified by:
addEntry in interface Dictionary<C>
Overrides:
addEntry in class AbstractDictionary<C>
Parameters:
entry - Dictionary entry to add.

iterator

public Iterator<DictionaryEntry<C>> iterator()
Return an iterator over the dictionary entries in this dictionary.

Specified by:
iterator in interface Iterable<DictionaryEntry<C>>
Specified by:
iterator in interface Collection<DictionaryEntry<C>>
Specified by:
iterator in interface Set<DictionaryEntry<C>>
Specified by:
iterator in class AbstractCollection<DictionaryEntry<C>>
Returns:
Iterator over entries.

phraseEntryIt

public Iterator<DictionaryEntry<C>> phraseEntryIt(String phrase)
Description copied from class: AbstractDictionary
Returns an iterator over the dictionary entries with the specified phrase.

Implementation Note: This implementation filters the result of AbstractCollection.iterator() for entries with a matching phrase.

Specified by:
phraseEntryIt in interface Dictionary<C>
Overrides:
phraseEntryIt in class AbstractDictionary<C>
Parameters:
phrase - The phrase to look up.
Returns:
Iterator over the entries with the specified phrase.

compileTo

public void compileTo(ObjectOutput out)
               throws IOException
Serializes the object to the specified output.

Specified by:
compileTo in interface Compilable
Overrides:
compileTo in class AbstractDictionary<C>
Parameters:
out - Object output to which this dictionary is compiled.
Throws:
IOException - If there is an I/O error writing the object.