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>
All Implemented Interfaces:
Dictionary<C>, Compilable, Iterable<DictionaryEntry<C>>, Collection<DictionaryEntry<C>>, Set<DictionaryEntry<C>>

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

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).

Since:
LingPipe2.3.1
Version:
3.0
Author:
Bob Carpenter

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)
          Compiles this dictionary to the specified object output.
 Iterator<DictionaryEntry<C>> iterator()
           
 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, entries, phraseEntries, 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()
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>>

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
Description copied from class: AbstractDictionary
Compiles this dictionary to the specified object output. This method must be overriden by subclasses that allow the compilation of dictionaries; the implementation here throws an unsupported operation exception.

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.