aho-corasick-automaton
A streaming Aho-Corasick automata for matching strings. This module is a low level interface, but can be used to construct more complex algorithms.
Example
var createTrie = var createAC = var trie = //First build the trie data structuretrietrietrietrietrie //Next construct the automata and use it to var automata = //Now run it on some datavar data = 123456789forvar state=automata i=0; i<datalength; //Process next symbol state=state //Print out all matches at position i ifstatevalue !== undefined console forvar cur = state; curvalue !== undefined; cur = curnext console
Here is some example output from the above program:
matches at position 2 :
4
matches at position 3 :
1
5
matches at position 4 :
2
matches at position 8 :
3
Install
npm install aho-corasick-automata
API
var createAC =
Constructor
var root = createAC(trie)
Creates an Aho-Corasick automata from the trie encoded as an array-trie
Returns A new Aho-Corasick automata
Methods
automata.push(symbol)
Returns the next state of the automata after processing symbol
symbol
is the next character in the stream to process
Returns The next state of the automata
automata.value
A value representing the terminal of the automata. undefined
if there is no trie entry at this point
automata.next
A pointer to the next entry in the linked list of values at this automata state. If the value
is undefined, then this is the last node in this list.
Credits
(c) 2013 Mikola Lysenko. MIT License