ahocorasick

1.0.2 • Public • Published

ahocorasick

Implementation of the Aho-Corasick string searching algorithm, as described in the paper "Efficient string matching: an aid to bibliographic search".

Installing / Running

npm install ahocorasick

for nodejs:

var AhoCorasick = require('ahocorasick');
var ac = new AhoCorasick(['keyword1', 'keyword2', 'etc']);
var results = ac.search('should find keyword1 at position 19 and keyword2 at position 47.');
// [ [ 19, [ 'keyword1' ] ], [ 47, [ 'keyword2' ] ] ]

or for browsers:

<script src="/src/main.js"><script>`
<script>
var ac = new AhoCorasick(['keyword1', 'keyword2', 'etc']);
...
</script>

check test/basic.js for more examples.

PS. Note that what's returned is the index of the last characters of the found keywords.

Visualization

See https://brunorb.github.io/ahocorasick/visualization.html for an interactive visualization of the algorithm.

License

The MIT License

Package Sidebar

Install

npm i ahocorasick

Weekly Downloads

225,154

Version

1.0.2

License

MIT

Unpacked Size

67.8 kB

Total Files

11

Last publish

Collaborators

  • brunorb