Skip to content

Commit

Permalink
Fix spam detection and comment moderation status
Browse files Browse the repository at this point in the history
Giving some initial data to the spam filter makes it work from the beginning. classifier-reborn was used instead of classifier to fix "Gem Load Error is: method `/' not defined in Integer" that occured on one test server
  • Loading branch information
onli committed Feb 16, 2020
1 parent 59b50ff commit 9b9eb49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gem 'oga'
gem 'puma'
gem 'sqlite3'
gem 'pony'
gem 'classifier'
gem 'classifier-reborn'
gem 'kramdown'
gem 'http'
gem 'thread'
Expand Down
9 changes: 6 additions & 3 deletions comment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'classifier'
require 'classifier-reborn'
require 'pony'
require 'kramdown'
require 'htmlentities'
Expand Down Expand Up @@ -47,7 +47,7 @@ def initialize(*args)
self.author = commentAuthor
self.id = params[:id]
self.status = "approved"
self.status = "moderate" if self.isSpam? || self.entry.moderate == "moderate"
self.status = "moderate" if self.isSpam? || self.entry.moderate == "moderated"
self.subscribe = 1 if params[:subscribe] != nil
self.type = params[:type]
if self.type == "trackback"
Expand Down Expand Up @@ -125,7 +125,10 @@ def train(category)
db = Database.new
bayes = db.getOption("spamFilter")
if bayes == nil
bayes = Classifier::Bayes.new "Spam", "Ham"
bayes = ClassifierReborn::Bayes.new "Spam", "Ham"
# we add some minimal initial training data, because if there is none in one of the categories it always returns "ham"
bayes.train "spam", "casino gold viagra"
bayes.train "ham", "a valid comment"
else
bayes = YAML.load(bayes)
end
Expand Down
2 changes: 1 addition & 1 deletion entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Entry
attr_accessor :title
attr_accessor :date
attr_accessor :author
attr_accessor :moderate
attr_accessor :moderate # 'open', 'moderated', 'closed'
attr_accessor :tags

def initialize(*args)
Expand Down

0 comments on commit 9b9eb49

Please sign in to comment.