UNPKG

node-ac

Version:

A nodejs implementation of the aho corasick pattern search algorithm

37 lines (25 loc) 1.07 kB
# aho corasick pattern search algorithm by C++ ## 安装说明: npm install node-ac ## 使用说明: var nac = require('node-ac'); //添加检查词汇,可多次添加 nac.addCheckItem('可口可了','可口可乐','字词错误'); //添加检查词汇字典,必须utf8格式,可多次添加 nac.addDictionary('../dictionary.txt'); //构建检查器,只可调用一次,调用后,再次调用addCheckItem和 addDictionary无效。 nac.buildChecker(); //reset后,模块重新初始化,需要重新addCheckItem和addDictionary,并buildChecker nac.reset(); //添加检查词汇字典,必须utf8格式,可多次添加 nac.addDictionary('../dictionary.txt'); //构建检查器,只可调用一次,调用后,再次调用addCheckItem和 addDictionary无效。 nac.buildChecker(); //检查文本 nac.checkText('aavbnasdfsaacasdf',function(data){ console.log(JSON.stringify(data)); }); //检查文本文件,必须utf8格式。 nac.checkTextFile('../textfile.txt',function(data){ console.log(JSON.stringify(data)); });