Class: Kotoshu::Languages::English::SpellChecker
- Inherits:
-
Components::SpellChecker
- Object
- Components::SpellChecker
- Kotoshu::Languages::English::SpellChecker
- Defined in:
- lib/kotoshu/languages/en/language.rb
Overview
English spell checker.
Uses the Lookup algorithm with Hunspell-format dictionaries.
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: 'ISO-8859-1') ⇒ 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: 'ISO-8859-1') ⇒ SpellChecker
Returns a new instance of SpellChecker.
32 33 34 35 36 37 38 |
# File 'lib/kotoshu/languages/en/language.rb', line 32 def initialize(aff_path:, dic_path:, script: :latin, encoding: 'ISO-8859-1') @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.
30 31 32 |
# File 'lib/kotoshu/languages/en/language.rb', line 30 def aff_path @aff_path end |
#dic_path ⇒ Object (readonly)
Returns the value of attribute dic_path.
30 31 32 |
# File 'lib/kotoshu/languages/en/language.rb', line 30 def dic_path @dic_path end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
30 31 32 |
# File 'lib/kotoshu/languages/en/language.rb', line 30 def script @script end |
Instance Method Details
#check(word) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/kotoshu/languages/en/language.rb', line 40 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
57 58 59 |
# File 'lib/kotoshu/languages/en/language.rb', line 57 def correct?(word) check(word)[:found] end |
#lookuper ⇒ Object
61 62 63 |
# File 'lib/kotoshu/languages/en/language.rb', line 61 def lookuper @lookuper end |
#suggest(word, max_suggestions: 10) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/kotoshu/languages/en/language.rb', line 50 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 |