function cc.splitStringToWords(str) local words = {} for uchar in string.gfind(str,"[%z\1-\127\194-\244][\128-\191]*") do words[#words+1] = uchar end return words end function cc.filterSensitiveWord(str) local filter = { [" "] = true,["。"] = true,[","] = true,["、"] = true,[";"] = true,[":"] = true,["’"] = true,["‘"] = true,["."] = true,[","] = true,["/"] = true,[";"] = true,[":"] = true,["'"] = true,} print("原字符:",str) local words = cc.splitStringToWords(str) local exist = false local pos = 1 while pos <= #words do local tmp = pos local t = cc.csvData["sensitive_words"][words[pos]] while t ~= nil do if next(t) then tmp = tmp +1 if filter[words[tmp]] then tmp = tmp +1 end t = t[words[tmp]] else print("find",pos,tmp) exist = true for i=pos,tmp do if filter[words[i]] ~= true then words[i] = "*" end end break end end if tmp ~= pos then pos = tmp else pos = pos +1 end end local newStr = "" if exist then for i=1,#words do newStr = newStr .. words[i] end else newStr = str end print("过滤后:",newStr) return newStr end
csv = path.."config/sensitive_words.csv" cc.csvData["sensitive_words"] = {} cc.praseCSV(csv,function (idx,vals) local words = cc.splitStringToWords(vals["code"]) --print("word",vals["code"],#words) local t = cc.csvData["sensitive_words"] local pos = 1 while pos <= #words do if not t[words[pos]] then t[words[pos]] = {} end t = t[words[pos]] pos = pos+1 end end)
单词 code 习大大
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。