Module: FisherClassifier
- Defined in:
- lib/fisher_classifier.rb,
lib/fisher_classifier/meta.rb,
lib/fisher_classifier/config.rb,
lib/fisher_classifier/version.rb,
lib/fisher_classifier/classifier.rb
Defined Under Namespace
Modules: Meta
Classes: Classifier, Config
Constant Summary
collapse
- VERSION =
"0.0.4"
Class Method Summary
collapse
Class Method Details
.create(&block) ⇒ Object
9
10
11
12
13
|
# File 'lib/fisher_classifier.rb', line 9
def create(&block)
config = Config.new block
Classifier.new config
end
|
.create_in_memory ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/fisher_classifier.rb', line 15
def create_in_memory
create do
@features = {}
@categories = {}
inc_feature do |feature, category|
@features[category] ||= {}
@features[category][feature] ||= 0
@features[category][feature] += 1
end
inc_category do |category|
@categories[category] ||= 0
@categories[category] += 1
end
get_features do |text|
text.split(' ').map { |s| s.downcase }
end
categories do
[:good, :bad]
end
category_count do |category|
if @categories.has_key?(category)
@categories[category]
else
0
end
end
features_count do |feature, category|
if @features.has_key?(category) && @features[category].has_key?(feature)
@features[category][feature]
else
0
end
end
default_category do
:none
end
end
end
|