我们中的许多人都需要处理用户输入、搜索查询以及输入文本可能包含亵渎或不受欢迎的语言的情况。通常情况下,这需要过滤掉。

在哪里可以找到各种语言和方言的粗口?

源代码中是否有包含好的列表的api ?或者可能是一个API,用一些参数简单地说“是的,这是干净的”或“不,这是脏的”?

有什么好方法可以捕捉那些试图欺骗系统的人,比如$$、azz或a55?

如果您为PHP提供了解决方案,则会有加分。:)

编辑:回答简单地说,避免程序问题:

我认为,当用户可以使用公共图像搜索来查找添加到敏感社区池的图片时,这种过滤器是有一席之地的。如果他们可以搜索“阴茎”,那么他们可能会得到很多照片,是的。如果我们不想要照片,那么阻止这个词作为搜索词是一个很好的把关者,尽管不可否认这不是一个万无一失的方法。真正的问题是首先获得单词列表。

我指的是一种方法来判断单个令牌是否脏,然后简单地禁止它。我不会费心去阻止那种完全滑稽的“长脖子长颈鹿”的说法。你在那里什么也做不了。:)


当前回答

注意本地化问题:在一种语言中是脏话的词在另一种语言中可能是完全正常的词。

目前的一个例子是:ebay使用字典的方法从反馈中过滤“坏词”。如果你试图输入德语翻译的“this was a perfect transaction”(“das war eine perfekte Transaktion”),ebay将会因为用词不当而拒绝反馈。

为什么?因为“was”的德语单词是“war”,而“war”在ebay的“坏词”词典中。

所以要注意本土化问题。

其他回答

不喜欢。这只会导致问题。我个人有一次使用脏话过滤器的经历是,有一次我在IRC频道上提到我“要去汉考克的桥上呆几个小时”或类似的事情,就被踢/禁止进入。

我同意hanclininto在讨论中发表的文章。我通常使用正则表达式来匹配输入文本。这是徒劳的努力,就像你最初提到的那样,你必须明确地在你的“阻止”列表中解释网络上流行的每一种写作技巧。

另一方面,当其他人在讨论审查的道德问题时,我必须同意在网络上有某种形式是必要的。有些人只是喜欢发表粗俗的文章,因为它可以立即冒犯到很多人,而且作者完全不需要思考。

谢谢你的建议。

HanClinto规则!

一旦你有了一个好的MYSQL表,里面有一些你想要过滤的坏单词(我从这个线程中的一个链接开始),你可以这样做:

$errors = array();  //Initialize error array (I use this with all my PHP form validations)

$SCREENNAME = mysql_real_escape_string($_POST['SCREENNAME']); //Escape the input data to prevent SQL injection when you query the profanity table.

$ProfanityCheckString = strtoupper($SCREENNAME); //Make the input string uppercase (so that 'BaDwOrD' is the same as 'BADWORD').  All your values in the profanity table will need to be UPPERCASE for this to work.

$ProfanityCheckString = preg_replace('/[_-]/','',$ProfanityCheckString); //I allow alphanumeric, underscores, and dashes...nothing else (I control this with PHP form validation).  Pull out non-alphanumeric characters so 'B-A-D-W-O-R-D' shows up as 'BADWORD'.

$ProfanityCheckString = preg_replace('/1/','I',$ProfanityCheckString); //Replace common numeric representations of letters so '84DW0RD' shows up as 'BADWORD'.

$ProfanityCheckString = preg_replace('/3/','E',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/4/','A',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/5/','S',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/6/','G',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/7/','T',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/8/','B',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/0/','O',$ProfanityCheckString); //Replace ZERO's with O's (Capital letter o's).

$ProfanityCheckString = preg_replace('/Z/','S',$ProfanityCheckString); //Replace Z's with S's, another common substitution.  Make sure you replace Z's with S's in your profanity database for this to work properly.  Same with all the numbers too--having S3X7 in your database won't work, since this code would render that string as 'SEXY'.  The profanity table should have the "rendered" version of the bad words.

$CheckProfanity = mysql_query("SELECT * FROM DATABASE.TABLE p WHERE p.WORD = '".$ProfanityCheckString."'");
if(mysql_num_rows($CheckProfanity) > 0) {$errors[] = 'Please select another Screen Name.';} //Check your profanity table for the scrubbed input.  You could get real crazy using LIKE and wildcards, but I only want a simple profanity filter.

if (count($errors) > 0) {foreach($errors as $error) {$errorString .= "<span class='PHPError'>$error</span><br /><br />";} echo $errorString;} //Echo any PHP errors that come out of the validation, including any profanity flagging.


//You can also use these lines to troubleshoot.
//echo $ProfanityCheckString;
//echo "<br />";
//echo mysql_error();
//echo "<br />";

我确信有一种更有效的方法来完成所有这些替换,但我不够聪明,无法找到它(尽管效率不高,但这似乎还可以)。

我认为你应该允许用户注册,并根据需要使用人工过滤和添加到你的亵渎表。尽管这一切都取决于一个假阳性(好的词被标记为坏)和一个假阴性(坏词通过)的成本。这将最终决定您在过滤策略中是积极还是保守。

如果您想使用通配符,我也会非常小心,因为它们有时会比您想要的更麻烦。

看看CDYNE的亵渎过滤器Web服务

测试网址

也是在游戏后期,但做了一些调查,偶然发现了这里。正如其他人所提到的,如果它是自动化的,这几乎是不可能的,但是如果你的设计/需求可以在某些情况下(但不是所有的时间)涉及人类交互来审查它是否亵渎神明,你可以考虑ML. https://learn.microsoft.com/en-us/azure/cognitive-services/content-moderator/text-moderation-api#profanity是我目前的选择,原因有很多:

支持多种本地化 他们不断更新数据库,所以我不必跟上最新的俚语或语言(维护问题) 当有很大的可能性(即90%或更多)时,你可以务实地否认它 你可以观察哪个类别会导致一个可能是或不是亵渎的标记,并可以让某人检查它,告诉它是否是亵渎的。

For my need, it was/is based on public-friendly commercial service (OK, videogames) which other users may/will see the username, but the design requires that it has to go through profanity filter to reject offensive username. The sad part about this is the classic "clbuttic" issue will most likely occur since usernames are usually single word (up to N characters) of sometimes multiple words concatenated... Again, Microsoft's cognitive service will not flag "Assist" as Text.HasProfanity=true but may flag one of the categories probability to be high.

当OP询问“a$$”时,这是我通过过滤器传递的结果:,正如你所看到的,它已经确定它不是亵渎的,但它有很高的概率是亵渎的,所以标记为审查(人类交互)的建议。

当概率高的时候,我可以返回“对不起,那个名字已经有人了”(即使没有),这样对反审查的人来说就不那么冒犯了,如果我们不想整合人工审查,或者返回“您的用户名已经通知到直播运营部门,您可以等待您的用户名审核通过或选择其他用户名”。之类的……

顺便说一下,这个服务的成本/价格对于我的目的来说是相当低的(用户名多久会被更改一次?),但是,对于OP来说,可能设计需要更密集的查询,并且可能不适合支付/订阅ml服务,或者不能进行人工审查/交互。这完全取决于设计……但如果设计确实符合要求,也许这可以成为OP的解决方案。

如果有兴趣,我可以在将来的评论中列出缺点。