Class: Kotoshu::Languages::French::GrammarRules::FrenchNegationRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/kotoshu/languages/fr/language.rb

Overview

Rule: Double negation in French (correct usage).

Constant Summary collapse

NEGATION_PARTICLES =
%w[ne n'].freeze
SECOND_PARTICLES =
%w[pas plus jamais rien personne].freeze

Instance Attribute Summary

Attributes inherited from Rule

#description, #id, #name

Instance Method Summary collapse

Methods inherited from Rule

#applies?

Constructor Details

#initializeFrenchNegationRule

Returns a new instance of FrenchNegationRule.



343
344
345
# File 'lib/kotoshu/languages/fr/language.rb', line 343

def initialize
  super('FR_NEGATION', 'French Negation', 'French uses double negation (ne...pas).')
end

Instance Method Details

#check(tokens) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/kotoshu/languages/fr/language.rb', line 347

def check(tokens)
  errors = []
  tokens.each_with_index do |token, idx|
    word = token[:token]&.downcase
    next unless NEGATION_PARTICLES.include?(word)

    # Check if second negation particle exists within reasonable distance
    found_second = false
    ((idx + 1)...[idx + 5, tokens.length].min).each do |j|
      next_word = tokens[j][:token]&.downcase
      if SECOND_PARTICLES.include?(next_word)
        found_second = true
        break
      end
    end

    unless found_second
      errors << {
        rule_id: @id,
        position: token[:position],
        message: "Incomplete negation: French requires double negation (ne...pas)",
        suggestion: 'Add pas or another negation particle',
        context: word,
        suggestions: ['ne...pas', 'ne...pas']
      }
    end
  end
  errors
end