Class: Kotoshu::Languages::French::GrammarRules::ArticleAgreementRule
- Defined in:
- lib/kotoshu/languages/fr/language.rb
Overview
Rule: Article agreement with gender/number.
Constant Summary collapse
- MASCULINE_SINGULAR =
%w[le un].freeze
- FEMININE_SINGULAR =
%w[la une].freeze
- PLURAL =
%w[les des].freeze
Instance Attribute Summary
Attributes inherited from Rule
Instance Method Summary collapse
- #check(tokens) ⇒ Object
-
#initialize ⇒ ArticleAgreementRule
constructor
A new instance of ArticleAgreementRule.
Methods inherited from Rule
Constructor Details
#initialize ⇒ ArticleAgreementRule
Returns a new instance of ArticleAgreementRule.
304 305 306 |
# File 'lib/kotoshu/languages/fr/language.rb', line 304 def initialize super('FR_ARTICLE_AGREEMENT', 'Article Agreement', 'Articles must agree with noun gender and number.') end |
Instance Method Details
#check(tokens) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/kotoshu/languages/fr/language.rb', line 308 def check(tokens) errors = [] tokens.each_cons(2) do |article_token, noun_token| article = article_token[:token]&.downcase next unless MASCULINE_SINGULAR.include?(article) || FEMININE_SINGULAR.include?(article) || PLURAL.include?(article) # This is a simplified check - full implementation would need dictionary lookup # for gender/number information next unless article_token[:pos_tag] == 'DET' noun = noun_token[:token] # Check for common patterns if noun&.end_with?('e') && MASCULINE_SINGULAR.include?(article) # Possibly incorrect: masculine article with feminine-looking noun errors << { rule_id: @id, position: article_token[:position], message: "Article agreement: check if '#{noun}' is feminine", suggestion: nil, context: "#{article} #{noun}", suggestions: ['la', 'une'] } end end errors end |