Class: Dogeify

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeDogeify

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, options = {})
  # Parse sentences.
  sentences = str.downcase.split(/[\.!?]+/).map(&:strip)

  sentences = sentences.map do |sentence|
    # Ignore any provided patterns.
    sentence = ignore_patterns(sentence, options[:ignore]) if options[:ignore]
    
    # Select just the nouns.
    tagged_sentence = tagger.add_tags(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