Socket
Socket
Sign inDemoInstall

aho-corasick2

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    aho-corasick2

Aho–Corasick string matching algorithm


Version published
Weekly downloads
87
decreased by-26.89%
Maintainers
1
Install size
93.8 kB
Created
Weekly downloads
 

Readme

Source

aho-corasick2

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 i, len, ref, word;

var ac = new AhoCorasick();

ref = ['say', 'she', 'shr', 'he', 'her', 'h', 'hers', 'his'];

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,
});

let actual = ac.search('yasherhs');
/*
{ matches: { h: [ 3, 6 ], she: [ 2 ], he: [ 3 ], her: [ 3 ] },
  positions: { '2': [ 'she' ], '3': [ 'h', 'he', 'her' ], '6': [ 'h' ] },
  count: { h: 2, she: 1, he: 1, her: 1 },
  data:
   { h: [ { word: 'h' } ],
     she: [ { word: 'she' } ],
     he: [ { word: 'he' } ],
     her: [ { word: 'her' } ] } }
 */

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

Keywords

FAQs

Last updated on 13 Nov 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc