Class: Kotoshu::Components::PassthroughSpellChecker

Inherits:
SpellChecker
  • Object
show all
Defined in:
lib/kotoshu/components/passthrough_spell_checker.rb

Overview

Passthrough spell checker for languages that don't use spell checking.

This checker always returns that words are "found" (correct). It's used for languages that don't have traditional spell checking, such as:

  • CJK languages (Japanese, Chinese) - use confusion rules instead
  • Languages with purely rule-based checking

Examples:

checker = PassthroughSpellChecker.new
result = checker.check('任意のテキスト')
# => { found: true, stem: nil, flags: [] }

Getting suggestions (always empty)

suggestions = checker.suggest('テキスト')
# => []

Instance Method Summary collapse

Constructor Details

#initialize(reason: nil) ⇒ PassthroughSpellChecker

Create a new passthrough spell checker.

Parameters:

  • reason (String) (defaults to: nil)

    Optional reason why spell checking is not used



24
25
26
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 24

def initialize(reason: nil)
  @reason = reason || "Language does not use spell checking"
end

Instance Method Details

#check(_word) ⇒ Hash

Always returns that the word is "found" (correct).

Parameters:

  • _word (String)

    The word to check (ignored)

Returns:

  • (Hash)

    Always returns { found: true, stem: nil, flags: [] }



32
33
34
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 32

def check(_word)
  { found: true, stem: nil, flags: [] }
end

#correct?(_word) ⇒ Boolean

Always returns true (all words are "correct").

Parameters:

  • _word (String)

    The word to check (ignored)

Returns:

  • (Boolean)

    Always true



51
52
53
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 51

def correct?(_word)
  true
end

#passthrough?Boolean

Check if this is a passthrough checker.

Returns:

  • (Boolean)

    Always true for this class



65
66
67
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 65

def passthrough?
  true
end

#reasonString

Get the reason why spell checking is not used.

Returns:

  • (String)

    Reason text



58
59
60
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 58

def reason
  @reason
end

#suggest(_word, _max_suggestions: 10) ⇒ Array<Hash>

Returns no suggestions.

Passthrough spell checkers don't provide suggestions.

Parameters:

  • _word (String)

    The word (ignored)

  • _max_suggestions (Integer) (defaults to: 10)

    Max suggestions (ignored)

Returns:

  • (Array<Hash>)

    Always returns empty array



43
44
45
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 43

def suggest(_word, _max_suggestions: 10)
  []
end