Class: Kotoshu::Languages::Spanish::SpellChecker

Inherits:
Components::SpellChecker show all
Defined in:
lib/kotoshu/languages/es/language.rb

Overview

Spanish spell checker with Hunspell integration.

Constant Summary collapse

SPANISH_SUBSTITUTIONS =

Spanish-specific character substitutions

{
  'á' => %w[a],
  'é' => %w[e],
  'í' => %w[i],
  'ó' => %w[o],
  'ú' => %w[u],
  'ü' => %w[u],
  'ñ' => %w[n],
  '¿' => [],
  '¡' => [],
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aff_path:, dic_path:, script: :latin, encoding: 'UTF-8') ⇒ SpellChecker

Returns a new instance of SpellChecker.



34
35
36
37
38
39
40
# File 'lib/kotoshu/languages/es/language.rb', line 34

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_pathObject (readonly)

Returns the value of attribute aff_path.



19
20
21
# File 'lib/kotoshu/languages/es/language.rb', line 19

def aff_path
  @aff_path
end

#dic_pathObject (readonly)

Returns the value of attribute dic_path.



19
20
21
# File 'lib/kotoshu/languages/es/language.rb', line 19

def dic_path
  @dic_path
end

#scriptObject (readonly)

Returns the value of attribute script.



19
20
21
# File 'lib/kotoshu/languages/es/language.rb', line 19

def script
  @script
end

Instance Method Details

#check(word) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/kotoshu/languages/es/language.rb', line 42

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

Returns:

  • (Boolean)


59
60
61
# File 'lib/kotoshu/languages/es/language.rb', line 59

def correct?(word)
  check(word)[:found]
end

#lookuperObject



63
64
65
# File 'lib/kotoshu/languages/es/language.rb', line 63

def lookuper
  @lookuper
end

#suggest(word, max_suggestions: 10) ⇒ Object



52
53
54
55
56
57
# File 'lib/kotoshu/languages/es/language.rb', line 52

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