Class: Kotoshu::Languages::German::GrammarRules::CompoundSpacingRule
- Defined in:
- lib/kotoshu/languages/de/language.rb
Overview
Rule: Compound word spacing (German compounds are written together).
Instance Attribute Summary
Attributes inherited from Rule
Instance Method Summary collapse
- #check(tokens) ⇒ Object
-
#initialize ⇒ CompoundSpacingRule
constructor
A new instance of CompoundSpacingRule.
Methods inherited from Rule
Constructor Details
#initialize ⇒ CompoundSpacingRule
Returns a new instance of CompoundSpacingRule.
394 395 396 |
# File 'lib/kotoshu/languages/de/language.rb', line 394 def initialize super('DE_COMPOUND_SPACING', 'Compound Spacing', 'German compound words should not have spaces.') end |
Instance Method Details
#check(tokens) ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/kotoshu/languages/de/language.rb', line 398 def check(tokens) errors = [] tokens.each_with_index do |token, idx| next unless idx < tokens.length - 1 word1 = token[:token] word2 = tokens[idx + 1][:token] next if word1.nil? || word2.nil? # Check if both are lowercase (might be parts of a compound) if word1.match?(/^[a-zäöüß]+$/) && word2.match?(/^[a-zäöüß]+$/) # Suggest they might be a compound word compound = word1 + word2 errors << { rule_id: @id, position: token[:position], message: "Possible compound word: '#{word1} #{word2}' should be '#{compound}'", suggestion: compound, context: "#{word1} #{word2}", suggestions: [compound] } end end errors end |