Class: Kotoshu::Components::SpellChecker Abstract
- Inherits:
-
Object
- Object
- Kotoshu::Components::SpellChecker
- Defined in:
- lib/kotoshu/components/spell_checker.rb
Overview
Subclasses must implement #check and #suggest
Base class for spell checkers.
Spell checkers validate words and provide suggestions for misspelled words. Different languages use different spell checking strategies:
-
Latin scripts: Dictionary lookup (Hunspell, Morfologik)
-
CJK: Confusion rule checking (no dictionary)
-
RTL: Dictionary lookup with bidirectional text handling
Direct Known Subclasses
PassthroughSpellChecker, Languages::English::SpellChecker, Languages::French::SpellChecker, Languages::German::SpellChecker, Languages::Japanese::SpellChecker, Languages::Portuguese::SpellChecker, Languages::Russian::SpellChecker, Languages::Spanish::SpellChecker
Instance Method Summary collapse
-
#check(word) ⇒ Hash
abstract
Check if a word is spelled correctly.
-
#correct?(word) ⇒ Boolean
Check if a word is spelled correctly.
-
#suggest(word, max_suggestions: 10) ⇒ Array<Hash>
abstract
Get spelling suggestions for a misspelled word.
Instance Method Details
#check(word) ⇒ Hash
Subclasses must implement
Check if a word is spelled correctly.
Returns a hash with:
-
:found (Boolean) - true if word is in dictionary
-
:stem (String, nil) - The stem/lemma if found
-
:flags (Array<String>) - Morphological flags
40 41 42 |
# File 'lib/kotoshu/components/spell_checker.rb', line 40 def check(word) raise NotImplementedError, "#{self.class} must implement #check" end |
#correct?(word) ⇒ Boolean
Check if a word is spelled correctly.
Convenience method that returns a boolean.
68 69 70 |
# File 'lib/kotoshu/components/spell_checker.rb', line 68 def correct?(word) check(word)[:found] end |
#suggest(word, max_suggestions: 10) ⇒ Array<Hash>
Subclasses must implement
Get spelling suggestions for a misspelled word.
Returns an array of suggestion hashes with:
-
:word (String) - The suggested word
-
:distance (Integer) - Edit distance from original word
-
:score (Float) - Confidence score (0-1, higher is better)
Suggestions are sorted by relevance (highest score first).
58 59 60 |
# File 'lib/kotoshu/components/spell_checker.rb', line 58 def suggest(word, max_suggestions: 10) raise NotImplementedError, "#{self.class} must implement #suggest" end |