Class: Kotoshu::Readers::LatinScriptConditionChecker
- Inherits:
-
ConditionChecker
- Object
- ConditionChecker
- Kotoshu::Readers::LatinScriptConditionChecker
- Defined in:
- lib/kotoshu/readers/condition_checker.rb
Overview
Condition checker for Latin-script dictionaries.
Hunspell conditions are regex-like patterns. Spylls compiles them
verbatim (with - escaped so it doesn't become a range inside an
unintended context) into a regex anchored at the start (for prefixes)
or end (for suffixes), and uses re.search to test.
Examples (suffix unless noted):
- '.' matches any stem (regex: /.$/ finds end-of-string)
- 'y' matches stems ending with 'y' (regex: /y$/)
- '[^y]' matches stems NOT ending with 'y' (regex: /[^y]$/)
- '[aeiou]y' matches stems ending with vowel + 'y' (regex: /[aeiou]y$/)
- '.[^aeiou]y' matches stems whose last 3 chars are any-non-vowel-y
- 'wr.' (prefix) matches stems starting with 'wr' + any char
This is NOT suitable for RTL scripts or CJK languages.
Instance Attribute Summary collapse
-
#anchor ⇒ Object
readonly
Returns the value of attribute anchor.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.compile(condition, type: :suffix) ⇒ LatinScriptConditionChecker
Compile a condition string.
Instance Method Summary collapse
-
#initialize(condition:, type:, anchor:) ⇒ LatinScriptConditionChecker
constructor
A new instance of LatinScriptConditionChecker.
-
#matches?(stem) ⇒ Boolean
Check if the stem matches the condition.
Constructor Details
#initialize(condition:, type:, anchor:) ⇒ LatinScriptConditionChecker
Returns a new instance of LatinScriptConditionChecker.
87 88 89 90 91 92 |
# File 'lib/kotoshu/readers/condition_checker.rb', line 87 def initialize(condition:, type:, anchor:) @condition = condition @type = type @anchor = anchor @pattern = compile_pattern end |
Instance Attribute Details
#anchor ⇒ Object (readonly)
Returns the value of attribute anchor.
75 76 77 |
# File 'lib/kotoshu/readers/condition_checker.rb', line 75 def anchor @anchor end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
75 76 77 |
# File 'lib/kotoshu/readers/condition_checker.rb', line 75 def condition @condition end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
75 76 77 |
# File 'lib/kotoshu/readers/condition_checker.rb', line 75 def pattern @pattern end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
75 76 77 |
# File 'lib/kotoshu/readers/condition_checker.rb', line 75 def type @type end |
Class Method Details
.compile(condition, type: :suffix) ⇒ LatinScriptConditionChecker
Compile a condition string.
82 83 84 85 |
# File 'lib/kotoshu/readers/condition_checker.rb', line 82 def self.compile(condition, type: :suffix) anchor = type == :prefix ? :start : :ending new(condition: condition, type: type, anchor: anchor) end |
Instance Method Details
#matches?(stem) ⇒ Boolean
Check if the stem matches the condition.
98 99 100 101 102 |
# File 'lib/kotoshu/readers/condition_checker.rb', line 98 def matches?(stem) return true if @condition.nil? || @condition.empty? || @condition == '.' @pattern.match?(stem) end |