Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "radix-trie", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "radix-trie implementation for Inverse Index Document Search.", | ||
"main": "radixtrie.js", | ||
"main": "dist/radixtrie.js", | ||
"scripts": { | ||
"test": "tape tests/*.js" | ||
"build": "rollup -c", | ||
"test": "tape tests/*.js", | ||
"prepublish": "npm run build" | ||
}, | ||
@@ -26,8 +28,13 @@ "repository": { | ||
"homepage": "https://github.com/Plataforma5/radix-trie#readme", | ||
"dependencies": { | ||
"devDependencies": { | ||
"babel-plugin-external-helpers": "~6.22.0", | ||
"babel-preset-es2015": "~6.24.1", | ||
"babel-preset-es2015-rollup": "~3.0.0", | ||
"rollup": "~0.41.6", | ||
"rollup-plugin-babel": "~2.7.1", | ||
"rollup-plugin-commonjs": "~8.0.2", | ||
"rollup-plugin-node-resolve": "~3.0.0", | ||
"rword": "^2.1.0", | ||
"tape": "^4.6.3" | ||
}, | ||
"devDependencies": { | ||
"rword": "^2.1.0" | ||
} | ||
} |
@@ -33,3 +33,3 @@ const isEmpty = require('./utils.js').isEmpty; | ||
module.exports = class radixTrie { | ||
module.exports = class RadixTrie { | ||
constructor(lang = 'es') { | ||
@@ -40,5 +40,13 @@ this.root = new Root(); | ||
} | ||
addWord(word, data, node) { | ||
if (typeof word !== 'string') { | ||
word = String(word); | ||
} | ||
word = replace(word.toLowerCase()); | ||
if (typeof word !== 'string') return new Error('TypeError: the word to add to the radix-tree should be a String'); | ||
if (typeof word !== 'string') { | ||
return new Error('TypeError: the word to add to the radix-tree should be a String'); | ||
} | ||
if (!node) { | ||
@@ -67,2 +75,3 @@ node = this.root; | ||
} | ||
if (node.labels[lcp]) { // If the label for the lcp exists | ||
@@ -78,2 +87,3 @@ return this.addWord(word.substring(lcp.length), data, node.labels[lcp]); | ||
} | ||
addMany(wordArray, data) { | ||
@@ -86,2 +96,3 @@ data = { id: uuid(), data }; | ||
} | ||
findPartial(word) { | ||
@@ -104,2 +115,3 @@ const node = this.find(word); | ||
} | ||
for (let i = 1; i <= word.length; i += 1) { | ||
@@ -110,2 +122,3 @@ if (this.labels[word.slice(0, i)]) { | ||
} | ||
return false; | ||
@@ -115,2 +128,5 @@ } | ||
find(word) { | ||
if (typeof word !== 'string') { | ||
word = String(word); | ||
} | ||
const tree = this; | ||
@@ -121,4 +137,8 @@ return this.search.call(this.root, replace(word.toLowerCase()), tree); | ||
findNode(word) { | ||
if (typeof word !== 'string') { | ||
word = String(word); | ||
} | ||
word = word.toLowerCase(); | ||
const node = this.find(word); | ||
if (node) { | ||
@@ -130,4 +150,6 @@ return { | ||
} | ||
return node; | ||
} | ||
findData(substring, node) { | ||
@@ -203,2 +225,3 @@ if (!node) { | ||
} | ||
removeData(node, parent, data, word) { | ||
@@ -252,2 +275,3 @@ if (node.data.length > 1 || Object.keys(node.labels).length > 1) { | ||
} | ||
filterStopWords(word) { | ||
@@ -254,0 +278,0 @@ return this.stopwords.indexOf(word) === -1; |
module.exports = [ | ||
'I', | ||
'i' | ||
'a', | ||
'about', | ||
'an', | ||
'are', | ||
'as', | ||
'at', | ||
'be', | ||
'by', | ||
'com', | ||
'for', | ||
'from', | ||
'how', | ||
'in', | ||
'is', | ||
'it', | ||
'of', | ||
'on', | ||
'or', | ||
'that', | ||
'the', | ||
'this', | ||
'to', | ||
'what', | ||
'when', | ||
'where', | ||
'who', | ||
'will', | ||
'with', | ||
'the', | ||
'www' | ||
] | ||
"a", | ||
"about", | ||
"an", | ||
"are", | ||
"as", | ||
"at", | ||
"be", | ||
"by", | ||
"com", | ||
"for", | ||
"from", | ||
"how", | ||
"i", | ||
"I", | ||
"in", | ||
"is", | ||
"it", | ||
"of", | ||
"on", | ||
"or", | ||
"that", | ||
"the", | ||
"the", | ||
"this", | ||
"to", | ||
"what", | ||
"when", | ||
"where", | ||
"who", | ||
"will", | ||
"with", | ||
"www" | ||
] |
module.exports = [ | ||
'un', | ||
'una', | ||
'unas', | ||
'unos', | ||
'uno', | ||
'sobre', | ||
'todo', | ||
'también', | ||
'tras', | ||
'otro', | ||
'ser', | ||
'es', | ||
'soy', | ||
'eres', | ||
'somos', | ||
'sois', | ||
'estoy', | ||
'esta', | ||
'estais', | ||
'estan', | ||
'como', | ||
'en', | ||
'para', | ||
'atras', | ||
'porque', | ||
'por qué', | ||
'ante', | ||
'antes', | ||
'ambos', | ||
'pero', | ||
'por', | ||
'puede', | ||
'puedo', | ||
'cada', | ||
'fin', | ||
'incluso', | ||
'gueno', | ||
'ha', | ||
'el', | ||
'la', | ||
'lo', | ||
'las', | ||
'los', | ||
'su', | ||
'aqui', | ||
'mio', | ||
'tuyo', | ||
'ellos', | ||
'ellas', | ||
'nos', | ||
'nosotros', | ||
'vosotros', | ||
'vosotras', | ||
'si', | ||
'dentro', | ||
'solo', | ||
'solamente', | ||
'bastante', | ||
'muchos', | ||
'aquellos', | ||
'aquellas', | ||
'sus', | ||
'dos', | ||
'muy', | ||
'cual', | ||
'cuando', | ||
'donde', | ||
'mientras', | ||
'quien', | ||
'con', | ||
'entre', | ||
'sin', | ||
'yo', | ||
'aquel', | ||
].sort(); | ||
"ambos", | ||
"ante", | ||
"antes", | ||
"aquel", | ||
"aquellas", | ||
"aquellos", | ||
"aqui", | ||
"atras", | ||
"bastante", | ||
"cada", | ||
"como", | ||
"con", | ||
"cual", | ||
"cuando", | ||
"dentro", | ||
"donde", | ||
"dos", | ||
"el", | ||
"ellas", | ||
"ellos", | ||
"en", | ||
"entre", | ||
"eres", | ||
"es", | ||
"esta", | ||
"estais", | ||
"estan", | ||
"estoy", | ||
"fin", | ||
"gueno", | ||
"ha", | ||
"incluso", | ||
"la", | ||
"las", | ||
"lo", | ||
"los", | ||
"mientras", | ||
"mio", | ||
"muchos", | ||
"muy", | ||
"nos", | ||
"nosotros", | ||
"otro", | ||
"para", | ||
"pero", | ||
"por qué", | ||
"por", | ||
"porque", | ||
"puede", | ||
"puedo", | ||
"quien", | ||
"ser", | ||
"si", | ||
"sin", | ||
"sobre", | ||
"sois", | ||
"solamente", | ||
"solo", | ||
"somos", | ||
"soy", | ||
"su", | ||
"sus", | ||
"también", | ||
"todo", | ||
"tras", | ||
"tuyo", | ||
"un", | ||
"una", | ||
"unas", | ||
"uno", | ||
"unos", | ||
"vosotras", | ||
"vosotros", | ||
"yo" | ||
] |
module.exports = { | ||
es: require('./es.js'), | ||
en: require('./en'), | ||
es: require('./es'), | ||
}; |
@@ -74,3 +74,3 @@ const test = require('tape'); | ||
test('Test findMany', (t) => { | ||
t.plan(6); | ||
t.plan(7); | ||
const trie = new RadixTrie(); | ||
@@ -80,2 +80,3 @@ trie.addMany(['hola', 'test'], 1); | ||
trie.addMany(['hola', 'teresa', 'chao'], 3); | ||
trie.addMany(['agregar', 'agregacion'], 4); | ||
@@ -88,2 +89,3 @@ t.ok(Array.isArray(trie.findMany(['test', 'hola'])), 'Should be an Array'); | ||
t.equal(trie.findMany(['t']).length, 3, 'Should find all'); | ||
t.equal(trie.findMany(['agre']).length, 1, 'Should remove duplicates'); | ||
}); | ||
@@ -90,0 +92,0 @@ |
@@ -60,2 +60,11 @@ const test = require('tape'); | ||
test('Integers as words', (t) => { | ||
t.plan(1); | ||
const trie = new RadixTrie(); | ||
trie.addWord(1234, 1234); | ||
trie.addWord(0, 0); | ||
t.ok(trie.findNode(1234) && trie.findNode(0), 'Should find the two nodes.'); | ||
}); | ||
test('Count words', (t) => { | ||
@@ -62,0 +71,0 @@ const trie = new RadixTrie(); |
Sorry, the diff of this file is not supported yet
45460
0
16
1209
9
- Removedtape@^4.6.3
- Removed@ljharb/resumer@0.0.1(transitive)
- Removed@ljharb/through@2.3.14(transitive)
- Removedarray-buffer-byte-length@1.0.2(transitive)
- Removedarraybuffer.prototype.slice@1.0.4(transitive)
- Removedasync-function@1.0.0(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcall-bind@1.0.8(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddata-view-buffer@1.0.2(transitive)
- Removeddata-view-byte-length@1.0.2(transitive)
- Removeddata-view-byte-offset@1.0.1(transitive)
- Removeddeep-equal@1.1.2(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddefined@1.0.1(transitive)
- Removeddotignore@0.1.2(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-abstract@1.23.9(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedes-set-tostringtag@2.1.0(transitive)
- Removedes-to-primitive@1.3.0(transitive)
- Removedfor-each@0.3.5(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunction.prototype.name@1.1.8(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedget-symbol-description@1.1.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas@1.0.4(transitive)
- Removedhas-bigints@1.1.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinternal-slot@1.1.0(transitive)
- Removedis-arguments@1.2.0(transitive)
- Removedis-array-buffer@3.0.5(transitive)
- Removedis-async-function@2.1.1(transitive)
- Removedis-bigint@1.1.0(transitive)
- Removedis-boolean-object@1.2.2(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-core-module@2.16.1(transitive)
- Removedis-data-view@1.0.2(transitive)
- Removedis-date-object@1.1.0(transitive)
- Removedis-finalizationregistry@1.1.1(transitive)
- Removedis-generator-function@1.1.0(transitive)
- Removedis-map@2.0.3(transitive)
- Removedis-number-object@1.1.1(transitive)
- Removedis-regex@1.1.41.2.1(transitive)
- Removedis-set@2.0.3(transitive)
- Removedis-shared-array-buffer@1.0.4(transitive)
- Removedis-string@1.1.1(transitive)
- Removedis-symbol@1.1.1(transitive)
- Removedis-typed-array@1.1.15(transitive)
- Removedis-weakmap@2.0.2(transitive)
- Removedis-weakref@1.1.1(transitive)
- Removedis-weakset@2.0.4(transitive)
- Removedisarray@2.0.5(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmock-property@1.0.3(transitive)
- Removedobject-inspect@1.12.31.13.4(transitive)
- Removedobject-is@1.1.6(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.7(transitive)
- Removedonce@1.4.0(transitive)
- Removedown-keys@1.0.1(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpossible-typed-array-names@1.1.0(transitive)
- Removedreflect.getprototypeof@1.0.10(transitive)
- Removedregexp.prototype.flags@1.5.4(transitive)
- Removedresolve@1.22.10(transitive)
- Removedsafe-array-concat@1.1.3(transitive)
- Removedsafe-push-apply@1.0.0(transitive)
- Removedsafe-regex-test@1.1.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedset-proto@1.0.0(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedstring.prototype.trim@1.2.10(transitive)
- Removedstring.prototype.trimend@1.0.9(transitive)
- Removedstring.prototype.trimstart@1.0.8(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtape@4.17.0(transitive)
- Removedtyped-array-buffer@1.0.3(transitive)
- Removedtyped-array-byte-length@1.0.3(transitive)
- Removedtyped-array-byte-offset@1.0.4(transitive)
- Removedtyped-array-length@1.0.7(transitive)
- Removedunbox-primitive@1.1.0(transitive)
- Removedwhich-boxed-primitive@1.1.1(transitive)
- Removedwhich-builtin-type@1.2.1(transitive)
- Removedwhich-collection@1.0.2(transitive)
- Removedwhich-typed-array@1.1.18(transitive)
- Removedwrappy@1.0.2(transitive)