Class: Kotoshu::Languages::French::SpellChecker

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

Overview

French spell checker with Hunspell integration.

Uses the Lookup algorithm with Hunspell-format dictionaries and French-specific character handling (accents, ligatures).

Constant Summary collapse

FRENCH_SUBSTITUTIONS =

French-specific character substitutions for suggestions

{
  'à' => %w[a],
  'â' => %w[a],
  'ä' => %w[a],
  'é' => %w[e],
  'è' => %w[e],
  'ê' => %w[e],
  'ë' => %w[e],
  'î' => %w[i],
  'ï' => %w[i],
  'ô' => %w[o],
  'ö' => %w[o],
  'ù' => %w[u],
  'û' => %w[u],
  'ü' => %w[u],
  'ç' => %w[c],
  'œ' => %w[oe],
  'æ' => %w[ae],
  # Common French errors
  'c' => %w[ç],  # garçon vs garcon
  'e' => %w[é è ê],  # café vs caffe
  'a' => %w[à],  # à vs a
}.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.



48
49
50
51
52
53
54
# File 'lib/kotoshu/languages/fr/language.rb', line 48

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.



21
22
23
# File 'lib/kotoshu/languages/fr/language.rb', line 21

def aff_path
  @aff_path
end

#dic_pathObject (readonly)

Returns the value of attribute dic_path.



21
22
23
# File 'lib/kotoshu/languages/fr/language.rb', line 21

def dic_path
  @dic_path
end

#scriptObject (readonly)

Returns the value of attribute script.



21
22
23
# File 'lib/kotoshu/languages/fr/language.rb', line 21

def script
  @script
end

Instance Method Details

#check(word) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/kotoshu/languages/fr/language.rb', line 56

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)


73
74
75
# File 'lib/kotoshu/languages/fr/language.rb', line 73

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

#lookuperObject



77
78
79
# File 'lib/kotoshu/languages/fr/language.rb', line 77

def lookuper
  @lookuper
end

#suggest(word, max_suggestions: 10) ⇒ Object



66
67
68
69
70
71
# File 'lib/kotoshu/languages/fr/language.rb', line 66

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