Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/classifier-reborn/backends/bayes_memory_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ClassifierReborn
class BayesMemoryBackend
attr_reader :total_words, :total_trainings

# This class provides Memory as the storage backend for the classifier data structures
def initialize
@total_words = 0
@total_trainings = 0
Expand Down
21 changes: 21 additions & 0 deletions lib/classifier-reborn/backends/bayes_redis_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@
end

module ClassifierReborn
# This class provides Redis as the storage backend for the classifier data structures
class BayesRedisBackend
# The class can be created with the same arguments that the redis gem accepts
# E.g.,
# b = ClassifierReborn::BayesRedisBackend.new
# b = ClassifierReborn::BayesRedisBackend.new host: "10.0.1.1", port: 6380, db: 2
# b = ClassifierReborn::BayesRedisBackend.new url: "redis://:secret@10.0.1.1:6380/2"
#
# Options available are:
# url: lambda { ENV["REDIS_URL"] }
# scheme: "redis"
# host: "127.0.0.1"
# port: 6379
# path: nil
# timeout: 5.0
# password: nil
# db: 0
# driver: nil
# id: nil
# tcp_keepalive: 0
# reconnect_attempts: 1
# inherit_socket: false
def initialize(options = {})
@redis = Redis.new(options)
@redis.set(:total_words, 0)
Expand Down
19 changes: 12 additions & 7 deletions lib/classifier-reborn/bayes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class Bayes
# b = ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting', 'Spam'
#
# Options available are:
# language: 'en' Used to select language specific stop words
# auto_categorize: false When true, enables ability to dynamically declare a category
# enable_threshold: false When true, enables a threshold requirement for classifition
# threshold: 0.0 Default threshold, only used when enabled
# enable_stemmer: true When false, disables word stemming
# language: 'en' Used to select language specific stop words
# auto_categorize: false When true, enables ability to dynamically declare a category
# enable_threshold: false When true, enables a threshold requirement for classifition
# threshold: 0.0 Default threshold, only used when enabled
# enable_stemmer: true When false, disables word stemming
# backend: BayesMemoryBackend.new Alternatively, BayesRedisBackend.new for persistent storage
def initialize(*args)
initial_categories = []
options = { language: 'en',
Expand Down Expand Up @@ -195,11 +196,15 @@ def method_missing(name, *args)
# Provides a list of category names
# For example:
# b.categories
# => ['This', 'That', 'the_other']
def categories # :nodoc:
# => ["This", "That", "The other"]
def categories
category_keys.collect(&:to_s)
end

# Provides a list of category keys as symbols
# For example:
# b.categories
# => [:This, :That, :"The other"]
def category_keys
@backend.category_keys
end
Expand Down