Class: Kotoshu::Languages::Portuguese::GrammarRules::CraseRule
- Defined in:
- lib/kotoshu/languages/pt/language.rb
Overview
Rule: Crase (à vs a)
Instance Attribute Summary
Attributes inherited from Rule
Instance Method Summary collapse
- #check(tokens) ⇒ Object
-
#initialize ⇒ CraseRule
constructor
A new instance of CraseRule.
Constructor Details
#initialize ⇒ CraseRule
Returns a new instance of CraseRule.
289 290 291 |
# File 'lib/kotoshu/languages/pt/language.rb', line 289 def initialize super('PT_CRASE', 'Crase Usage', 'Use crase (à) before feminine nouns indicating place/time.') end |
Instance Method Details
#check(tokens) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/kotoshu/languages/pt/language.rb', line 293 def check(tokens) errors = [] tokens.each_cons(2) do |prev_token, current_token| prev_word = prev_token[:token]&.downcase next unless %w[a ema].include?(prev_word) # Check if next word starts with 'a' sound and is feminine next_word = current_token[:token] next if next_word.nil? || next_word.empty? if next_word&.match?(/^[aáãâä]/i) # Suggest using crase errors << { rule_id: @id, position: prev_token[:position], message: "Possible crase usage needed: '#{prev_word}' -> 'à'", suggestion: 'à', context: "#{prev_word} #{next_word}", suggestions: ['à'] } end end errors end |