Installations
npm install node-levenshtein-automata
Developer Guide
Typescript
No
Module System
CommonJS
NPM Version
1.2.15
Score
73.8
Supply Chain
90.4
Quality
74.9
Maintenance
100
Vulnerability
99.5
License
Releases
Unable to fetch releases
Download Statistics
Total Downloads
2,817
Last Day
1
Last Week
5
Last Month
12
Last Year
72
Bundle Size
51.23 kB
Minified
15.80 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.0.2
Package Id
node-levenshtein-automata@0.0.2
Size
13.44 kB
NPM Version
1.2.15
Total Downloads
Cumulative downloads
Total Downloads
2,817
Last day
-50%
1
Compared to previous day
Last week
25%
5
Compared to previous week
Last month
100%
12
Compared to previous month
Last year
-68.6%
72
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
#node-levenshtein-automata ##Levenshtein Automata module for Nodejs based on Dylon Edwards great implementation
Based on the dylon implementation of Levenshtein Automata, a nodejs module wrapper that attempts to simplify the use of this algorithm for automating fuzzy text search.
Installation:
1npm install node-levenshtein-automata
###Instantiating the module: When requiring the module a simple Factory Function will be returned allowing you to create a basic memory store and an index which will be used for loading text and searching. When creating the index there are several possible arguments that could be passed into the constructor.
- algorithm: standard, transposition, or merge_and_split
- distance: a numberical value as default for maximum edit distance, otherwise 1 is the default
- sort_matches: true/false of whether to sort. Sorting is done first according to the transduced terms' Levenshtein distances from the query term, then lexicographically, in a case insensitive manner
- include_distance: true/false of whether to include the levenshtein distance with the result
- case_insensitive: true/false of whether to sort in a case insensitive manner
- store: currently supporting memory and redis stores with leveldb in the works
1var lev = require('node-levenshtein-automata') 2 , memStore = lev.MemoryStore() 3 , idx = lev.createIndex('twits', {store: memStore});
Creating a memory store as shown above will keep all indexes together in the same object. This requires that all index names (first argument to createIndex) are unique. If that is not desireable, simply omitting the "store" argument to createIndex will create a separate memory store per index.
Note: this is only applicable to MemoryStore
1var idx = lev.createIndex('twits');
###Redis Store Redis may be used as the backing store for indexing and searching. Using RedisStore is simple:
1var lev = require('node-levenshtein-automata') 2 , RedisStore = lev.RedisStore() 3 , store = new RedisStore(args) //args are redis specific arguments 4 , idx = lev.createIndex('twits', {store: store});
###Indexing Text input may be in the form of a string or array of strings. The second argument is an id. It can be integer or string.
1 2var doc = [ 3 "some string to index", 4 "I love surfing videos on @youtube", 5 "https://github.com/rhasson is pretty cool too" 6] 7 8idx.index(doc, 111); 9idx.index('this is another test string', "222333");
###Searching Search can be done by simply passing in the query term and optionally passing in the max edit distance for the particular query. Otherwise the default provided in the constructor will be used. Lastly a callback must be provided which will receive error and data arguments. The data parameter may be an emptry array if no match was found or an array containing the id, one or more arrays with the term and its levenshtein distance, total count of matches, and the initial query term.
1idx.search('youtube', 2, function(err, data) { 2 console.log(data) // {id: 111, terms: [ ['youtube', 0] ], count: 1, query: 'youtube'} 3}); 4 5idx.search('youtube videos', onResponse);
For more information about the details behind Levenshtein Automata and how this module implements it visit dylon's Levenshtein Automata Github page.
No vulnerabilities found.
No security vulnerabilities found.