class Bayes::FilterBase

Attributes

charset[R]
db_name[R]
ham[R]
spam[R]

Public Class Methods

new(db_name=nil, charset=nil) click to toggle source
# File lib/bayes.rb, line 138
def initialize(db_name=nil, charset=nil)
        @spam = self.class::Corpus.new
        @ham = self.class::Corpus.new
        @charset = charset

        @db_name = db_name
        if db_name && File.exist?(db_name)
                PStore.new(db_name).transaction(true) do |db|
                        @spam = db["spam"]
                        @ham = db["ham"]
                        @charset = db["charset"]
                end
        end
end

Public Instance Methods

[](token) click to toggle source
# File lib/bayes.rb, line 165
def [](token)
        score(token)
end
convert(to_code, from_code) click to toggle source
# File lib/bayes/convert.rb, line 28
def convert(to_code, from_code)
        @charset = to_code
        @ham = convert_corpus(@ham, to_code, from_code)
        @spam = convert_corpus(@spam, to_code, from_code)
end
save(db_name=nil) { |db| ... } click to toggle source
# File lib/bayes.rb, line 153
def save(db_name=nil)
        db_name ||= @db_name
        @db_name ||= db_name
        return unless @db_name
        PStore.new(@db_name).transaction do |db|
                db["spam"] = @spam
                db["ham"] = @ham
                db["charset"] = @charset
                yield(db) if block_given?
        end
end

Private Instance Methods

convert_corpus(corpus, to_code, from_code) click to toggle source
# File lib/bayes/convert.rb, line 19
def convert_corpus(corpus, to_code, from_code)
        r = self.class::Corpus.new
        corpus.each do |k, v|
                r[k.kconv(to_code::KCONV, from_code::KCONV)] = v
        end
        r
end