You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 line
2.1 KiB

  1. eAcs
  2. =====
  3. 基于ac算法实现的快速高效的敏感词匹配,检查,过滤功能, 另外特殊字符不参与敏感词匹配,检查和替换, 替换是会按照原位置保留
  4. Build
  5. -----
  6. $ rebar3 escriptize -> genAcs
  7. $ rebar3 compile
  8. Uses
  9. -----
  10. 敏感词预处理 去除特殊字符和去掉重复的敏感词 (SWordFile 和 OutputDirFile) 可以同名
  11. 脚本生成:./genAcs -f/-F SWordFile OutputDirFile
  12. 函数调用: genAcs:main(["-f"/"-F", SWordFile, OutputDirFile])
  13. 创建 acsTree.erl
  14. 脚本生成:./genAcs SWordFile OutputDir
  15. 函数调用: genAcs:main([SWordFile, OutputDir])
  16. 匹配 检查 过滤 敏感词
  17. eAcs:matchSw/1 %% 返回匹配的敏感词列表
  18. eAcs:isHasSw/1 %% 检查是否包含敏感词
  19. eAcs:replaceSw/1 %% 替换敏感词
  20. eAcs:isHasRpSw/1 %% 检测并替换敏感词
  21. 性能
  22. -----
  23. 实际测试中
  24. 基于在一个2万敏感词构造的ac状态树中测试 匹配耗时为 50-100ns 一个字 算下来1秒可以匹配上千万的文本
  25. 测试示例(测试前先注释掉测试代码打印的参数和eAcs matchSw匹配输出的列表构造):
  26. 下载了一个比较火的动漫小说 吞噬星空.txt
  27. 查看该小说有多少字
  28. {ok, DataStr} = file:read_file("吞噬星空.txt"),
  29. eAcs:strSize(DataStr, 0). -> 5729268
  30. 测试匹配
  31. acTest:test4(100, "./src/test/吞噬星空.txt").
  32. =====================
  33. execute Fun :matchSw
  34. execute Mod :eAcs
  35. execute LoopTime:100
  36. MaxTime: 450278766(ns) 0.450279(s)
  37. MinTime: 428782619(ns) 0.428783(s)
  38. SumTime: 4345761036(ns) 43.45761(s)
  39. AvgTime: 434576103.(ns) 0.434576(s)
  40. Grar : 43(cn) 0.43(%)
  41. Less : 57(cn) 0.57(%)
  42. =====================
  43. ok
  44. It's really fast!!!
  45. 算法说明
  46. -----
  47. [算法说明](https://www.cnblogs.com/cmmdc/articles/7337611.html)