Changeset 12244 for platform/tdiary/lib
- Timestamp:
- 05/23/08 17:24:47 (6 months ago)
- Files:
-
- 1 modified
-
platform/tdiary/lib/bayes.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
platform/tdiary/lib/bayes.rb
r6084 r12244 3 3 4 4 require "pstore" 5 require "uri"6 5 7 6 module Bayes … … 97 96 98 97 def add_url(url, prefix=nil) 99 if URI.regexp(%w[http https ftp]) === url 100 url = URI.parse url 101 host = url.host # $4 102 path = url.path.gsub(%r{^/+|/+$}, '') # $7 98 if %r[^(?:https?|ftp)://(.*?)(?::\d+)?/(.*?)\/?(\?.*)?$] =~ url 99 host, path = $1, $2 103 100 104 101 add_host(host, prefix) … … 137 134 138 135 class FilterBase 139 attr_reader :spam, :ham, :db_name 140 141 def initialize(db_name=nil )136 attr_reader :spam, :ham, :db_name, :charset 137 138 def initialize(db_name=nil, charset=nil) 142 139 @spam = self.class::Corpus.new 143 140 @ham = self.class::Corpus.new 141 @charset = charset 144 142 145 143 @db_name = db_name … … 148 146 @spam = db["spam"] 149 147 @ham = db["ham"] 148 @charset = db["charset"] 150 149 end 151 150 end … … 159 158 db["spam"] = @spam 160 159 db["ham"] = @ham 160 db["charset"] = @charset 161 161 yield(db) if block_given? 162 162 end … … 218 218 g = @ham.count==0 ? 0.0 : [1.0, 2*@ham[token]/@ham.count.to_f].min 219 219 b = @spam.count==0 ? 0.0 : [1.0, @spam[token]/@spam.count.to_f].min 220 if g+b==0221 raise "OOO"222 end223 220 r = [0.01, [0.99, b/(g+b)].min].max 224 221 r
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)