Class GeneratingSuggester
java.lang.Object
org.apache.lucene.analysis.hunspell.GeneratingSuggester
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 ClassesModifier and TypeClassDescriptionprivate static interface
private static class
GeneratingSuggester.Weighted<T extends Comparable<T>>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Dictionary
private final SuggestibleEntryCache
private static final int
private static final int
private static final int
private static final int
private final Hunspell
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int
affixStripLength
(int affixId) private static int
anyMismatchNgram
(int n, String s1, String s2, boolean weighted) private static int
calcThreshold
(String word) private boolean
checkAffixCondition
(int suffixId, char[] word, int offset, int length) private static int
commonCharacterPositionScore
(String s1, String s2) (package private) static int
commonPrefix
(CharSequence s1, CharSequence s2) expandRoot
(Root<String> root, String misspelled) private List
<GeneratingSuggester.Weighted<String>> expandRoots
(String misspelled, List<GeneratingSuggester.Weighted<Root<String>>> roots) private List
<GeneratingSuggester.Weighted<Root<String>>> findSimilarDictionaryEntries
(String word, WordCase originalCase) getMostRelevantSuggestions
(TreeSet<GeneratingSuggester.Weighted<String>> bySimilarity, Set<Suggestion> prevSuggestions) private boolean
hasCompatibleFlags
(Root<?> root, int affixId) private static int
indexOfSubstring
(String haystack, int haystackPos, String needle, int needlePos, int len) private static boolean
isWorseThan
(int score, CharsRef candidate, GeneratingSuggester.Weighted<Root<String>> root) private static int
private static int
longerWorsePenalty
(int length1, int length2) (package private) static int
ngramScore
(int n, String s1, String s2, boolean weighted) private void
processAffixes
(boolean prefixes, String word, GeneratingSuggester.AffixProcessor processor) private void
processAffixIds
(int affixLength, IntsRef affixIds, GeneratingSuggester.AffixProcessor processor) private void
processSuggestibleWords
(int minLength, int maxLength, BiConsumer<CharsRef, Supplier<IntsRef>> processor) private TreeSet
<GeneratingSuggester.Weighted<String>> rankBySimilarity
(String word, List<GeneratingSuggester.Weighted<String>> expanded) suggest
(String word, WordCase originalCase, Set<Suggestion> prevSuggestions)
-
Field Details
-
MAX_ROOTS
private static final int MAX_ROOTS- See Also:
-
MAX_WORDS
private static final int MAX_WORDS- See Also:
-
MAX_GUESSES
private static final int MAX_GUESSES- See Also:
-
MAX_ROOT_LENGTH_DIFF
private static final int MAX_ROOT_LENGTH_DIFF- See Also:
-
dictionary
-
speller
-
entryCache
-
-
Constructor Details
-
GeneratingSuggester
GeneratingSuggester(Hunspell speller, SuggestibleEntryCache entryCache)
-
-
Method Details
-
suggest
-
findSimilarDictionaryEntries
-
isWorseThan
private static boolean isWorseThan(int score, CharsRef candidate, GeneratingSuggester.Weighted<Root<String>> root) -
processSuggestibleWords
private void processSuggestibleWords(int minLength, int maxLength, BiConsumer<CharsRef, Supplier<IntsRef>> processor) -
expandRoots
private List<GeneratingSuggester.Weighted<String>> expandRoots(String misspelled, List<GeneratingSuggester.Weighted<Root<String>>> roots) -
calcThreshold
-
expandRoot
-
processAffixes
private void processAffixes(boolean prefixes, String word, GeneratingSuggester.AffixProcessor processor) -
processAffixIds
private void processAffixIds(int affixLength, IntsRef affixIds, GeneratingSuggester.AffixProcessor processor) -
hasCompatibleFlags
-
checkAffixCondition
private boolean checkAffixCondition(int suffixId, char[] word, int offset, int length) -
affixStripLength
private int affixStripLength(int affixId) -
rankBySimilarity
private TreeSet<GeneratingSuggester.Weighted<String>> rankBySimilarity(String word, List<GeneratingSuggester.Weighted<String>> expanded) -
getMostRelevantSuggestions
private List<String> getMostRelevantSuggestions(TreeSet<GeneratingSuggester.Weighted<String>> bySimilarity, Set<Suggestion> prevSuggestions) -
commonPrefix
-
ngramScore
-
longerWorsePenalty
private static int longerWorsePenalty(int length1, int length2) -
anyMismatchNgram
-
indexOfSubstring
-
lcs
-
commonCharacterPositionScore
-