Class: Dogeify
- Inherits:
-
Object
- Object
- Dogeify
- Defined in:
- lib/dogeify.rb,
lib/dogeify/version.rb
Constant Summary collapse
- ADJECTIVES =
%w[so such very much many how].freeze
- EMOTIONS =
%w[wow amaze excite].freeze
- VERSION =
'1.1.0'
Instance Method Summary collapse
-
#initialize ⇒ Dogeify
constructor
A new instance of Dogeify.
- #process(str, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Dogeify
Returns a new instance of Dogeify.
8 9 10 |
# File 'lib/dogeify.rb', line 8 def initialize @tagger = EngTagger.new end |
Instance Method Details
#process(str, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dogeify.rb', line 12 def process(str, = {}) # Parse sentences. sentences = str.downcase.split(/[\.!?]+/).map(&:strip) sentences = sentences.map do |sentence| # Ignore any provided patterns. sentence = ignore_patterns(sentence, [:ignore]) if [:ignore] # Select just the nouns. tagged_sentence = tagger.(sentence) phrases = tagger.get_nouns(tagged_sentence).keys rescue [] # Prefix nouns with adjectives, and convert to sentences. phrases.map! { |phrase| correct_spelling(phrase) } phrases.map! { |phrase| "#{adjective} #{phrase}." } # Append a word or phrase describing emotion. phrases << "#{emotional_summary}." phrases.join(' ') end sentences.join(' ') end |