Class: Tracinho::WordClassifier
- Inherits:
-
Object
- Object
- Tracinho::WordClassifier
- Defined in:
- lib/tracinho/word_classifier.rb
Overview
WordClassifier is the responsible for classifying a word. It gives the verb, the verb tense and the full classification of a Word.
Example:
word = Tracinho::Word.new('comeste')
classifier = Tracinho::WordClassifier.new(word)
classifier.verb
# => "comer"
classifier.verb_tense
# => "pretérito perfeito do indicativo"
classifier.full_classification
# => "Segunda pessoa do singular do pretérito perfeito do indicativo do verbo comer."
Constant Summary collapse
- ENDINGS =
:nodoc:
/(?:(ste)|(sse)|[^-](mos)|(-(se|mos))|[^s](-te)|(s-te))$/.freeze
Instance Method Summary collapse
-
#full_classification ⇒ Object
Returns the full classification of a word.
-
#initialize(word) ⇒ WordClassifier
constructor
A new instance of WordClassifier.
- #verb ⇒ Object
- #verb_tense ⇒ Object
Constructor Details
#initialize(word) ⇒ WordClassifier
Returns a new instance of WordClassifier.
23 24 25 |
# File 'lib/tracinho/word_classifier.rb', line 23 def initialize(word) @word = word end |
Instance Method Details
#full_classification ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tracinho/word_classifier.rb', line 34 def full_classification case @word.to_s when /ste$/ "Segunda pessoa do singular do #{full_verb}." when /sse$/ "Primeira ou terceira pessoa do singular do #{full_verb}." when /[^-]mos$/ "Primeira pessoa do plural do #{full_verb}." when /(-te|-se)$/ "Conjugação pronominal reflexa da segunda pessoa do #{full_verb}." when /-mos$/ "Conjugação pronominal da segunda pessoa do singular do #{full_verb}." end end |
#verb ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tracinho/word_classifier.rb', line 49 def verb endings = @word.to_s.match(ENDINGS).captures.compact verb = @word.to_s.sub(endings.first, 'r') verb.sub!(/rr$/, 'r') verb.sub!(/our$/, 'ar') # Irregular verbs that got bad guesses verb = verb.sub(/^var$/, 'ir').sub(/^sor$/, 'ser').sub(/^for$/, 'ser') verb end |
#verb_tense ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tracinho/word_classifier.rb', line 62 def verb_tense case @word.to_s when /ste$/ 'pretérito perfeito do indicativo' when /sse$/ 'pretérito imperfeito do conjuntivo' when /[^-]mos$/ 'presente do indicativo ou pretérito perfeito do indicativo' when /(-te|-se)$/ 'presente do indicativo' when /-mos$/ 'imperativo' end end |