bayesic_matching 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bayesic_matching.gemspec +28 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/benchmark.rb +82 -0
- data/examples/favorite_recent_movies.csv +11 -0
- data/examples/popular_recent_movies.csv +2601 -0
- data/lib/bayesic_matching/version.rb +3 -0
- data/lib/bayesic_matching.rb +34 -0
- metadata +116 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require "bayesic_matching/version"
|
2
|
+
|
3
|
+
class BayesicMatching
|
4
|
+
def initialize
|
5
|
+
@classifications = []
|
6
|
+
@classifications_by_token = {}
|
7
|
+
@tokens_by_classification = {}
|
8
|
+
@total_token_entries = 0.0
|
9
|
+
end
|
10
|
+
|
11
|
+
def classify(tokens)
|
12
|
+
tokens = tokens.reject{|t| @classifications_by_token[t].nil? }
|
13
|
+
tokens.each_with_object({}) do |token, hash|
|
14
|
+
@classifications_by_token[token].each do |c|
|
15
|
+
p_klass = hash[c] || (1.0 / @classifications.size)
|
16
|
+
p_not_klass = 1.0 - p_klass
|
17
|
+
p_token_given_klass = 1.0
|
18
|
+
p_token_given_not_klass = (@classifications_by_token[token].size - 1) / @classifications.size.to_f
|
19
|
+
hash[c] = (p_token_given_klass * p_klass) / ((p_token_given_klass * p_klass) + (p_token_given_not_klass * p_not_klass))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def train(tokens, classification)
|
25
|
+
@classifications << classification
|
26
|
+
@tokens_by_classification[classification] ||= []
|
27
|
+
@tokens_by_classification[classification].concat(tokens)
|
28
|
+
tokens.each do |token|
|
29
|
+
@classifications_by_token[token] ||= []
|
30
|
+
@classifications_by_token[token] << classification
|
31
|
+
@total_token_entries += 1.0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bayesic_matching
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Ries
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: benchmark-ips
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: bayesian approach to matching one list of strings with another
|
70
|
+
email:
|
71
|
+
- michael@riesd.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bayesic_matching.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- examples/benchmark.rb
|
88
|
+
- examples/favorite_recent_movies.csv
|
89
|
+
- examples/popular_recent_movies.csv
|
90
|
+
- lib/bayesic_matching.rb
|
91
|
+
- lib/bayesic_matching/version.rb
|
92
|
+
homepage: https://github.com/mmmries/bayesic_matching
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.6.14
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: bayesian approach to matching one list of strings with another
|
116
|
+
test_files: []
|