Interface IDictionary
-
- All Superinterfaces:
java.lang.AutoCloseable
public interface IDictionary extends java.lang.AutoCloseable
Interface for dictionary access.Each dictionary format reader should implement this interface. Each instance of this interface represents one dictionary.
Implementers are encouraged to use
DictionaryData
to store their data. A simple implementation can just load its entire data at once, but we don't recommend it because it's very memory-intensive.Instead we recommend that you read the dictionary's index (article titles) and store some short data, like article offsets into the dictionary file, as the value. In your implementation of the
readArticles*
methods you can use these offsets to actually load the content from disk. The OS will cache dictionary file against slow access.See
StarDict
for an example of the recommended deferred-loading implementation, andLingvoDSL
for an example of an simpler, up-front loading implementation.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
close()
Dispose IDictionary.java.util.List<DictionaryEntry>
readArticles(java.lang.String word)
Read article's text.default java.util.List<DictionaryEntry>
readArticlesPredictive(java.lang.String word)
Read article's text.default java.util.List<DictionaryEntry>
retrieveArticles(java.util.Collection<java.lang.String> words)
default java.util.List<DictionaryEntry>
retrieveArticlesPredictive(java.util.Collection<java.lang.String> words)
-
-
-
Method Detail
-
readArticles
java.util.List<DictionaryEntry> readArticles(java.lang.String word) throws java.lang.Exception
Read article's text.- Parameters:
word
- The word to look up in the dictionary- Returns:
- List of entries. May be empty, but cannot be null.
- Throws:
java.lang.Exception
-
readArticlesPredictive
default java.util.List<DictionaryEntry> readArticlesPredictive(java.lang.String word) throws java.lang.Exception
Read article's text. Matching is predictive, so e.g. supplying "term" will return articles for "term", "terminology", "termite", etc. The default implementation simply callsreadArticles(String)
for backwards compatibility.- Parameters:
word
- The word to look up in the dictionary- Returns:
- List of entries. May be empty, but cannot be null.
- Throws:
java.lang.Exception
-
retrieveArticles
default java.util.List<DictionaryEntry> retrieveArticles(java.util.Collection<java.lang.String> words) throws java.lang.Exception
- Throws:
java.lang.Exception
-
retrieveArticlesPredictive
default java.util.List<DictionaryEntry> retrieveArticlesPredictive(java.util.Collection<java.lang.String> words) throws java.lang.Exception
- Throws:
java.lang.Exception
-
close
default void close() throws java.io.IOException
Dispose IDictionary. Default is no action.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.io.IOException
-
-