Socket
Socket
Sign inDemoInstall

efrt

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

efrt - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

builds/efrt-unpack.es5.js

324

builds/efrt-unpack.js

@@ -1,40 +0,27 @@

/* efrt trie-compression v0.0.4 github.com/nlp-compromise/efrt - MIT */
/* efrt trie-compression v0.0.5 github.com/nlp-compromise/efrt - MIT */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.unpack = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
'use strict';
const BASE = 36;
module.exports = {
NODE_SEP: ';',
STRING_SEP: ',',
TERMINAL_PREFIX: '!',
//characters banned from entering the trie
NOT_ALLOWED: new RegExp('[0-9A-Z,;!]'),
BASE: 36
};
},{}],2:[function(_dereq_,module,exports){
'use strict';
var config = _dereq_('./config');
var seq = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var cache = seq.split('').reduce(function (h, c, i) {
const seq = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const cache = seq.split('').reduce((h, c, i) => {
h[c] = i;
return h;
}, {});
// console.log(cache);
// 0, 1, 2, ..., A, B, C, ..., 00, 01, ... AA, AB, AC, ..., AAA, AAB, ...
var toAlphaCode = function toAlphaCode(n) {
const toAlphaCode = function(n) {
if (seq[n] !== undefined) {
return seq[n];
}
var places = 1;
var range = config.BASE;
var s = '';
let places = 1;
let range = BASE;
let s = '';
for (; n >= range; n -= range, places++, range *= config.BASE) {}
for (; n >= range; n -= range, places++, range *= BASE) {
}
while (places--) {
var d = n % config.BASE;
const d = n % BASE;
s = String.fromCharCode((d < 10 ? 48 : 55) + d) + s;
n = (n - d) / config.BASE;
n = (n - d) / BASE;
}

@@ -44,14 +31,16 @@ return s;

var fromAlphaCode = function fromAlphaCode(s) {
const fromAlphaCode = function(s) {
if (cache[s] !== undefined) {
return cache[s];
}
var n = 0;
var places = 1;
var range = config.BASE;
var pow = 1;
let n = 0;
let places = 1;
let range = BASE;
let pow = 1;
for (; places < s.length; n += range, places++, range *= config.BASE) {}
for (var i = s.length - 1; i >= 0; i--, pow *= config.BASE) {
var d = s.charCodeAt(i) - 48;
for (; places < s.length; n += range, places++, range *= BASE) {
}
for (let i = s.length - 1; i >= 0; i--, pow *= BASE) {
let d = s.charCodeAt(i) - 48;
if (d > 10) {

@@ -65,43 +54,12 @@ d -= 7;

/* Sort elements and remove duplicates from array (modified in place) */
var unique = function unique(a) {
a.sort();
for (var i = 1; i < a.length; i++) {
if (a[i - 1] === a[i]) {
a.splice(i, 1);
}
}
};
var commonPrefix = function commonPrefix(w1, w2) {
var len = Math.min(w1.length, w2.length);
while (len > 0) {
var prefix = w1.slice(0, len);
if (prefix === w2.slice(0, len)) {
return prefix;
}
len -= 1;
}
return '';
};
module.exports = {
toAlphaCode: toAlphaCode,
fromAlphaCode: fromAlphaCode,
unique: unique,
commonPrefix: commonPrefix
fromAlphaCode: fromAlphaCode
};
// let out = fromAlphaCode('A');
// console.log(out);
// console.log(fromAlphaCode(out));
// console.log(fromAlphaCode('R'));
},{"./config":1}],3:[function(_dereq_,module,exports){
},{}],2:[function(_dereq_,module,exports){
'use strict';
const Ptrie = _dereq_('./ptrie');
var Ptrie = _dereq_('./ptrie');
// const Ptrie = require('./ptrie_old');
var unpack = function unpack(str) {
const unpack = (str) => {
return new Ptrie(str);

@@ -111,8 +69,7 @@ };

},{"./ptrie":5}],4:[function(_dereq_,module,exports){
},{"./ptrie":4}],3:[function(_dereq_,module,exports){
'use strict';
//are we on the right path with this string?
var isPrefix = function isPrefix(str, want) {
const isPrefix = function(str, want) {
//allow perfect equals

@@ -123,3 +80,3 @@ if (str === want) {

//compare lengths
var len = str.length;
let len = str.length;
if (len >= want.length) {

@@ -137,21 +94,12 @@ return false;

},{}],5:[function(_dereq_,module,exports){
},{}],4:[function(_dereq_,module,exports){
'use strict';
const encoding = _dereq_('../encoding');
const isPrefix = _dereq_('./prefix');
const unravel = _dereq_('./unravel');
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var config = _dereq_('../config');
var fns = _dereq_('../fns');
var isPrefix = _dereq_('./prefix');
var unravel = _dereq_('./unravel');
//PackedTrie - Trie traversal of the Trie packed-string representation.
var PackedTrie = function () {
function PackedTrie(str) {
_classCallCheck(this, PackedTrie);
this.nodes = str.split(config.NODE_SEP); //that's all ;)!
class PackedTrie {
constructor(str) {
this.nodes = str.split(';'); //that's all ;)!
this.syms = [];

@@ -167,122 +115,106 @@ this.symCount = 0;

//the symbols are at the top of the array.
_createClass(PackedTrie, [{
key: 'initSymbols',
value: function initSymbols() {
//... process these lines
var reSymbol = new RegExp('([0-9A-Z]+):([0-9A-Z]+)');
for (var i = 0; i < this.nodes.length; i++) {
var m = reSymbol.exec(this.nodes[i]);
if (!m) {
this.symCount = i;
break;
}
this.syms[fns.fromAlphaCode(m[1])] = fns.fromAlphaCode(m[2]);
initSymbols() {
//... process these lines
const reSymbol = new RegExp('([0-9A-Z]+):([0-9A-Z]+)');
for(let i = 0; i < this.nodes.length; i++) {
const m = reSymbol.exec(this.nodes[i]);
if (!m) {
this.symCount = i;
break;
}
//remove from main node list
this.nodes = this.nodes.slice(this.symCount, this.nodes.length);
this.syms[encoding.fromAlphaCode(m[1])] = encoding.fromAlphaCode(m[2]);
}
//remove from main node list
this.nodes = this.nodes.slice(this.symCount, this.nodes.length);
}
// Return largest matching string in the dictionary (or '')
}, {
key: 'has',
value: function has(want) {
var _this = this;
// console.log(this.nodes);
//fail-fast
if (!want) {
return false;
// Return largest matching string in the dictionary (or '')
has(want) {
//fail-fast
if (!want) {
return false;
}
//then, try cache-lookup
if (this._cache) {
return this._cache[want] || false;
}
const crawl = (index, prefix) => {
let node = this.nodes[index];
//the '!' means a prefix-alone is a good match
if (node[0] === '!') {
//try to match the prefix (the last branch)
if (prefix === want) {
return true;
}
node = node.slice(1); //ok, we tried. remove it.
}
//then, try cache-lookup
if (this._cache) {
return this._cache[want] || false;
}
var crawl = function crawl(index, prefix) {
var node = _this.nodes[index];
//the '!' means a prefix-alone is a good match
if (node[0] === '!') {
//try to match the prefix (the last branch)
if (prefix === want) {
//each possible match on this line is something like 'me,me2,me4'.
//try each one
const matches = node.split(/([A-Z0-9,]+)/g);
for (let i = 0; i < matches.length; i += 2) {
const str = matches[i];
const ref = matches[i + 1];
if (!str) {
continue;
}
const have = prefix + str;
//we're at the branch's end, so try to match it
if (ref === ',' || ref === undefined) {
if (have === want) {
return true;
}
node = node.slice(1); //ok, we tried. remove it.
}
//each possible match on this line is something like 'me,me2,me4'.
//try each one
var matches = node.split(/([A-Z0-9,]+)/g);
for (var i = 0; i < matches.length; i += 2) {
var str = matches[i];
var ref = matches[i + 1];
if (!str) {
continue;
}
var have = prefix + str;
//we're at the branch's end, so try to match it
if (ref === ',' || ref === undefined) {
if (have === want) {
return true;
}
continue;
}
//ok, not a match.
//well, should we keep going on this branch?
//if we do, we ignore all the others here.
if (isPrefix(have, want)) {
index = _this.indexFromRef(ref, index);
return crawl(index, have);
}
//nah, lets try the next branch..
continue;
}
//ok, not a match.
//well, should we keep going on this branch?
//if we do, we ignore all the others here.
if (isPrefix(have, want)) {
index = this.indexFromRef(ref, index);
return crawl(index, have);
}
//nah, lets try the next branch..
continue;
}
return false;
};
return crawl(0, '');
return false;
};
return crawl(0, '');
}
// References are either absolute (symbol) or relative (1 - based)
indexFromRef(ref, index) {
const dnode = encoding.fromAlphaCode(ref);
if (dnode < this.symCount) {
return this.syms[dnode];
}
return index + dnode + 1 - this.symCount;
}
// References are either absolute (symbol) or relative (1 - based)
}, {
key: 'indexFromRef',
value: function indexFromRef(ref, index) {
var dnode = fns.fromAlphaCode(ref);
if (dnode < this.symCount) {
return this.syms[dnode];
}
return index + dnode + 1 - this.symCount;
toArray() {
return Object.keys(this.toObject());
}
toObject() {
if (this._cache) {
return this._cache;
}
}, {
key: 'toArray',
value: function toArray() {
if (this._cache) {
return Object.keys(this._cache);
}
return Object.keys(unravel(this));
}
}, {
key: 'cache',
value: function cache() {
this._cache = unravel(this);
this.nodes = null;
this.syms = null;
}
}]);
return unravel(this);
}
cache() {
this._cache = unravel(this);
this.nodes = null;
this.syms = null;
}
return PackedTrie;
}();
}
module.exports = PackedTrie;
},{"../config":1,"../fns":2,"./prefix":4,"./unravel":6}],6:[function(_dereq_,module,exports){
},{"../encoding":1,"./prefix":3,"./unravel":5}],5:[function(_dereq_,module,exports){
'use strict';
//spin-out all words from this trie
var unRavel = function unRavel(trie) {
var all = {};
var crawl = function crawl(index, prefix) {
var node = trie.nodes[index];
const unRavel = (trie) => {
let all = {};
const crawl = function(index, prefix) {
let node = trie.nodes[index];
if (node[0] === '!') {

@@ -292,6 +224,6 @@ all[prefix] = true;

}
var matches = node.split(/([A-Z0-9,]+)/g);
for (var i = 0; i < matches.length; i += 2) {
var str = matches[i];
var ref = matches[i + 1];
let matches = node.split(/([A-Z0-9,]+)/g);
for (let i = 0; i < matches.length; i += 2) {
let str = matches[i];
let ref = matches[i + 1];
if (!str) {

@@ -301,3 +233,3 @@ continue;

var have = prefix + str;
let have = prefix + str;
//branch's end

@@ -308,3 +240,3 @@ if (ref === ',' || ref === undefined) {

}
var newIndex = trie.indexFromRef(ref, index);
let newIndex = trie.indexFromRef(ref, index);
crawl(newIndex, have);

@@ -318,3 +250,3 @@ }

},{}]},{},[3])(3)
},{}]},{},[2])(2)
});

@@ -1,2 +0,2 @@

/* efrt trie-compression v0.0.4 github.com/nlp-compromise/efrt - MIT */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.unpack=e()}}(function(){return function e(n,t,r){function i(f,u){if(!t[f]){if(!n[f]){var s="function"==typeof require&&require;if(!u&&s)return s(f,!0);if(o)return o(f,!0);var c=new Error("Cannot find module '"+f+"'");throw c.code="MODULE_NOT_FOUND",c}var a=t[f]={exports:{}};n[f][0].call(a.exports,function(e){var t=n[f][1][e];return i(t?t:e)},a,a.exports,e,n,t,r)}return t[f].exports}for(var o="function"==typeof require&&require,f=0;f<r.length;f++)i(r[f]);return i}({1:[function(e,n,t){"use strict";n.exports={NODE_SEP:";",STRING_SEP:",",TERMINAL_PREFIX:"!",NOT_ALLOWED:new RegExp("[0-9A-Z,;!]"),BASE:36}},{}],2:[function(e,n,t){"use strict";var r=e("./config"),i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",o=i.split("").reduce(function(e,n,t){return e[n]=t,e},{}),f=function(e){if(void 0!==i[e])return i[e];for(var n=1,t=r.BASE,o="";e>=t;e-=t,n++,t*=r.BASE);for(;n--;){var f=e%r.BASE;o=String.fromCharCode((f<10?48:55)+f)+o,e=(e-f)/r.BASE}return o},u=function(e){if(void 0!==o[e])return o[e];for(var n=0,t=1,i=r.BASE,f=1;t<e.length;n+=i,t++,i*=r.BASE);for(var u=e.length-1;u>=0;u--,f*=r.BASE){var s=e.charCodeAt(u)-48;s>10&&(s-=7),n+=s*f}return n},s=function(e){e.sort();for(var n=1;n<e.length;n++)e[n-1]===e[n]&&e.splice(n,1)},c=function(e,n){for(var t=Math.min(e.length,n.length);t>0;){var r=e.slice(0,t);if(r===n.slice(0,t))return r;t-=1}return""};n.exports={toAlphaCode:f,fromAlphaCode:u,unique:s,commonPrefix:c}},{"./config":1}],3:[function(e,n,t){"use strict";var r=e("./ptrie"),i=function(e){return new r(e)};n.exports=i},{"./ptrie":5}],4:[function(e,n,t){"use strict";var r=function(e,n){if(e===n)return!0;var t=e.length;return!(t>=n.length)&&(1===t?e===n[0]:n.slice(0,t)===e)};n.exports=r},{}],5:[function(e,n,t){"use strict";function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),o=e("../config"),f=e("../fns"),u=e("./prefix"),s=e("./unravel"),c=function(){function e(n){r(this,e),this.nodes=n.split(o.NODE_SEP),this.syms=[],this.symCount=0,this._cache=null,n.match(":")&&this.initSymbols()}return i(e,[{key:"initSymbols",value:function(){for(var e=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),n=0;n<this.nodes.length;n++){var t=e.exec(this.nodes[n]);if(!t){this.symCount=n;break}this.syms[f.fromAlphaCode(t[1])]=f.fromAlphaCode(t[2])}this.nodes=this.nodes.slice(this.symCount,this.nodes.length)}},{key:"has",value:function(e){var n=this;if(!e)return!1;if(this._cache)return this._cache[e]||!1;var t=function t(r,i){var o=n.nodes[r];if("!"===o[0]){if(i===e)return!0;o=o.slice(1)}for(var f=o.split(/([A-Z0-9,]+)/g),s=0;s<f.length;s+=2){var c=f[s],a=f[s+1];if(c){var l=i+c;if(","!==a&&void 0!==a){if(u(l,e))return r=n.indexFromRef(a,r),t(r,l)}else if(l===e)return!0}}return!1};return t(0,"")}},{key:"indexFromRef",value:function(e,n){var t=f.fromAlphaCode(e);return t<this.symCount?this.syms[t]:n+t+1-this.symCount}},{key:"toArray",value:function(){return this._cache?Object.keys(this._cache):Object.keys(s(this))}},{key:"cache",value:function(){this._cache=s(this),this.nodes=null,this.syms=null}}]),e}();n.exports=c},{"../config":1,"../fns":2,"./prefix":4,"./unravel":6}],6:[function(e,n,t){"use strict";var r=function(e){var n={},t=function t(r,i){var o=e.nodes[r];"!"===o[0]&&(n[i]=!0,o=o.slice(1));for(var f=o.split(/([A-Z0-9,]+)/g),u=0;u<f.length;u+=2){var s=f[u],c=f[u+1];if(s){var a=i+s;if(","!==c&&void 0!==c){var l=e.indexFromRef(c,r);t(l,a)}else n[a]=!0}}};return t(0,""),n};n.exports=r},{}]},{},[3])(3)});
/* efrt trie-compression v0.0.5 github.com/nlp-compromise/efrt - MIT */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.unpack=e()}}(function(){return function e(n,t,r){function i(u,f){if(!t[u]){if(!n[u]){var s="function"==typeof require&&require;if(!f&&s)return s(u,!0);if(o)return o(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return i(t?t:e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(e,n,t){"use strict";var r=36,i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",o=i.split("").reduce(function(e,n,t){return e[n]=t,e},{}),u=function(e){if(void 0!==i[e])return i[e];for(var n=1,t=r,o="";e>=t;e-=t,n++,t*=r);for(;n--;){var u=e%r;o=String.fromCharCode((u<10?48:55)+u)+o,e=(e-u)/r}return o},f=function(e){if(void 0!==o[e])return o[e];for(var n=0,t=1,i=r,u=1;t<e.length;n+=i,t++,i*=r);for(var f=e.length-1;f>=0;f--,u*=r){var s=e.charCodeAt(f)-48;s>10&&(s-=7),n+=s*u}return n};n.exports={toAlphaCode:u,fromAlphaCode:f}},{}],2:[function(e,n,t){"use strict";var r=e("./ptrie"),i=function(e){return new r(e)};n.exports=i},{"./ptrie":4}],3:[function(e,n,t){"use strict";var r=function(e,n){if(e===n)return!0;var t=e.length;return!(t>=n.length)&&(1===t?e===n[0]:n.slice(0,t)===e)};n.exports=r},{}],4:[function(e,n,t){"use strict";function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),o=e("../encoding"),u=e("./prefix"),f=e("./unravel"),s=function(){function e(n){r(this,e),this.nodes=n.split(";"),this.syms=[],this.symCount=0,this._cache=null,n.match(":")&&this.initSymbols()}return i(e,[{key:"initSymbols",value:function(){for(var e=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),n=0;n<this.nodes.length;n++){var t=e.exec(this.nodes[n]);if(!t){this.symCount=n;break}this.syms[o.fromAlphaCode(t[1])]=o.fromAlphaCode(t[2])}this.nodes=this.nodes.slice(this.symCount,this.nodes.length)}},{key:"has",value:function(e){var n=this;if(!e)return!1;if(this._cache)return this._cache[e]||!1;var t=function t(r,i){var o=n.nodes[r];if("!"===o[0]){if(i===e)return!0;o=o.slice(1)}for(var f=o.split(/([A-Z0-9,]+)/g),s=0;s<f.length;s+=2){var a=f[s],c=f[s+1];if(a){var l=i+a;if(","!==c&&void 0!==c){if(u(l,e))return r=n.indexFromRef(c,r),t(r,l)}else if(l===e)return!0}}return!1};return t(0,"")}},{key:"indexFromRef",value:function(e,n){var t=o.fromAlphaCode(e);return t<this.symCount?this.syms[t]:n+t+1-this.symCount}},{key:"toArray",value:function(){return Object.keys(this.toObject())}},{key:"toObject",value:function(){return this._cache?this._cache:f(this)}},{key:"cache",value:function(){this._cache=f(this),this.nodes=null,this.syms=null}}]),e}();n.exports=s},{"../encoding":1,"./prefix":3,"./unravel":5}],5:[function(e,n,t){"use strict";var r=function(e){var n={},t=function t(r,i){var o=e.nodes[r];"!"===o[0]&&(n[i]=!0,o=o.slice(1));for(var u=o.split(/([A-Z0-9,]+)/g),f=0;f<u.length;f+=2){var s=u[f],a=u[f+1];if(s){var c=i+s;if(","!==a&&void 0!==a){var l=e.indexFromRef(a,r);t(l,c)}else n[c]=!0}}};return t(0,""),n};n.exports=r},{}]},{},[2])(2)});

@@ -1,2 +0,2 @@

/* efrt trie-compression v0.0.4 github.com/nlp-compromise/efrt - MIT */
/* efrt trie-compression v0.0.5 github.com/nlp-compromise/efrt - MIT */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.efrt = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

@@ -17,3 +17,3 @@ 'use strict';

var config = _dereq_('./config');
var BASE = 36;

@@ -25,3 +25,2 @@ var seq = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

}, {});
// console.log(cache);

@@ -34,10 +33,10 @@ // 0, 1, 2, ..., A, B, C, ..., 00, 01, ... AA, AB, AC, ..., AAA, AAB, ...

var places = 1;
var range = config.BASE;
var range = BASE;
var s = '';
for (; n >= range; n -= range, places++, range *= config.BASE) {}
for (; n >= range; n -= range, places++, range *= BASE) {}
while (places--) {
var d = n % config.BASE;
var d = n % BASE;
s = String.fromCharCode((d < 10 ? 48 : 55) + d) + s;
n = (n - d) / config.BASE;
n = (n - d) / BASE;
}

@@ -53,7 +52,7 @@ return s;

var places = 1;
var range = config.BASE;
var range = BASE;
var pow = 1;
for (; places < s.length; n += range, places++, range *= config.BASE) {}
for (var i = s.length - 1; i >= 0; i--, pow *= config.BASE) {
for (; places < s.length; n += range, places++, range *= BASE) {}
for (var i = s.length - 1; i >= 0; i--, pow *= BASE) {
var d = s.charCodeAt(i) - 48;

@@ -68,12 +67,18 @@ if (d > 10) {

/* Sort elements and remove duplicates from array (modified in place) */
var unique = function unique(a) {
a.sort();
for (var i = 1; i < a.length; i++) {
if (a[i - 1] === a[i]) {
a.splice(i, 1);
}
}
module.exports = {
toAlphaCode: toAlphaCode,
fromAlphaCode: fromAlphaCode
};
},{}],3:[function(_dereq_,module,exports){
'use strict';
module.exports = {
pack: _dereq_('./pack/index'),
unpack: _dereq_('./unpack/index')
};
},{"./pack/index":6,"./unpack/index":9}],4:[function(_dereq_,module,exports){
'use strict';
var commonPrefix = function commonPrefix(w1, w2) {

@@ -91,23 +96,18 @@ var len = Math.min(w1.length, w2.length);

module.exports = {
toAlphaCode: toAlphaCode,
fromAlphaCode: fromAlphaCode,
unique: unique,
commonPrefix: commonPrefix
/* Sort elements and remove duplicates from array (modified in place) */
var unique = function unique(a) {
a.sort();
for (var i = 1; i < a.length; i++) {
if (a[i - 1] === a[i]) {
a.splice(i, 1);
}
}
};
// let out = fromAlphaCode('A');
// console.log(out);
// console.log(fromAlphaCode(out));
// console.log(fromAlphaCode('R'));
},{"./config":1}],3:[function(_dereq_,module,exports){
'use strict';
module.exports = {
pack: _dereq_('./pack/index'),
unpack: _dereq_('./unpack/index')
commonPrefix: commonPrefix,
unique: unique
};
},{"./pack/index":5,"./unpack/index":8}],4:[function(_dereq_,module,exports){
},{}],5:[function(_dereq_,module,exports){
'use strict';

@@ -181,3 +181,3 @@

},{}],5:[function(_dereq_,module,exports){
},{}],6:[function(_dereq_,module,exports){
'use strict';

@@ -194,3 +194,3 @@

},{"./trie":7}],6:[function(_dereq_,module,exports){
},{"./trie":8}],7:[function(_dereq_,module,exports){
'use strict';

@@ -200,3 +200,4 @@

var config = _dereq_('../config');
var fns = _dereq_('../fns');
var encoding = _dereq_('../encoding');
// Return packed representation of Trie as a string.

@@ -255,3 +256,3 @@

}
var ref = fns.toAlphaCode(node._n - node[prop]._n - 1 + self.symCount);
var ref = encoding.toAlphaCode(node._n - node[prop]._n - 1 + self.symCount);
// Large reference to smaller string suffix -> duplicate suffix

@@ -284,3 +285,3 @@ if (node[prop]._g && ref.length >= node[prop]._g.length && node[node[prop]._g] === 1) {

// reference to a one-character symbol.
self.histAbs.add(node[prop]._n, fns.toAlphaCode(ref).length - 1);
self.histAbs.add(node[prop]._n, encoding.toAlphaCode(ref).length - 1);
analyzeRefs(self, node[prop]);

@@ -296,3 +297,3 @@ }

sCount = 0;
var defSize = 3 + fns.toAlphaCode(self.nodeCount).length;
var defSize = 3 + encoding.toAlphaCode(self.nodeCount).length;
for (var sym = 0; sym < config.BASE; sym++) {

@@ -343,3 +344,3 @@ if (self.histAbs[sym] === undefined) {

for (var sym = 0; sym < self.symCount; sym++) {
self.syms[self.histAbs[sym][0]] = fns.toAlphaCode(sym);
self.syms[self.histAbs[sym][0]] = encoding.toAlphaCode(sym);
}

@@ -351,3 +352,3 @@ for (var i = 0; i < self.nodeCount; i++) {

for (var _sym = self.symCount - 1; _sym >= 0; _sym--) {
self.nodes.unshift(fns.toAlphaCode(_sym) + ':' + fns.toAlphaCode(self.nodeCount - self.histAbs[_sym][0] - 1));
self.nodes.unshift(encoding.toAlphaCode(_sym) + ':' + encoding.toAlphaCode(self.nodeCount - self.histAbs[_sym][0] - 1));
}

@@ -360,3 +361,3 @@

},{"../config":1,"../fns":2,"./histogram":4}],7:[function(_dereq_,module,exports){
},{"../config":1,"../encoding":2,"./histogram":5}],8:[function(_dereq_,module,exports){
'use strict';

@@ -370,3 +371,3 @@

var fns = _dereq_('../fns');
var fns = _dereq_('./fns');
var _pack = _dereq_('./pack');

@@ -715,7 +716,6 @@ var config = _dereq_('../config');

},{"../config":1,"../fns":2,"./pack":6}],8:[function(_dereq_,module,exports){
},{"../config":1,"./fns":4,"./pack":7}],9:[function(_dereq_,module,exports){
'use strict';
var Ptrie = _dereq_('./ptrie');
// const Ptrie = require('./ptrie_old');

@@ -727,3 +727,3 @@ var unpack = function unpack(str) {

},{"./ptrie":10}],9:[function(_dereq_,module,exports){
},{"./ptrie":11}],10:[function(_dereq_,module,exports){
'use strict';

@@ -752,3 +752,3 @@

},{}],10:[function(_dereq_,module,exports){
},{}],11:[function(_dereq_,module,exports){
'use strict';

@@ -760,4 +760,3 @@

var config = _dereq_('../config');
var fns = _dereq_('../fns');
var encoding = _dereq_('../encoding');
var isPrefix = _dereq_('./prefix');

@@ -772,3 +771,3 @@ var unravel = _dereq_('./unravel');

this.nodes = str.split(config.NODE_SEP); //that's all ;)!
this.nodes = str.split(';'); //that's all ;)!
this.syms = [];

@@ -797,3 +796,3 @@ this.symCount = 0;

}
this.syms[fns.fromAlphaCode(m[1])] = fns.fromAlphaCode(m[2]);
this.syms[encoding.fromAlphaCode(m[1])] = encoding.fromAlphaCode(m[2]);
}

@@ -811,3 +810,2 @@ //remove from main node list

// console.log(this.nodes);
//fail-fast

@@ -869,3 +867,3 @@ if (!want) {

value: function indexFromRef(ref, index) {
var dnode = fns.fromAlphaCode(ref);
var dnode = encoding.fromAlphaCode(ref);
if (dnode < this.symCount) {

@@ -879,6 +877,11 @@ return this.syms[dnode];

value: function toArray() {
return Object.keys(this.toObject());
}
}, {
key: 'toObject',
value: function toObject() {
if (this._cache) {
return Object.keys(this._cache);
return this._cache;
}
return Object.keys(unravel(this));
return unravel(this);
}

@@ -899,3 +902,3 @@ }, {

},{"../config":1,"../fns":2,"./prefix":9,"./unravel":11}],11:[function(_dereq_,module,exports){
},{"../encoding":2,"./prefix":10,"./unravel":12}],12:[function(_dereq_,module,exports){
'use strict';

@@ -902,0 +905,0 @@

@@ -1,2 +0,2 @@

/* efrt trie-compression v0.0.4 github.com/nlp-compromise/efrt - MIT */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.efrt=e()}}(function(){return function e(t,n,i){function r(s,u){if(!n[s]){if(!t[s]){var f="function"==typeof require&&require;if(!u&&f)return f(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return r(n?n:e)},c,c.exports,e,t,n,i)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<i.length;s++)r(i[s]);return r}({1:[function(e,t,n){"use strict";t.exports={NODE_SEP:";",STRING_SEP:",",TERMINAL_PREFIX:"!",NOT_ALLOWED:new RegExp("[0-9A-Z,;!]"),BASE:36}},{}],2:[function(e,t,n){"use strict";var i=e("./config"),r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",o=r.split("").reduce(function(e,t,n){return e[t]=n,e},{}),s=function(e){if(void 0!==r[e])return r[e];for(var t=1,n=i.BASE,o="";e>=n;e-=n,t++,n*=i.BASE);for(;t--;){var s=e%i.BASE;o=String.fromCharCode((s<10?48:55)+s)+o,e=(e-s)/i.BASE}return o},u=function(e){if(void 0!==o[e])return o[e];for(var t=0,n=1,r=i.BASE,s=1;n<e.length;t+=r,n++,r*=i.BASE);for(var u=e.length-1;u>=0;u--,s*=i.BASE){var f=e.charCodeAt(u)-48;f>10&&(f-=7),t+=f*s}return t},f=function(e){e.sort();for(var t=1;t<e.length;t++)e[t-1]===e[t]&&e.splice(t,1)},a=function(e,t){for(var n=Math.min(e.length,t.length);n>0;){var i=e.slice(0,n);if(i===t.slice(0,n))return i;n-=1}return""};t.exports={toAlphaCode:s,fromAlphaCode:u,unique:f,commonPrefix:a}},{"./config":1}],3:[function(e,t,n){"use strict";t.exports={pack:e("./pack/index"),unpack:e("./unpack/index")}},{"./pack/index":5,"./unpack/index":8}],4:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),o=function(){function e(){i(this,e),this.counts={}}return r(e,[{key:"init",value:function(e){void 0===this.counts[e]&&(this.counts[e]=0)}},{key:"add",value:function(e,t){void 0===t&&(t=1),this.init(e),this.counts[e]+=t}},{key:"change",value:function(e,t,n){void 0===n&&(n=1),this.add(t,-n),this.add(e,n)}},{key:"countOf",value:function(e){return this.init(e),this.counts[e]}},{key:"highest",value:function(e){for(var t=[],n=Object.keys(this.counts),i=0;i<n.length;i++){var r=n[i];t.push([r,this.counts[r]])}return t.sort(function(e,t){return t[1]-e[1]}),e&&(t=t.slice(0,e)),t}}]),e}();t.exports=o},{}],5:[function(e,t,n){"use strict";var i=e("./trie"),r=function(e){var t=new i(e);return t.pack()};t.exports=r},{"./trie":7}],6:[function(e,t,n){"use strict";var i=e("./histogram"),r=e("../config"),o=e("../fns"),s=function(e,t){var n="",i="";e.isTerminal(t)&&(n+=r.TERMINAL_PREFIX);for(var s=e.nodeProps(t),u=0;u<s.length;u++){var f=s[u];if("number"!=typeof t[f])if(e.syms[t[f]._n])n+=i+f+e.syms[t[f]._n],i="";else{var a=o.toAlphaCode(t._n-t[f]._n-1+e.symCount);t[f]._g&&a.length>=t[f]._g.length&&1===t[t[f]._g]?(a=t[f]._g,n+=i+f+a,i=r.STRING_SEP):(n+=i+f+a,i="")}else n+=i+f,i=r.STRING_SEP}return n},u=function e(t,n){if(!t.visited(n))for(var i=t.nodeProps(n,!0),s=0;s<i.length;s++){var u=i[s],f=n._n-n[u]._n-1;f<r.BASE&&t.histRel.add(f),t.histAbs.add(n[u]._n,o.toAlphaCode(f).length-1),e(t,n[u])}},f=function(e){e.histAbs=e.histAbs.highest(r.BASE);var t=[];t[-1]=0;for(var n=0,i=0,s=3+o.toAlphaCode(e.nodeCount).length,u=0;u<r.BASE&&void 0!==e.histAbs[u];u++)t[u]=e.histAbs[u][1]-s-e.histRel.countOf(r.BASE-u-1)+t[u-1],t[u]>=n&&(n=t[u],i=u+1);return i},a=function e(t,n){if(void 0===n._n){for(var i=t.nodeProps(n,!0),r=0;r<i.length;r++)e(t,n[i[r]]);n._n=t.pos++,t.nodes.unshift(n)}},c=function(e){e.nodes=[],e.nodeCount=0,e.syms={},e.symCount=0,e.pos=0,e.optimize(),e.histAbs=new i,e.histRel=new i,a(e,e.root),e.nodeCount=e.nodes.length,e.prepDFS(),u(e,e.root),e.symCount=f(e);for(var t=0;t<e.symCount;t++)e.syms[e.histAbs[t][0]]=o.toAlphaCode(t);for(var n=0;n<e.nodeCount;n++)e.nodes[n]=s(e,e.nodes[n]);for(var c=e.symCount-1;c>=0;c--)e.nodes.unshift(o.toAlphaCode(c)+":"+o.toAlphaCode(e.nodeCount-e.histAbs[c][0]-1));return e.nodes.join(r.NODE_SEP)};t.exports=c},{"../config":1,"../fns":2,"./histogram":4}],7:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),s=e("../fns"),u=e("./pack"),f=e("../config"),a=function(){function e(t){i(this,e),this.root={},this.lastWord="",this.suffixes={},this.suffixCounts={},this.cNext=1,this.wordCount=0,this.insertWords(t),this.vCur=0}return o(e,[{key:"insertWords",value:function(e){if(void 0!==e){"string"==typeof e&&(e=e.split(/[^a-zA-Z]+/));for(var t=0;t<e.length;t++)e[t]=e[t].toLowerCase();s.unique(e);for(var n=0;n<e.length;n++)null===e[n].match(f.NOT_ALLOWED)&&this.insert(e[n])}}},{key:"insert",value:function(e){this._insert(e,this.root);var t=this.lastWord;this.lastWord=e;var n=s.commonPrefix(e,t);if(n!==t){var i=this.uniqueNode(t,e,this.root);i&&this.combineSuffixNode(i)}}},{key:"_insert",value:function(e,t){var n=void 0,i=void 0;if(0!==e.length){for(var o=Object.keys(t),u=0;u<o.length;u++){var f=o[u];if(n=s.commonPrefix(e,f),0!==n.length){if(f===n&&"object"===r(t[f]))return void this._insert(e.slice(n.length),t[f]);if(f===e&&"number"==typeof t[f])return;return i={},i[f.slice(n.length)]=t[f],this.addTerminal(i,e=e.slice(n.length)),delete t[f],t[n]=i,void this.wordCount++}}this.addTerminal(t,e),this.wordCount++}}},{key:"addTerminal",value:function(e,t){if(t.length<=1)return void(e[t]=1);var n={};e[t[0]]=n,this.addTerminal(n,t.slice(1))}},{key:"nodeProps",value:function(e,t){var n=[];for(var i in e)""!==i&&"_"!==i[0]&&(t&&"object"!==r(e[i])||n.push(i));return n.sort(),n}},{key:"optimize",value:function(){this.combineSuffixNode(this.root),this.prepDFS(),this.countDegree(this.root),this.prepDFS(),this.collapseChains(this.root)}},{key:"combineSuffixNode",value:function(e){if(e._c)return e;var t=[];this.isTerminal(e)&&t.push("!");for(var n=this.nodeProps(e),i=0;i<n.length;i++){var o=n[i];"object"===r(e[o])?(e[o]=this.combineSuffixNode(e[o]),t.push(o),t.push(e[o]._c)):t.push(o)}t=t.join("-");var s=this.suffixes[t];return s?s:(this.suffixes[t]=e,e._c=this.cNext++,e)}},{key:"prepDFS",value:function(){this.vCur++}},{key:"visited",value:function(e){return e._v===this.vCur||(e._v=this.vCur,!1)}},{key:"countDegree",value:function(e){if(void 0===e._d&&(e._d=0),e._d++,!this.visited(e))for(var t=this.nodeProps(e,!0),n=0;n<t.length;n++)this.countDegree(e[t[n]])}},{key:"collapseChains",value:function(e){var t=void 0,n=void 0,i=void 0,o=void 0;if(!this.visited(e)){for(n=this.nodeProps(e),o=0;o<n.length;o++)t=n[o],i=e[t],"object"===("undefined"==typeof i?"undefined":r(i))&&(this.collapseChains(i),void 0===i._g||1!==i._d&&1!==i._g.length||(delete e[t],t+=i._g,e[t]=i[i._g]));1!==n.length||this.isTerminal(e)||(e._g=t)}}},{key:"has",value:function(e){return this.isFragment(e,this.root)}},{key:"isTerminal",value:function(e){return!!e[""]}},{key:"isFragment",value:function(e,t){if(0===e.length)return this.isTerminal(t);if(1===t[e])return!0;for(var n=this.nodeProps(t,!0),i=0;i<n.length;i++){var r=n[i];if(r===e.slice(0,r.length))return this.isFragment(e.slice(r.length),t[r])}return!1}},{key:"uniqueNode",value:function(e,t,n){for(var i=this.nodeProps(n,!0),r=0;r<i.length;r++){var o=i[r];if(o===e.slice(0,o.length))return o!==t.slice(0,o.length)?n[o]:this.uniqueNode(e.slice(o.length),t.slice(o.length),n[o])}}},{key:"pack",value:function(){return u(this)}}]),e}();t.exports=a},{"../config":1,"../fns":2,"./pack":6}],8:[function(e,t,n){"use strict";var i=e("./ptrie"),r=function(e){return new i(e)};t.exports=r},{"./ptrie":10}],9:[function(e,t,n){"use strict";var i=function(e,t){if(e===t)return!0;var n=e.length;return!(n>=t.length)&&(1===n?e===t[0]:t.slice(0,n)===e)};t.exports=i},{}],10:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),o=e("../config"),s=e("../fns"),u=e("./prefix"),f=e("./unravel"),a=function(){function e(t){i(this,e),this.nodes=t.split(o.NODE_SEP),this.syms=[],this.symCount=0,this._cache=null,t.match(":")&&this.initSymbols()}return r(e,[{key:"initSymbols",value:function(){for(var e=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),t=0;t<this.nodes.length;t++){var n=e.exec(this.nodes[t]);if(!n){this.symCount=t;break}this.syms[s.fromAlphaCode(n[1])]=s.fromAlphaCode(n[2])}this.nodes=this.nodes.slice(this.symCount,this.nodes.length)}},{key:"has",value:function(e){var t=this;if(!e)return!1;if(this._cache)return this._cache[e]||!1;var n=function n(i,r){var o=t.nodes[i];if("!"===o[0]){if(r===e)return!0;o=o.slice(1)}for(var s=o.split(/([A-Z0-9,]+)/g),f=0;f<s.length;f+=2){var a=s[f],c=s[f+1];if(a){var h=r+a;if(","!==c&&void 0!==c){if(u(h,e))return i=t.indexFromRef(c,i),n(i,h)}else if(h===e)return!0}}return!1};return n(0,"")}},{key:"indexFromRef",value:function(e,t){var n=s.fromAlphaCode(e);return n<this.symCount?this.syms[n]:t+n+1-this.symCount}},{key:"toArray",value:function(){return this._cache?Object.keys(this._cache):Object.keys(f(this))}},{key:"cache",value:function(){this._cache=f(this),this.nodes=null,this.syms=null}}]),e}();t.exports=a},{"../config":1,"../fns":2,"./prefix":9,"./unravel":11}],11:[function(e,t,n){"use strict";var i=function(e){var t={},n=function n(i,r){var o=e.nodes[i];"!"===o[0]&&(t[r]=!0,o=o.slice(1));for(var s=o.split(/([A-Z0-9,]+)/g),u=0;u<s.length;u+=2){var f=s[u],a=s[u+1];if(f){var c=r+f;if(","!==a&&void 0!==a){var h=e.indexFromRef(a,i);n(h,c)}else t[c]=!0}}};return n(0,""),t};t.exports=i},{}]},{},[3])(3)});
/* efrt trie-compression v0.0.5 github.com/nlp-compromise/efrt - MIT */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.efrt=t()}}(function(){return function t(e,n,i){function r(s,u){if(!n[s]){if(!e[s]){var f="function"==typeof require&&require;if(!u&&f)return f(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return r(n?n:t)},c,c.exports,t,e,n,i)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<i.length;s++)r(i[s]);return r}({1:[function(t,e,n){"use strict";e.exports={NODE_SEP:";",STRING_SEP:",",TERMINAL_PREFIX:"!",NOT_ALLOWED:new RegExp("[0-9A-Z,;!]"),BASE:36}},{}],2:[function(t,e,n){"use strict";var i=36,r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",o=r.split("").reduce(function(t,e,n){return t[e]=n,t},{}),s=function(t){if(void 0!==r[t])return r[t];for(var e=1,n=i,o="";t>=n;t-=n,e++,n*=i);for(;e--;){var s=t%i;o=String.fromCharCode((s<10?48:55)+s)+o,t=(t-s)/i}return o},u=function(t){if(void 0!==o[t])return o[t];for(var e=0,n=1,r=i,s=1;n<t.length;e+=r,n++,r*=i);for(var u=t.length-1;u>=0;u--,s*=i){var f=t.charCodeAt(u)-48;f>10&&(f-=7),e+=f*s}return e};e.exports={toAlphaCode:s,fromAlphaCode:u}},{}],3:[function(t,e,n){"use strict";e.exports={pack:t("./pack/index"),unpack:t("./unpack/index")}},{"./pack/index":6,"./unpack/index":9}],4:[function(t,e,n){"use strict";var i=function(t,e){for(var n=Math.min(t.length,e.length);n>0;){var i=t.slice(0,n);if(i===e.slice(0,n))return i;n-=1}return""},r=function(t){t.sort();for(var e=1;e<t.length;e++)t[e-1]===t[e]&&t.splice(e,1)};e.exports={commonPrefix:i,unique:r}},{}],5:[function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),o=function(){function t(){i(this,t),this.counts={}}return r(t,[{key:"init",value:function(t){void 0===this.counts[t]&&(this.counts[t]=0)}},{key:"add",value:function(t,e){void 0===e&&(e=1),this.init(t),this.counts[t]+=e}},{key:"change",value:function(t,e,n){void 0===n&&(n=1),this.add(e,-n),this.add(t,n)}},{key:"countOf",value:function(t){return this.init(t),this.counts[t]}},{key:"highest",value:function(t){for(var e=[],n=Object.keys(this.counts),i=0;i<n.length;i++){var r=n[i];e.push([r,this.counts[r]])}return e.sort(function(t,e){return e[1]-t[1]}),t&&(e=e.slice(0,t)),e}}]),t}();e.exports=o},{}],6:[function(t,e,n){"use strict";var i=t("./trie"),r=function(t){var e=new i(t);return e.pack()};e.exports=r},{"./trie":8}],7:[function(t,e,n){"use strict";var i=t("./histogram"),r=t("../config"),o=t("../encoding"),s=function(t,e){var n="",i="";t.isTerminal(e)&&(n+=r.TERMINAL_PREFIX);for(var s=t.nodeProps(e),u=0;u<s.length;u++){var f=s[u];if("number"!=typeof e[f])if(t.syms[e[f]._n])n+=i+f+t.syms[e[f]._n],i="";else{var a=o.toAlphaCode(e._n-e[f]._n-1+t.symCount);e[f]._g&&a.length>=e[f]._g.length&&1===e[e[f]._g]?(a=e[f]._g,n+=i+f+a,i=r.STRING_SEP):(n+=i+f+a,i="")}else n+=i+f,i=r.STRING_SEP}return n},u=function t(e,n){if(!e.visited(n))for(var i=e.nodeProps(n,!0),s=0;s<i.length;s++){var u=i[s],f=n._n-n[u]._n-1;f<r.BASE&&e.histRel.add(f),e.histAbs.add(n[u]._n,o.toAlphaCode(f).length-1),t(e,n[u])}},f=function(t){t.histAbs=t.histAbs.highest(r.BASE);var e=[];e[-1]=0;for(var n=0,i=0,s=3+o.toAlphaCode(t.nodeCount).length,u=0;u<r.BASE&&void 0!==t.histAbs[u];u++)e[u]=t.histAbs[u][1]-s-t.histRel.countOf(r.BASE-u-1)+e[u-1],e[u]>=n&&(n=e[u],i=u+1);return i},a=function t(e,n){if(void 0===n._n){for(var i=e.nodeProps(n,!0),r=0;r<i.length;r++)t(e,n[i[r]]);n._n=e.pos++,e.nodes.unshift(n)}},c=function(t){t.nodes=[],t.nodeCount=0,t.syms={},t.symCount=0,t.pos=0,t.optimize(),t.histAbs=new i,t.histRel=new i,a(t,t.root),t.nodeCount=t.nodes.length,t.prepDFS(),u(t,t.root),t.symCount=f(t);for(var e=0;e<t.symCount;e++)t.syms[t.histAbs[e][0]]=o.toAlphaCode(e);for(var n=0;n<t.nodeCount;n++)t.nodes[n]=s(t,t.nodes[n]);for(var c=t.symCount-1;c>=0;c--)t.nodes.unshift(o.toAlphaCode(c)+":"+o.toAlphaCode(t.nodeCount-t.histAbs[c][0]-1));return t.nodes.join(r.NODE_SEP)};e.exports=c},{"../config":1,"../encoding":2,"./histogram":5}],8:[function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),s=t("./fns"),u=t("./pack"),f=t("../config"),a=function(){function t(e){i(this,t),this.root={},this.lastWord="",this.suffixes={},this.suffixCounts={},this.cNext=1,this.wordCount=0,this.insertWords(e),this.vCur=0}return o(t,[{key:"insertWords",value:function(t){if(void 0!==t){"string"==typeof t&&(t=t.split(/[^a-zA-Z]+/));for(var e=0;e<t.length;e++)t[e]=t[e].toLowerCase();s.unique(t);for(var n=0;n<t.length;n++)null===t[n].match(f.NOT_ALLOWED)&&this.insert(t[n])}}},{key:"insert",value:function(t){this._insert(t,this.root);var e=this.lastWord;this.lastWord=t;var n=s.commonPrefix(t,e);if(n!==e){var i=this.uniqueNode(e,t,this.root);i&&this.combineSuffixNode(i)}}},{key:"_insert",value:function(t,e){var n=void 0,i=void 0;if(0!==t.length){for(var o=Object.keys(e),u=0;u<o.length;u++){var f=o[u];if(n=s.commonPrefix(t,f),0!==n.length){if(f===n&&"object"===r(e[f]))return void this._insert(t.slice(n.length),e[f]);if(f===t&&"number"==typeof e[f])return;return i={},i[f.slice(n.length)]=e[f],this.addTerminal(i,t=t.slice(n.length)),delete e[f],e[n]=i,void this.wordCount++}}this.addTerminal(e,t),this.wordCount++}}},{key:"addTerminal",value:function(t,e){if(e.length<=1)return void(t[e]=1);var n={};t[e[0]]=n,this.addTerminal(n,e.slice(1))}},{key:"nodeProps",value:function(t,e){var n=[];for(var i in t)""!==i&&"_"!==i[0]&&(e&&"object"!==r(t[i])||n.push(i));return n.sort(),n}},{key:"optimize",value:function(){this.combineSuffixNode(this.root),this.prepDFS(),this.countDegree(this.root),this.prepDFS(),this.collapseChains(this.root)}},{key:"combineSuffixNode",value:function(t){if(t._c)return t;var e=[];this.isTerminal(t)&&e.push("!");for(var n=this.nodeProps(t),i=0;i<n.length;i++){var o=n[i];"object"===r(t[o])?(t[o]=this.combineSuffixNode(t[o]),e.push(o),e.push(t[o]._c)):e.push(o)}e=e.join("-");var s=this.suffixes[e];return s?s:(this.suffixes[e]=t,t._c=this.cNext++,t)}},{key:"prepDFS",value:function(){this.vCur++}},{key:"visited",value:function(t){return t._v===this.vCur||(t._v=this.vCur,!1)}},{key:"countDegree",value:function(t){if(void 0===t._d&&(t._d=0),t._d++,!this.visited(t))for(var e=this.nodeProps(t,!0),n=0;n<e.length;n++)this.countDegree(t[e[n]])}},{key:"collapseChains",value:function(t){var e=void 0,n=void 0,i=void 0,o=void 0;if(!this.visited(t)){for(n=this.nodeProps(t),o=0;o<n.length;o++)e=n[o],i=t[e],"object"===("undefined"==typeof i?"undefined":r(i))&&(this.collapseChains(i),void 0===i._g||1!==i._d&&1!==i._g.length||(delete t[e],e+=i._g,t[e]=i[i._g]));1!==n.length||this.isTerminal(t)||(t._g=e)}}},{key:"has",value:function(t){return this.isFragment(t,this.root)}},{key:"isTerminal",value:function(t){return!!t[""]}},{key:"isFragment",value:function(t,e){if(0===t.length)return this.isTerminal(e);if(1===e[t])return!0;for(var n=this.nodeProps(e,!0),i=0;i<n.length;i++){var r=n[i];if(r===t.slice(0,r.length))return this.isFragment(t.slice(r.length),e[r])}return!1}},{key:"uniqueNode",value:function(t,e,n){for(var i=this.nodeProps(n,!0),r=0;r<i.length;r++){var o=i[r];if(o===t.slice(0,o.length))return o!==e.slice(0,o.length)?n[o]:this.uniqueNode(t.slice(o.length),e.slice(o.length),n[o])}}},{key:"pack",value:function(){return u(this)}}]),t}();e.exports=a},{"../config":1,"./fns":4,"./pack":7}],9:[function(t,e,n){"use strict";var i=t("./ptrie"),r=function(t){return new i(t)};e.exports=r},{"./ptrie":11}],10:[function(t,e,n){"use strict";var i=function(t,e){if(t===e)return!0;var n=t.length;return!(n>=e.length)&&(1===n?t===e[0]:e.slice(0,n)===t)};e.exports=i},{}],11:[function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),o=t("../encoding"),s=t("./prefix"),u=t("./unravel"),f=function(){function t(e){i(this,t),this.nodes=e.split(";"),this.syms=[],this.symCount=0,this._cache=null,e.match(":")&&this.initSymbols()}return r(t,[{key:"initSymbols",value:function(){for(var t=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),e=0;e<this.nodes.length;e++){var n=t.exec(this.nodes[e]);if(!n){this.symCount=e;break}this.syms[o.fromAlphaCode(n[1])]=o.fromAlphaCode(n[2])}this.nodes=this.nodes.slice(this.symCount,this.nodes.length)}},{key:"has",value:function(t){var e=this;if(!t)return!1;if(this._cache)return this._cache[t]||!1;var n=function n(i,r){var o=e.nodes[i];if("!"===o[0]){if(r===t)return!0;o=o.slice(1)}for(var u=o.split(/([A-Z0-9,]+)/g),f=0;f<u.length;f+=2){var a=u[f],c=u[f+1];if(a){var h=r+a;if(","!==c&&void 0!==c){if(s(h,t))return i=e.indexFromRef(c,i),n(i,h)}else if(h===t)return!0}}return!1};return n(0,"")}},{key:"indexFromRef",value:function(t,e){var n=o.fromAlphaCode(t);return n<this.symCount?this.syms[n]:e+n+1-this.symCount}},{key:"toArray",value:function(){return Object.keys(this.toObject())}},{key:"toObject",value:function(){return this._cache?this._cache:u(this)}},{key:"cache",value:function(){this._cache=u(this),this.nodes=null,this.syms=null}}]),t}();e.exports=f},{"../encoding":2,"./prefix":10,"./unravel":12}],12:[function(t,e,n){"use strict";var i=function(t){var e={},n=function n(i,r){var o=t.nodes[i];"!"===o[0]&&(e[r]=!0,o=o.slice(1));for(var s=o.split(/([A-Z0-9,]+)/g),u=0;u<s.length;u+=2){var f=s[u],a=s[u+1];if(f){var c=r+f;if(","!==a&&void 0!==a){var h=t.indexFromRef(a,i);n(h,c)}else e[c]=!0}}};return n(0,""),e};e.exports=i},{}]},{},[3])(3)});

@@ -5,3 +5,3 @@ {

"description": "compressed-trie data-structure",
"version": "0.0.4",
"version": "0.0.5",
"main": "./builds/efrt.js",

@@ -14,8 +14,7 @@ "repository": {

"test": "node ./scripts/test.js",
"build": "node ./scripts/build.js",
"build": "node ./scripts/build/index.js",
"watch": "node ./scripts/watch.js"
},
"files": [
"builds/",
"src/"
"builds/"
],

@@ -22,0 +21,0 @@ "dependencies": {},

@@ -76,3 +76,3 @@ <div align="center">

In this example, with 1k words, it makes sense to hit `.cache()` if you are going to do more-than 5 lookups on the trie, but your mileage may vary.
You can access the object from `trie._cache` if you'd like use it directly.
You can access the object from `trie.toObject()`, or `trie.toArray()` if you'd like use it directly.

@@ -79,0 +79,0 @@ ## Size

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc