Class: Kotoshu::Languages::Japanese::SpellChecker
- Inherits:
-
Components::SpellChecker
- Object
- Components::SpellChecker
- Kotoshu::Languages::Japanese::SpellChecker
- Defined in:
- lib/kotoshu/languages/ja/language.rb
Overview
Japanese spell checker using dictionary lookup.
Japanese uses morphological analysis rather than traditional Hunspell dictionaries. Spell checking is done through dictionary lookup of segmented words from the morphological analyzer.
Instance Attribute Summary collapse
-
#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(dic_path:, script: :cjk) ⇒ SpellChecker
constructor
A new instance of SpellChecker.
- #suggest(word, max_suggestions: 10) ⇒ Object
Constructor Details
#initialize(dic_path:, script: :cjk) ⇒ SpellChecker
Returns a new instance of SpellChecker.
25 26 27 28 29 30 31 |
# File 'lib/kotoshu/languages/ja/language.rb', line 25 def initialize(dic_path:, script: :cjk) @dic_path = dic_path @script = script # Japanese dictionaries are typically in custom formats # Load dictionary into memory for fast lookup @dictionary = load_dictionary(dic_path) end |
Instance Attribute Details
#dic_path ⇒ Object (readonly)
Returns the value of attribute dic_path.
23 24 25 |
# File 'lib/kotoshu/languages/ja/language.rb', line 23 def dic_path @dic_path end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
23 24 25 |
# File 'lib/kotoshu/languages/ja/language.rb', line 23 def script @script end |
Instance Method Details
#check(word) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kotoshu/languages/ja/language.rb', line 33 def check(word) return { found: false, stem: nil, flags: [] } if word.nil? || word.empty? # Check if word exists in dictionary found = @dictionary.include?(word) if found { found: true, stem: word, flags: [] } else # For CJK text, we might want to check if it contains valid characters # but not actual word validation { found: false, stem: nil, flags: [] } end end |
#correct?(word) ⇒ Boolean
56 57 58 |
# File 'lib/kotoshu/languages/ja/language.rb', line 56 def correct?(word) check(word)[:found] end |
#suggest(word, max_suggestions: 10) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/kotoshu/languages/ja/language.rb', line 48 def suggest(word, max_suggestions: 10) return [] if word.nil? || word.empty? return [] if @dictionary.include?(word) # Generate suggestions based on common Japanese errors generate_suggestions(word, max_suggestions).take(max_suggestions) end |