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



26
27
28
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 26

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: [] }



34
35
36
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 34

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



53
54
55
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 53

def correct?(_word)
  true
end

#passthrough?Boolean

Check if this is a passthrough checker.

Returns:

  • (Boolean)

    Always true for this class



67
68
69
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 67

def passthrough?
  true
end

#reasonString

Get the reason why spell checking is not used.

Returns:

  • (String)

    Reason text



60
61
62
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 60

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



45
46
47
# File 'lib/kotoshu/components/passthrough_spell_checker.rb', line 45

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