如果一段文本是垃圾邮件,那么检查 Java 的最佳、最简单、免费的方法是什么?
4 回答
这一点都不容易,需要有一些理论/数学/统计背景。它被称为贝叶斯过滤,它只是其中一种方法,但效果很好。
您可以在此处了解有关 wikipedia 的介绍和一些背景知识,但它是互联网上广泛涵盖的主题,只需四处搜索(我认为这里也是 StackOverflow)。
Probably the easiest way is to leverage an existing API for that. Akismet has bindings for Java, and it's what Wordpress uses on its blogs by default. Oh, and it's free, libre, open source software.
You could pipe it through SpamAssassin and see what the return value is.
Here's a wacky idea: send the text as an email to a Gmail account. Then use IMAP to see whether it ended up in the Inbox or the Spam folder.
Akismet 为您制作了所有数学和逻辑,我认为这是避免垃圾邮件的最佳方法。
您只需要询问与您的网站相关的密钥。有一种免费(自愿付费)的方式。
通过它的Java API进行的正常调用是这样的,我commentCheck
用于您正在检查的那段文本。
Akismet akismet = new Akismet(AKISMET_KEY, SITE);
return akismet.commentCheck(
request.getRemoteAddr(),
request.getHeader("User-agent"),
request.getHeader("referer"),
"", //permalink
"comment", //comment type
"", //author
"", //email
"",
commentText, //Text to check
request.getParameterMap());
如果此调用返回true
,则将其视为垃圾邮件。