adjectifier 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/adjectifier.rb +37 -2
- data/lib/adjectifier/version.rb +1 -1
- metadata +3 -3
data/lib/adjectifier.rb
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
module Adjectifier
|
2
|
-
def self.extract
|
3
|
-
|
2
|
+
def self.extract(text, options = {})
|
3
|
+
|
4
|
+
adjectives = []
|
5
|
+
|
6
|
+
# single word sentences
|
7
|
+
single_words = %r{
|
8
|
+
\A
|
9
|
+
([a-z]+)
|
10
|
+
[\.\?\!]?
|
11
|
+
\Z
|
12
|
+
}xi
|
13
|
+
|
14
|
+
|
15
|
+
# words following 'very'
|
16
|
+
very = %r{\bvery\s+([a-z]+)\b}xi
|
17
|
+
|
18
|
+
# First check to see if text consists of single words
|
19
|
+
single_words_match = text.scan(single_words)
|
20
|
+
|
21
|
+
if single_words_match.size > 0
|
22
|
+
single_words_match.each do |word|
|
23
|
+
word = word[0].downcase
|
24
|
+
adjectives << word unless adjectives.include?(word)
|
25
|
+
end
|
26
|
+
|
27
|
+
# If text doesn't contain just single words, continue on to do more complex searching.
|
28
|
+
else
|
29
|
+
|
30
|
+
text.scan(very) do |match|
|
31
|
+
word = match[0].downcase
|
32
|
+
adjectives << word unless adjectives.include?(word)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
return adjectives
|
4
39
|
end
|
5
40
|
end
|
data/lib/adjectifier/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adjectifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Frankie Roberto
|