Class: Kotoshu::Readers::ConditionChecker Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/readers/condition_checker.rb

Overview

This class is abstract.

Subclasses must implement the matches? method

Base class for checking affix conditions.

Hunspell affix rules specify conditions that the stem must match before an affix can be applied. Different scripts may have different interpretations of these conditions.

Examples:

Latin script condition checking

checker = LatinScriptConditionChecker.compile('[^y]')
checker.matches?('try')  # => true (doesn't end with 'y')
checker.matches?('fly')  # => false (ends with 'y')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.compile(condition, script: :latin) ⇒ ConditionChecker

Compile a condition string into a checker.

Parameters:

  • condition (String)

    The condition string from .aff file

  • script (Symbol) (defaults to: :latin)

    The script type (:latin, :arabic, :hebrew, etc.)

Returns:



23
24
25
26
27
28
29
30
31
32
# File 'lib/kotoshu/readers/condition_checker.rb', line 23

def self.compile(condition, script: :latin)
  case script
  when :latin
    LatinScriptConditionChecker.compile(condition)
  else
    # For other scripts, create a passthrough checker
    # (condition is not applied)
    PassthroughConditionChecker.new
  end
end

Instance Method Details

#matches?(stem) ⇒ Boolean

Check if the given stem matches this condition.

Parameters:

  • stem (String)

    The stem to check

Returns:

  • (Boolean)

    True if the stem matches

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/kotoshu/readers/condition_checker.rb', line 38

def matches?(stem)
  raise NotImplementedError, "#{self.class} must implement #matches?"
end