开发了一个 npm 包:关键字匹配工具
代码 Github: https://github.com/guofei/aho-corasick-node Npm: https://www.npmjs.com/package/aho-corasick-node
主要使用了 aho-corasick 跟 doublearray这两个算法
用法:
const AhoCorasick = require('aho-corasick-node');
const keywords = ['b', 'ba', 'nan', 'ab'];
const builder = AhoCorasick.builder();
keywords.forEach(k => builder.add(k));
const ac = builder.build();
const text = 'banana';
const hits = ac.match(text); // ['b', 'ba', 'nan']