此例子只考慮少量的敏感詞詞庫替換。
let comments =
"***y girl yes, no ***y ****"
;let abusivewordsdata =
['****'
,'ass'
,'***y girl'
,'***y'];
//敏感詞詞庫
function
replacewords
(comments)
replacewords
(comments)
;//"*** yes, no *** ***"
注意這個例子中』***y girl』, '***y『 順序。在正則匹配的時候,會先尋找和替換「***y girl」,之後再替換「***y」.
如果反著寫, 就不能全部匹配了。因為把***y替換成***後,就沒有"***y girl"可以匹配了。
let comments =
"***y girl yes, no ***y ****"
;let abusivewordsdata =
['****'
,'ass'
,'***y'
,'***y girl'];
//敏感詞詞庫
function
replacewords
(comments)
replacewords
(comments)
;//"*** girl yes, no *** ***"
敏感詞過濾
最近需要實現對聊天裡的敏感詞過濾,要求比較簡單,只需要對字型檔中存在的關鍵字進行匹配,所以不需要非常複雜的實現,但是需要能夠快速地對乙個關鍵字集合進行匹配。搜了一下相關的資料,比較簡單的乙個演算法是使用aho corasick演算法,以下簡稱ac演算法。該演算法的基本思想中包含了kmp演算法,即利用...
敏感詞過濾
敏感詞過濾 防沉迷,基本所有上線系統都會用的基礎功能吧,網上挺多 的,也很多種方式,看的有點繞寫了個自己感覺比較乾淨清楚的,結構也比較簡單,記錄一下insert 和 審查 檢查 都是遞迴,效率還好,win release版本5700的樣本,length 1000的 str 大概0.2ms支援比如敏感...
敏感詞過濾
分享乙個敏感詞過濾方法 1 public class wordfiltercontroller basecontroller 225 result str result 2627 if s filters null 28 3132 bool check false 33 foreach string...