ridic 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/README.md +2 -0
- data/lib/.DS_Store +0 -0
- data/lib/ridic/version.rb +1 -1
- data/lib/ridic.rb +21 -6
- data/spec/ridic_spec.rb +2 -2
- metadata +4 -2
data/.DS_Store
ADDED
Binary file
|
data/README.md
CHANGED
@@ -43,6 +43,8 @@ category_number refers to the “column”, or category hierarchy. In the case o
|
|
43
43
|
|
44
44
|
"ALE" => ["ORALITY","NEED","PRIMARY"]
|
45
45
|
|
46
|
+
The full dictionary can be found in its original format at the URL provided at the top of the page, or in hash table format
|
47
|
+
within lib/ridic/dictionary.rb
|
46
48
|
## Contributing
|
47
49
|
|
48
50
|
1. Fork it
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/ridic/version.rb
CHANGED
data/lib/ridic.rb
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
require "ridic/version"
|
2
2
|
require "ridic/dictionary"
|
3
|
+
require 'benchmark'
|
3
4
|
|
4
5
|
module RiDic
|
5
6
|
def self.word_match(text_word)
|
6
|
-
|
7
|
-
dictionary_1
|
7
|
+
text_word.upcase!
|
8
|
+
dictionary_1 = RiDic::Dictionary.words[text_word]
|
9
|
+
dictionary_1 == nil ? RiDic::Dictionary.word_stems[text_word] : dictionary_1
|
8
10
|
end
|
9
11
|
|
10
12
|
def self.stem_match(text_word)
|
11
13
|
text_word.upcase!
|
12
|
-
|
14
|
+
until text_word.length < 3
|
15
|
+
text_word = text_word[0...-1]
|
16
|
+
dictionary_2 = RiDic::Dictionary.word_stems[text_word]
|
17
|
+
(return dictionary_2) if dictionary_2 != nil
|
18
|
+
end
|
13
19
|
nil
|
14
20
|
end
|
15
21
|
|
16
22
|
def self.all_categories_in_document(document_text, result = [])
|
17
|
-
sanitize(document_text).split(' ').each do |elem|
|
18
|
-
|
23
|
+
sanitize(document_text).split(' ').each do |elem|
|
24
|
+
word_res = word_match(elem)
|
25
|
+
if word_res == nil
|
26
|
+
stem_res = stem_match(elem)
|
27
|
+
result.push(stem_res) if stem_res != nil
|
28
|
+
else
|
29
|
+
result << word_res
|
30
|
+
end
|
19
31
|
end
|
20
32
|
result
|
21
33
|
end
|
@@ -26,13 +38,15 @@ module RiDic
|
|
26
38
|
end
|
27
39
|
|
28
40
|
def self.category_distribution(document_text, category_number = 1, result = Hash.new(0))
|
29
|
-
first_categories = category_in_document(sanitize(document_text), category_number)
|
41
|
+
first_categories = category_in_document(sanitize(document_text.upcase), category_number)
|
30
42
|
first_categories.each {|elem| result[elem.first] += 1}
|
31
43
|
sort_distribution(result)
|
32
44
|
end
|
33
45
|
|
34
46
|
private
|
35
47
|
|
48
|
+
# general private methods
|
49
|
+
|
36
50
|
def self.sort_distribution(distribution_set, result = Hash.new)
|
37
51
|
distribution_set.sort_by {|key, value| value}.reverse.each {|i| result[i[0]] = i[1]}
|
38
52
|
result
|
@@ -42,3 +56,4 @@ module RiDic
|
|
42
56
|
document_text.split(' ').each {|word| word.gsub!(/\W/, '')}.join(' ')
|
43
57
|
end
|
44
58
|
end
|
59
|
+
|
data/spec/ridic_spec.rb
CHANGED
@@ -25,8 +25,8 @@ describe 'RiDic' do
|
|
25
25
|
let(:document_text) {"splendid and sublime ale critiqued and bit the harlot of an apple"}
|
26
26
|
let(:categories_result){RiDic.all_categories_in_document(document_text)}
|
27
27
|
|
28
|
-
it 'returns an element for every word in the document' do
|
29
|
-
categories_result.length.should eql(
|
28
|
+
it 'returns an element for every word match in the document' do
|
29
|
+
categories_result.length.should eql(5)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'correctly evaluates the first dictionary item' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby gem wrapper for the Regressive Imagery Dictionary
|
15
15
|
email:
|
@@ -18,11 +18,13 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- .DS_Store
|
21
22
|
- .gitignore
|
22
23
|
- Gemfile
|
23
24
|
- LICENSE.txt
|
24
25
|
- README.md
|
25
26
|
- Rakefile
|
27
|
+
- lib/.DS_Store
|
26
28
|
- lib/ridic.rb
|
27
29
|
- lib/ridic/dictionary.rb
|
28
30
|
- lib/ridic/version.rb
|