bayesic_matching 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bayesic_matching/version.rb +1 -1
- data/lib/bayesic_matching.rb +6 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df98c7d569ac9e2e548452b9a3b40656b3626a91
|
4
|
+
data.tar.gz: 8da8d971e361eb88303054ca11ab83deeab10a6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b0bffa3d5381e085f7376e76053ed47b3593b9cc51a64590ea15f889a763b8fd71a40a8a5f0820444221d31990fed2936ee17d06e23fdab8cd752e2ed55e3f7
|
7
|
+
data.tar.gz: 64d046aff06b505337e8f3593f9cd4a89e365fdcad65cd482d2d4c3782ed6f5e33b696f0a372c93ec7257eff3f39d5681410d7ba0787cee5ebaf0f2ab72c4687
|
data/Gemfile.lock
CHANGED
data/lib/bayesic_matching.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require "bayesic_matching/version"
|
2
|
+
require "set"
|
2
3
|
|
3
4
|
class BayesicMatching
|
4
5
|
def initialize
|
5
|
-
@classifications =
|
6
|
+
@classifications = ::Set.new
|
6
7
|
@classifications_by_token = {}
|
7
8
|
@tokens_by_classification = {}
|
8
|
-
@total_token_entries = 0.0
|
9
9
|
end
|
10
10
|
|
11
11
|
def classify(tokens)
|
12
|
-
tokens = tokens.reject{|t| @classifications_by_token[t].nil? }
|
12
|
+
tokens = tokens.reject{|t| @classifications_by_token[t].nil? }.uniq
|
13
13
|
tokens.each_with_object({}) do |token, hash|
|
14
14
|
@classifications_by_token[token].each do |c|
|
15
15
|
p_klass = hash[c] || (1.0 / @classifications.size)
|
@@ -23,12 +23,11 @@ class BayesicMatching
|
|
23
23
|
|
24
24
|
def train(tokens, classification)
|
25
25
|
@classifications << classification
|
26
|
-
@tokens_by_classification[classification] ||=
|
27
|
-
@tokens_by_classification[classification].concat(tokens)
|
26
|
+
@tokens_by_classification[classification] ||= ::Set.new
|
28
27
|
tokens.each do |token|
|
29
|
-
@
|
28
|
+
@tokens_by_classification[classification] << token
|
29
|
+
@classifications_by_token[token] ||= ::Set.new
|
30
30
|
@classifications_by_token[token] << classification
|
31
|
-
@total_token_entries += 1.0
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|