Rails Lameness Filter?
I've done some searching, and I haven't been able to find any kind of open-source lameness filter for rails. Does anyth开发者_运维百科ing like that exist? I'm trying to curtail lame user generated content, in particular, all caps, improper capitalization, excessive exclamation marks, and excessive bold or italics.
Here is a ruby Bayesian Classifier which can be trained to block certain types of content. It would take some creativity to apply directly to your problem.
Its a commercial service, but SocialMod is worth a mention.
I don't know of any existing ones, but it should be too hard to catch most of these with a set of regular expressions in a custom validation. Improper capitalization is a hard one to catch because of proper names and acronyms.
before_validation :filter_lameness
def filter_lameness
# reduce exclamation marks
content.gsub!(/![!1]+/, "!")
# Proper capitalization.
content.gsub!(/(\.\s*[a-z])/, $1.upcase) # capital starts sentence
content.gsub!(/([A-Z]{5,})/, $1.capitalize) # lowercases all but first letter in a string of capitals. Minimum length 5.
# etc...
return true # needed in case the last gsub matches nothing, otherwise validation returns nil and will fail
end
Personally I'd be tempted to keep track of users' infractions to the style guide and pin them with demerit badges after enough offenses, for public humliation.
精彩评论