Stream Aho-Corasick automata
npm install aho-corasick-automatonaho-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.
``javascript
var createTrie = require("array-trie")
var createAC = require("aho-corasick-automaton")
var trie = createTrie()
//First build the trie data structure
trie.set([1,2,3], 1)
trie.set([2,3,4], 2)
trie.set([6,7,8], 3)
trie.set([1,2], 4)
trie.set([2,3], 5)
//Next construct the automata and use it to
var automata = createAC(trie)
//Now run it on some data //Process next symbol //Print out all matches at position i Here is some example output from the above program: `
var data = [1,2,3,4,5,6,7,8,9]
for(var state=automata, i=0; i
state=state.push(data[i++])
if(state.value !== undefined) {
console.log("matches at position", i, ":")
for(var cur = state; cur.value !== undefined; cur = cur.next) {
console.log(cur.value)
}
}
}
``
matches at position 2 :
4
matches at position 3 :
1
5
matches at position 4 :
2
matches at position 8 :
3Install
npm install aho-corasick-automata
`javascript`
var createAC = require("aho-corasick-automata")
Returns A new Aho-Corasick automata
*
symbol is the next character in the stream to processReturns The next state of the automata
$3
A value representing the terminal of the automata. undefined if there is no trie entry at this point$3
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.