Class: Kotoshu::Grammar::PatternMatchers::VowelSoundMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Kotoshu::Grammar::PatternMatchers::VowelSoundMatcher
- Defined in:
- lib/kotoshu/grammar/pattern_matchers/vowel_sound_matcher.rb
Overview
Matcher for a/an article usage rules.
This matcher checks if βaβ or βanβ is used correctly before vowel and consonant sounds.
Constant Summary collapse
- VOWEL_SOUNDS =
%w[a e i o u].freeze
Instance Method Summary collapse
-
#match(tokens, rule) ⇒ Array<Hash>
Match tokens against the a/an pattern.
Methods inherited from BaseMatcher
Constructor Details
This class inherits a constructor from Kotoshu::Grammar::PatternMatchers::BaseMatcher
Instance Method Details
#match(tokens, rule) ⇒ Array<Hash>
Match tokens against the a/an pattern.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kotoshu/grammar/pattern_matchers/vowel_sound_matcher.rb', line 20 def match(tokens, rule) errors = [] tokens.each_cons(2) do |prev_token, current_token| prev_word = prev_token[:token]&.downcase next unless %w[a an].include?(prev_word) next unless prev_token[:pos_tag] == 'DET' || prev_token[:pos_tag].nil? next_word = current_token[:token] next if next_word.nil? || next_word.empty? expected = article_for(next_word, rule) if prev_word != expected errors << build_error(prev_token, current_token, expected, rule) end end errors end |