density-trie

1.1.1 • Public • Published

Density Trie

A trie tree implementation, provide add/remove/lookup and density calcuation over specified text. Eastern/Western languages are supported

Requirement

Node v4.0+

Installation

npm install density-trie --save

Usage

var Trie = require('density-trie');
var should = require('should');
 
describe('Demo', function() {
  var western = true;
  var trie = new Trie(western);
 
  trie.add('He');
  trie.add('Hell');
  trie.add('Hello');
 
  console.log(trie.dump());
 
  var text = 'here is a fragment of text with "Hello World", "Hello" should be 2, "Hell" should be 1, no matter if "eHell" or eHello presented';
 
  trie.density(text).should.be.deepEqual({
    Hello: 2, 
    World: 1,
    Hell: 1
  });
 
  should(trie.remove('Hello').lookup('Hello')).not.be.ok();
 
  trie.check('check method will return immediately when any keyword is found, like Hello').should.be.ok();
  trie.replace('replace KEYWORD with *******').be.exactly('replace ******* with *******');
});

Dependencies (1)

Dev Dependencies (2)

Package Sidebar

Install

npm i density-trie

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

11.3 kB

Total Files

5

Last publish

Collaborators

  • kleshwong