Class GeneratingSuggester
- java.lang.Object
-
- org.apache.lucene.analysis.hunspell.GeneratingSuggester
-
class GeneratingSuggester extends java.lang.Object
A class that traverses the entire dictionary and applies affix rules to check if those yield correct suggestions similar enough to the given misspelled word
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
GeneratingSuggester.AffixProcessor
private static class
GeneratingSuggester.Weighted<T extends java.lang.Comparable<T>>
-
Field Summary
Fields Modifier and Type Field Description private Dictionary
dictionary
private SuggestibleEntryCache
entryCache
private static int
MAX_GUESSES
private static int
MAX_ROOT_LENGTH_DIFF
private static int
MAX_ROOTS
private static int
MAX_WORDS
private Hunspell
speller
-
Constructor Summary
Constructors Constructor Description GeneratingSuggester(Hunspell speller, SuggestibleEntryCache entryCache)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
affixStripLength(int affixId)
private static int
anyMismatchNgram(int n, java.lang.String s1, java.lang.String s2, boolean weighted)
private static int
calcThreshold(java.lang.String word)
private boolean
checkAffixCondition(int suffixId, char[] word, int offset, int length)
private static int
commonCharacterPositionScore(java.lang.String s1, java.lang.String s2)
(package private) static int
commonPrefix(java.lang.CharSequence s1, java.lang.CharSequence s2)
private java.util.List<java.lang.String>
expandRoot(Root<java.lang.String> root, java.lang.String misspelled)
private java.util.List<GeneratingSuggester.Weighted<java.lang.String>>
expandRoots(java.lang.String misspelled, java.util.List<GeneratingSuggester.Weighted<Root<java.lang.String>>> roots)
private java.util.List<GeneratingSuggester.Weighted<Root<java.lang.String>>>
findSimilarDictionaryEntries(java.lang.String word, WordCase originalCase)
private java.util.List<java.lang.String>
getMostRelevantSuggestions(java.util.TreeSet<GeneratingSuggester.Weighted<java.lang.String>> bySimilarity, java.util.Set<Suggestion> prevSuggestions)
private boolean
hasCompatibleFlags(Root<?> root, int affixId)
private static int
indexOfSubstring(java.lang.String haystack, int haystackPos, java.lang.String needle, int needlePos, int len)
private static boolean
isWorseThan(int score, CharsRef candidate, GeneratingSuggester.Weighted<Root<java.lang.String>> root)
private static int
lcs(java.lang.String s1, java.lang.String s2)
private static int
longerWorsePenalty(int length1, int length2)
(package private) static int
ngramScore(int n, java.lang.String s1, java.lang.String s2, boolean weighted)
private void
processAffixes(boolean prefixes, java.lang.String word, GeneratingSuggester.AffixProcessor processor)
private void
processAffixIds(int affixLength, IntsRef affixIds, GeneratingSuggester.AffixProcessor processor)
private void
processSuggestibleWords(int minLength, int maxLength, java.util.function.BiConsumer<CharsRef,java.util.function.Supplier<IntsRef>> processor)
private java.util.TreeSet<GeneratingSuggester.Weighted<java.lang.String>>
rankBySimilarity(java.lang.String word, java.util.List<GeneratingSuggester.Weighted<java.lang.String>> expanded)
(package private) java.util.List<java.lang.String>
suggest(java.lang.String word, WordCase originalCase, java.util.Set<Suggestion> prevSuggestions)
-
-
-
Field Detail
-
MAX_ROOTS
private static final int MAX_ROOTS
- See Also:
- Constant Field Values
-
MAX_WORDS
private static final int MAX_WORDS
- See Also:
- Constant Field Values
-
MAX_GUESSES
private static final int MAX_GUESSES
- See Also:
- Constant Field Values
-
MAX_ROOT_LENGTH_DIFF
private static final int MAX_ROOT_LENGTH_DIFF
- See Also:
- Constant Field Values
-
dictionary
private final Dictionary dictionary
-
speller
private final Hunspell speller
-
entryCache
private final SuggestibleEntryCache entryCache
-
-
Constructor Detail
-
GeneratingSuggester
GeneratingSuggester(Hunspell speller, SuggestibleEntryCache entryCache)
-
-
Method Detail
-
suggest
java.util.List<java.lang.String> suggest(java.lang.String word, WordCase originalCase, java.util.Set<Suggestion> prevSuggestions)
-
findSimilarDictionaryEntries
private java.util.List<GeneratingSuggester.Weighted<Root<java.lang.String>>> findSimilarDictionaryEntries(java.lang.String word, WordCase originalCase)
-
isWorseThan
private static boolean isWorseThan(int score, CharsRef candidate, GeneratingSuggester.Weighted<Root<java.lang.String>> root)
-
processSuggestibleWords
private void processSuggestibleWords(int minLength, int maxLength, java.util.function.BiConsumer<CharsRef,java.util.function.Supplier<IntsRef>> processor)
-
expandRoots
private java.util.List<GeneratingSuggester.Weighted<java.lang.String>> expandRoots(java.lang.String misspelled, java.util.List<GeneratingSuggester.Weighted<Root<java.lang.String>>> roots)
-
calcThreshold
private static int calcThreshold(java.lang.String word)
-
expandRoot
private java.util.List<java.lang.String> expandRoot(Root<java.lang.String> root, java.lang.String misspelled)
-
processAffixes
private void processAffixes(boolean prefixes, java.lang.String word, GeneratingSuggester.AffixProcessor processor)
-
processAffixIds
private void processAffixIds(int affixLength, IntsRef affixIds, GeneratingSuggester.AffixProcessor processor)
-
hasCompatibleFlags
private boolean hasCompatibleFlags(Root<?> root, int affixId)
-
checkAffixCondition
private boolean checkAffixCondition(int suffixId, char[] word, int offset, int length)
-
affixStripLength
private int affixStripLength(int affixId)
-
rankBySimilarity
private java.util.TreeSet<GeneratingSuggester.Weighted<java.lang.String>> rankBySimilarity(java.lang.String word, java.util.List<GeneratingSuggester.Weighted<java.lang.String>> expanded)
-
getMostRelevantSuggestions
private java.util.List<java.lang.String> getMostRelevantSuggestions(java.util.TreeSet<GeneratingSuggester.Weighted<java.lang.String>> bySimilarity, java.util.Set<Suggestion> prevSuggestions)
-
commonPrefix
static int commonPrefix(java.lang.CharSequence s1, java.lang.CharSequence s2)
-
ngramScore
static int ngramScore(int n, java.lang.String s1, java.lang.String s2, boolean weighted)
-
longerWorsePenalty
private static int longerWorsePenalty(int length1, int length2)
-
anyMismatchNgram
private static int anyMismatchNgram(int n, java.lang.String s1, java.lang.String s2, boolean weighted)
-
indexOfSubstring
private static int indexOfSubstring(java.lang.String haystack, int haystackPos, java.lang.String needle, int needlePos, int len)
-
lcs
private static int lcs(java.lang.String s1, java.lang.String s2)
-
commonCharacterPositionScore
private static int commonCharacterPositionScore(java.lang.String s1, java.lang.String s2)
-
-