Class: Kotoshu::Languages::German::SpellChecker
- Inherits:
-
Components::SpellChecker
- Object
- Components::SpellChecker
- Kotoshu::Languages::German::SpellChecker
- Defined in:
- lib/kotoshu/languages/de/language.rb
Overview
German spell checker with Hunspell integration.
Uses the Lookup algorithm with Hunspell-format dictionaries and handles German-specific features (umlauts, ß, compound words).
Constant Summary collapse
- GERMAN_SUBSTITUTIONS =
German-specific character substitutions for suggestions
{ # Umlauts 'ä' => %w[a ae], 'ö' => %w[o oe], 'ü' => %w[u ue], 'ß' => %w[ss sz], # Common German errors 'a' => %w[ä], 'o' => %w[ö], 'u' => %w[ü], 's' => %w[ß], }.freeze
Instance Attribute Summary collapse
-
#aff_path ⇒ Object
readonly
Returns the value of attribute aff_path.
-
#dic_path ⇒ Object
readonly
Returns the value of attribute dic_path.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Instance Method Summary collapse
- #check(word) ⇒ Object
- #correct?(word) ⇒ Boolean
-
#initialize(aff_path:, dic_path:, script: :latin, encoding: 'UTF-8') ⇒ SpellChecker
constructor
A new instance of SpellChecker.
- #lookuper ⇒ Object
- #suggest(word, max_suggestions: 10) ⇒ Object
Constructor Details
#initialize(aff_path:, dic_path:, script: :latin, encoding: 'UTF-8') ⇒ SpellChecker
Returns a new instance of SpellChecker.
38 39 40 41 42 43 44 |
# File 'lib/kotoshu/languages/de/language.rb', line 38 def initialize(aff_path:, dic_path:, script: :latin, encoding: 'UTF-8') @aff_path = aff_path @dic_path = dic_path @script = script @encoding = encoding @lookuper = Readers::LookupBuilder.new(aff_path, dic_path, encoding: encoding, script: script).build end |
Instance Attribute Details
#aff_path ⇒ Object (readonly)
Returns the value of attribute aff_path.
22 23 24 |
# File 'lib/kotoshu/languages/de/language.rb', line 22 def aff_path @aff_path end |
#dic_path ⇒ Object (readonly)
Returns the value of attribute dic_path.
22 23 24 |
# File 'lib/kotoshu/languages/de/language.rb', line 22 def dic_path @dic_path end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
22 23 24 |
# File 'lib/kotoshu/languages/de/language.rb', line 22 def script @script end |
Instance Method Details
#check(word) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kotoshu/languages/de/language.rb', line 46 def check(word) return { found: false, stem: nil, flags: [] } if word.nil? || word.empty? # Try exact match first first_form = @lookuper.good_forms(word).first return { found: true, stem: first_form.stem || word, flags: first_form.flags&.to_a || [] } if first_form # Try lowercase version (German nouns are capitalized) unless word == word.downcase lowercase_form = @lookuper.good_forms(word.downcase).first if lowercase_form return { found: true, stem: lowercase_form.stem || word.downcase, flags: lowercase_form.flags&.to_a || [] } end end { found: false, stem: nil, flags: [] } end |
#correct?(word) ⇒ Boolean
70 71 72 |
# File 'lib/kotoshu/languages/de/language.rb', line 70 def correct?(word) check(word)[:found] end |
#lookuper ⇒ Object
74 75 76 |
# File 'lib/kotoshu/languages/de/language.rb', line 74 def lookuper @lookuper end |
#suggest(word, max_suggestions: 10) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/kotoshu/languages/de/language.rb', line 63 def suggest(word, max_suggestions: 10) return [] if word.nil? || word.empty? first_form = @lookuper.good_forms(word).first return [] if first_form generate_suggestions(word, max_suggestions).take(max_suggestions) end |