Class: Kotoshu::Languages::Portuguese::SpellChecker
- Inherits:
-
Components::SpellChecker
- Object
- Components::SpellChecker
- Kotoshu::Languages::Portuguese::SpellChecker
- Defined in:
- lib/kotoshu/languages/pt/language.rb
Overview
Portuguese spell checker with Hunspell integration.
Constant Summary collapse
- PORTUGUESE_SUBSTITUTIONS =
Portuguese-specific character substitutions
{ 'á' => %w[a], 'â' => %w[a], 'ã' => %w[a], 'à' => %w[a], 'é' => %w[e], 'ê' => %w[e], 'í' => %w[i], 'ó' => %w[o], 'ô' => %w[o], 'õ' => %w[o], 'ú' => %w[u], 'ü' => %w[u], 'ç' => %w[c], }.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/pt/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.
19 20 21 |
# File 'lib/kotoshu/languages/pt/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/pt/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/pt/language.rb', line 19 def script @script end |
Instance Method Details
#check(word) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/kotoshu/languages/pt/language.rb', line 46 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
63 64 65 |
# File 'lib/kotoshu/languages/pt/language.rb', line 63 def correct?(word) check(word)[:found] end |
#lookuper ⇒ Object
67 68 69 |
# File 'lib/kotoshu/languages/pt/language.rb', line 67 def lookuper @lookuper end |
#suggest(word, max_suggestions: 10) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/kotoshu/languages/pt/language.rb', line 56 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 |