Class: Kotoshu::Languages::Russian::SpellChecker
- Inherits:
-
Components::SpellChecker
- Object
- Components::SpellChecker
- Kotoshu::Languages::Russian::SpellChecker
- Defined in:
- lib/kotoshu/languages/ru/language.rb
Overview
Russian spell checker with Hunspell integration.
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: :cyrillic, 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: :cyrillic, encoding: 'UTF-8') ⇒ SpellChecker
Returns a new instance of SpellChecker.
21 22 23 24 25 26 27 |
# File 'lib/kotoshu/languages/ru/language.rb', line 21 def initialize(aff_path:, dic_path:, script: :cyrillic, 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.
19 20 21 |
# File 'lib/kotoshu/languages/ru/language.rb', line 19 def aff_path @aff_path end |
#dic_path ⇒ Object (readonly)
Returns the value of attribute dic_path.
19 20 21 |
# File 'lib/kotoshu/languages/ru/language.rb', line 19 def dic_path @dic_path end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
19 20 21 |
# File 'lib/kotoshu/languages/ru/language.rb', line 19 def script @script end |
Instance Method Details
#check(word) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/kotoshu/languages/ru/language.rb', line 29 def check(word) return { found: false, stem: nil, flags: [] } if word.nil? || word.empty? first_form = @lookuper.good_forms(word).first if first_form { found: true, stem: first_form.stem || word, flags: first_form.flags&.to_a || [] } else { found: false, stem: nil, flags: [] } end end |
#correct?(word) ⇒ Boolean
46 47 48 |
# File 'lib/kotoshu/languages/ru/language.rb', line 46 def correct?(word) check(word)[:found] end |
#lookuper ⇒ Object
50 51 52 |
# File 'lib/kotoshu/languages/ru/language.rb', line 50 def lookuper @lookuper end |
#suggest(word, max_suggestions: 10) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/kotoshu/languages/ru/language.rb', line 39 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 |