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.

Conditions are anchored differently for prefixes vs suffixes:

  • Suffix condition y matches stems that END with y (e.g. [^y]$)
  • Prefix condition ij matches stems that START with ij (e.g. ^ij)

Examples:

Latin script condition checking

checker = LatinScriptConditionChecker.compile('[^y]', type: :suffix)
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, type: :suffix) ⇒ 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.)

  • type (Symbol) (defaults to: :suffix)

    :suffix (anchor at end) or :prefix (anchor at start)

Returns:



29
30
31
32
33
34
35
36
37
38
# File 'lib/kotoshu/readers/condition_checker.rb', line 29

def self.compile(condition, script: :latin, type: :suffix)
  case script
  when :latin
    LatinScriptConditionChecker.compile(condition, type: type)
  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)


44
45
46
# File 'lib/kotoshu/readers/condition_checker.rb', line 44

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