Class SimpleDictionary
java.lang.Object
smile.nlp.dictionary.SimpleDictionary
- All Implemented Interfaces:
Iterable<String>, Dictionary
A simple implementation of dictionary interface.
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleDictionary(String resource) Constructor that loads a dictionary from a file path or classpath resource.SimpleDictionary(Path path) Constructor that loads a dictionary from aPath. -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Dictionary
streamMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
SimpleDictionary
Constructor that loads a dictionary from a file path or classpath resource. If the given path points to an existing file, it is loaded directly. Otherwise, it is treated as a classpath resource path.- Parameters:
resource- the file path or classpath resource path of the dictionary. The file should be plain text with one word per line.
-
SimpleDictionary
-
-
Method Details
-
contains
Description copied from interface:DictionaryReturns true if this dictionary contains the specified word.- Specified by:
containsin interfaceDictionary- Parameters:
word- the query word.- Returns:
- true if this dictionary contains the specified word.
-
size
public int size()Description copied from interface:DictionaryReturns the number of words in this dictionary.- Specified by:
sizein interfaceDictionary- Returns:
- the number of words in this dictionary.
-
iterator
Description copied from interface:DictionaryReturns an iterator over the words in this dictionary.- Specified by:
iteratorin interfaceDictionary- Specified by:
iteratorin interfaceIterable<String>- Returns:
- the iterator.
-