Class Suggester
- java.lang.Object
-
- org.apache.lucene.analysis.hunspell.Suggester
-
public class Suggester extends java.lang.Object
A generator for misspelled word corrections based on Hunspell flags. The suggestions are searched for in two main ways:- Modification: trying to insert/remove/delete/swap parts of the word to get something
acceptable. The performance of this part depends heavily on the contents of TRY, MAP, REP,
KEY directives in the .aff file. To speed up this part, consider using
withFragmentChecker(org.apache.lucene.analysis.hunspell.FragmentChecker)
. - Enumeration: if the modification hasn't produced "good enough" suggestions, the whole
dictionary is scanned and simple affixes are added onto the entries to check if that
produces anything similar to the given misspelled word. This depends on the dictionary size
and the affix count, and it can take noticeable amount of time. To speed this up,
withSuggestibleEntryCache()
can be used.
- Modification: trying to insert/remove/delete/swap parts of the word to get something
acceptable. The performance of this part depends heavily on the contents of TRY, MAP, REP,
KEY directives in the .aff file. To speed up this part, consider using
-
-
Field Summary
Fields Modifier and Type Field Description private Dictionary
dictionary
private FragmentChecker
fragmentChecker
private SuggestibleEntryCache
suggestibleCache
-
Constructor Summary
Constructors Modifier Constructor Description Suggester(Dictionary dictionary)
private
Suggester(Dictionary dictionary, SuggestibleEntryCache suggestibleCache, FragmentChecker checker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.Runnable
checkTimeLimit(java.lang.String word, java.util.Set<Suggestion> suggestions, long timeLimitMs, java.lang.Runnable checkCanceled)
private java.lang.Runnable
handleCustomTimeoutException(java.lang.Runnable checkCanceled, java.util.LinkedHashSet<Suggestion> suggestions)
private java.util.List<java.lang.String>
modifyChunksBetweenDashes(java.lang.String word, Hunspell speller, java.lang.Runnable checkCanceled)
private java.util.List<java.lang.String>
postprocess(java.util.Collection<Suggestion> suggestions)
private java.util.List<java.lang.String>
suggest(java.lang.String word, java.util.LinkedHashSet<Suggestion> suggestions, java.lang.Runnable checkCanceled)
java.util.List<java.lang.String>
suggestNoTimeout(java.lang.String word, java.lang.Runnable checkCanceled)
Compute suggestions for the given misspelled wordjava.util.List<java.lang.String>
suggestWithTimeout(java.lang.String word, long timeLimitMs, java.lang.Runnable checkCanceled)
Suggester
withFragmentChecker(FragmentChecker checker)
Returns a copy of this suggester instance withFragmentChecker
hint that can improve the performance of the "Modification" phase performance.Suggester
withSuggestibleEntryCache()
Returns a copy of this suggester instance with better "Enumeration" phase performance (seeSuggester
documentation), but using more memory.
-
-
-
Field Detail
-
dictionary
private final Dictionary dictionary
-
suggestibleCache
private final SuggestibleEntryCache suggestibleCache
-
fragmentChecker
private final FragmentChecker fragmentChecker
-
-
Constructor Detail
-
Suggester
public Suggester(Dictionary dictionary)
-
Suggester
private Suggester(Dictionary dictionary, SuggestibleEntryCache suggestibleCache, FragmentChecker checker)
-
-
Method Detail
-
withSuggestibleEntryCache
public Suggester withSuggestibleEntryCache()
Returns a copy of this suggester instance with better "Enumeration" phase performance (seeSuggester
documentation), but using more memory. With this option, the dictionary entries are stored as fast-to-iterate plain words instead of highly compressed prefix trees.
-
withFragmentChecker
public Suggester withFragmentChecker(FragmentChecker checker)
Returns a copy of this suggester instance withFragmentChecker
hint that can improve the performance of the "Modification" phase performance.
-
suggestNoTimeout
public java.util.List<java.lang.String> suggestNoTimeout(java.lang.String word, java.lang.Runnable checkCanceled)
Compute suggestions for the given misspelled word- Parameters:
word
- the misspelled word to calculate suggestions forcheckCanceled
- an object that's periodically called, allowing to interrupt or suggestion generation by throwing an exception
-
handleCustomTimeoutException
private java.lang.Runnable handleCustomTimeoutException(java.lang.Runnable checkCanceled, java.util.LinkedHashSet<Suggestion> suggestions)
-
suggestWithTimeout
public java.util.List<java.lang.String> suggestWithTimeout(java.lang.String word, long timeLimitMs, java.lang.Runnable checkCanceled) throws SuggestionTimeoutException
- Parameters:
word
- the misspelled word to calculate suggestions fortimeLimitMs
- the duration limit in milliseconds after which the computation is interruped by an exceptioncheckCanceled
- an object that's periodically called, allowing to interrupt or suggestion generation by throwing an exception- Throws:
SuggestionTimeoutException
- if the computation takes too long. UseSuggestionTimeoutException.getPartialResult()
to get the suggestions computed up to that point
-
suggest
private java.util.List<java.lang.String> suggest(java.lang.String word, java.util.LinkedHashSet<Suggestion> suggestions, java.lang.Runnable checkCanceled) throws SuggestionTimeoutException
- Throws:
SuggestionTimeoutException
-
checkTimeLimit
private java.lang.Runnable checkTimeLimit(java.lang.String word, java.util.Set<Suggestion> suggestions, long timeLimitMs, java.lang.Runnable checkCanceled)
-
postprocess
private java.util.List<java.lang.String> postprocess(java.util.Collection<Suggestion> suggestions)
-
modifyChunksBetweenDashes
private java.util.List<java.lang.String> modifyChunksBetweenDashes(java.lang.String word, Hunspell speller, java.lang.Runnable checkCanceled)
-
-