bayes_on_redis 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +8 -4
- data/lib/bayes_on_redis.rb +4 -4
- metadata +3 -3
data/README.markdown
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# What is BayesOnRedis?
|
2
2
|
|
3
3
|
Bayesian classifier on top of Redis
|
4
4
|
|
5
5
|
## Why on Redis?
|
6
6
|
|
7
|
-
Redis is perfect for
|
7
|
+
Because of its persistent but also in-memory data structures, Redis is perfect for weeks of machine learning.
|
8
|
+
|
9
|
+
## How to install?
|
10
|
+
|
11
|
+
gem install bayes_on_redis
|
8
12
|
|
9
13
|
## Getting started
|
10
14
|
|
@@ -16,8 +20,8 @@ Redis is perfect for building fast bayesian filter.
|
|
16
20
|
bor.train "bad", "sucks lame boo death bankrupt loser sad"
|
17
21
|
|
18
22
|
# Then ask it to classify text.
|
19
|
-
bor.
|
23
|
+
bor.classify("awesome kick-ass ninja can still be lame.")
|
20
24
|
|
21
25
|
## Contributing
|
22
26
|
|
23
|
-
[Fork
|
27
|
+
[Fork http://github.com/didip/bayes_on_redis](http://github.com/didip/bayes_on_redis) and send pull requests.
|
data/lib/bayes_on_redis.rb
CHANGED
@@ -43,7 +43,7 @@ class BayesOnRedis
|
|
43
43
|
end
|
44
44
|
alias_method :unlearn, :untrain
|
45
45
|
|
46
|
-
def
|
46
|
+
def score(text)
|
47
47
|
scores = {}
|
48
48
|
|
49
49
|
@redis.smembers(CATEGORIES_KEY).each do |category|
|
@@ -63,8 +63,8 @@ class BayesOnRedis
|
|
63
63
|
return scores
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
67
|
-
(
|
66
|
+
def classify(text)
|
67
|
+
(score(text).sort_by { |score| -score[1] })[0][0] # [0][0] -> first score, get the key
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
@@ -76,7 +76,7 @@ class BayesOnRedis
|
|
76
76
|
def count_occurance(text='')
|
77
77
|
raise "input must be instance of String" unless text.is_a?(String)
|
78
78
|
|
79
|
-
text_chunks = text.downcase.gsub(ONE_OR_TWO_WORDS_RE, '').gsub(NON_ALPHANUMERIC_AND_NON_DOT_RE, ' ').gsub(@stopwords.to_re, '').split
|
79
|
+
text_chunks = text.downcase.gsub(ONE_OR_TWO_WORDS_RE, '').gsub(NON_ALPHANUMERIC_AND_NON_DOT_RE, ' ').gsub(@stopwords.to_re, '').gsub(/\./, '').split
|
80
80
|
text_chunks.inject(Hash.new(0)) do |container, word|
|
81
81
|
container[word] += 1; container
|
82
82
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bayes_on_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Didip Kerabat
|