Module: Adjectifier

Defined in:
lib/adjectifier.rb,
lib/adjectifier/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.extract(text, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/adjectifier.rb', line 2

def self.extract(text, options = {})
  
  adjectives = []
  
  # single word sentences
  single_words = %r{
    \A
    ([a-z]+)
    [\.\?\!]?
    \Z
    }xi
  
      
  # words following 'very'
  very = %r{\bvery\s+([a-z]+)\b}xi
  
  # First check to see if text consists of single words
  single_words_match = text.scan(single_words)
  
  if single_words_match.size > 0
    single_words_match.each do |word|
      word = word[0].downcase
      adjectives << word unless adjectives.include?(word)
    end
  
  # If text doesn't contain just single words, continue on to do more complex searching.
  else

    text.scan(very) do |match|
      word = match[0].downcase
      adjectives << word unless adjectives.include?(word)
    end 
        
  end
  
   
  return adjectives 
end