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.
279 280 281 |
# File 'lib/kotoshu/languages/pt/language.rb', line 279 def initialize super('PT_CRASE', 'Crase Usage', 'Use crase (à) before feminine nouns indicating place/time.') end |
Instance Method Details
#check(tokens) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/kotoshu/languages/pt/language.rb', line 283 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 |