5 confdir = ENV['HOME'] + '/settings/mailvisa'
13 def calculate_word_score word
14 bad_count = $bad_words[word]
15 good_count = $good_words[word]
16 b = bad_count != nil ? ($bad_words[word].to_f / $bad_messages) : 0
17 g = good_count != nil ?
18 ($good_multiplier * $good_words[word].to_f / $good_messages) :
30 usage = 'USAGE: ' + $0 + ' [options]'
35 -c <path> Look for files in <path> (default: $HOME/settings/mailvisa)
36 -g <file> Load good words from <file> (default: "good")
37 -b <file> Load bad words from <file> (default: "bad")
38 -f <file> Write scores to <file> (default: "scores")
39 -m <num> Multiply number of good occurrences by <num> (default: 1.0)
44 ## Process command line
66 $good_multiplier = ARGV[i].to_f
68 $stderr.puts 'Unknown option: ' + ARGV[i]
69 $stderr.puts 'See "' + $0 + ' -h" for valid options'
72 ## Compatibility with original version
81 raise 'Too many arguments'
87 goodfile = confdir + '/' + goodfile if goodfile.index('/') == nil
88 badfile = confdir + '/' + badfile if badfile.index('/') == nil
89 scorefile = confdir + '/' + scorefile if scorefile.index('/') == nil
91 print "Loading good words from #{goodfile}..."
93 good = load_wordlist open(goodfile)
94 $good_words = good[:words]
95 $good_messages = good[:messages]
96 puts "#{$good_words.length} words loaded"
98 print "Loading bad words from #{badfile}..."
100 bad = load_wordlist open(badfile)
101 $bad_words = bad[:words]
102 $bad_messages = bad[:messages]
103 puts "#{$bad_words.length} words loaded"
105 print "Calculating probabilities..."
108 $bad_words.each do |word,count|
109 if score[word] == nil && count > 4
110 score[word] = calculate_word_score word
114 $good_words.each do |word,count|
115 if score[word] == nil && count > 4
116 score[word] = calculate_word_score word
121 fh = open scorefile, 'w'
122 wordlist = { :messages => ($good_messages + $bad_messages), :words => score }
123 dump_wordlist wordlist, fh