JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q67575F
  • License ISC

Aho–Corasick string matching algorithm

Package Exports

  • aho-corasick2

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aho-corasick2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

About

aho-corasick2 - Aho–Corasick string matching algorithm

#Installation

$ npm install aho-corasick2

Example

API

import * as AhoCorasick from 'aho-corasick2';
import AhoCorasick from 'aho-corasick2';
import AhoCorasick = require('aho-corasick2');
  • search
var ac, actual, i, len, ref, word;

ac = new AhoCorasick();

ref = ['say', 'she', 'shr', 'he', 'her'];
for (i = 0, len = ref.length; i < len; i++) {
  word = ref[i];
  ac.add(word, {
    word: word
  });
}

ac.build_fail();

console.dir(ac, {
    depth: null,
    colors: true,
});

actual = {};

ac.search('yasherhs', function(found_word) {
  if (actual[found_word] == null) {
    actual[found_word] = 0;
  }
  return actual[found_word]++;
});

console.dir(actual, {
    depth: null,
    colors: true,
});

build graphviz dot

        ac = new AhoCorasick()
        ac.add word, word:word for word in ['say', 'she', 'shr', 'he', 'her']
        ac.build_fail()
        console.log ac.to_dot()

save output as trie.dot and

$ dot -Tpng trie.dot -o trie.png

You also need to install GraphViz

Author

Dejian Xu Google+

Thanks

References

wikipedia: Aho-Corasick