Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

68 righe
2.2 KiB

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