Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikolalysenko/aho-corasick-automaton

Generates an Aho-Corasick automata for matching multiple patterns in a stream
https://github.com/mikolalysenko/aho-corasick-automaton

Last synced: about 2 months ago
JSON representation

Generates an Aho-Corasick automata for matching multiple patterns in a stream

Awesome Lists containing this project

README

        

aho-corasick-automaton
======================
A streaming [Aho-Corasick](http://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm) automata for matching strings. This module is a low level interface, but can be used to construct more complex algorithms.

# Example

```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
var data = [1,2,3,4,5,6,7,8,9]
for(var state=automata, i=0; i