做了个Nodejs敏感词过滤器
发布于 8 年前 作者 aojiaotage 9511 次浏览 来自 分享

前两天要做个用户评论的敏感词过滤,怕被请喝茶大家懂的 造了个炒鸡简单初级的轮子,用的DFA实现,有需要的童鞋可以试一试

[github]https://github.com/aojiaotage/text-censor

当然,如果你已经接入了搜索引擎,比如 elasticsearch用来做过滤,或者c++的敏感词过滤器,还是不建议使用这个轮子

NPM Version

Introduction

A simple&basic text filter that is under censor of GFW, with DFA.

为nodejs提供的简单GFW敏感词过滤器,使用DFA实现。

Usage

var tc = require('text-censor')
tc.filter('Ur so sexy babe!',function(err, censored){
    console.log(censored) // 'Ur so ***y babe!'
})

If you want to add key words of your own, simply add them to the end of ‘keywords’ file, one word per line.

在’keywords’文件末尾增加自定义敏感词,每行一个。

Performance

Under 1ms for a 10-20 words sentence. Around 10ms for 1000 words.

10-20字的短句在1ms以内替换完成,1000字左右需要10ms左右

Thanks

Keyword list from https://github.com/observerss/textfilter

License

MIT

1 回复

自己顶顶,欢迎各位批评指导

回到顶部