过滤或者查找敏感词(DFA 算法)

刚刚发布了一个laravel过滤敏感词的包,采用 DFA 算法,可能还存在着一些不完善的地方,各位大佬如有发现可以指正一下,开发包前借鉴了前人的一些算法,发现其有些不足的地方(如:过滤敏感词中存在包含的关系::敏感和敏感词),然后进行了改造;

github : nelsonkti/sensitive-word

Installation

$ composer require nelsonkti/sensitive-word

Laravel

config/app.php
'providers' => [
    Nelsonkti\SensitiveWord\SensitiveWordServiceProvider::class,
],

'aliases' => [
    'SensitiveWord' => Nelsonkti\SensitiveWord\SensitiveWord::class,
],

Usage

基本使用:

use Nelsonkti\SensitiveWord\Facades\SensitiveWord;

$path = './word.txt'

$content = '敏感,敏感词需要过滤'; #检查内容
$filename = '/txt/sensitive-words.txt'; #敏感词文件路径

SensitiveWord::searchWord($content, $filename);
# 返回: array('敏感', '敏感词');

SensitiveWord::filterWord($content, $filename);
# 返回: **,***需要过滤
注意:
word.txt 内容需要换行;如下:
敏感词
敏感

License

sensitive-word is licensed under The MIT License (MIT).

你可能感兴趣的:(敏感词,laravel)