natural 0.1.27 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/.editorconfig +7 -0
  2. package/LICENSE.txt +0 -0
  3. package/Makefile +0 -0
  4. package/README.md +237 -24
  5. package/benchmarks/index.js +1 -1
  6. package/benchmarks/metaphone.js +0 -0
  7. package/benchmarks/soundex.js +0 -0
  8. package/examples/classification/basic.js +0 -0
  9. package/examples/classification/recall.js +0 -0
  10. package/examples/classification/store.js +0 -0
  11. package/examples/inflection/count.js +0 -0
  12. package/examples/inflection/noun.js +0 -0
  13. package/examples/inflection/noun_attach.js +0 -0
  14. package/examples/phonetics/compare.js +0 -0
  15. package/examples/phonetics/sounds_like.js +0 -0
  16. package/examples/phonetics/tokenize_and_phoneticize.js +0 -0
  17. package/examples/stemming/stem_corpus.js +0 -0
  18. package/examples/stemming/stem_word.js +0 -0
  19. package/examples/tfidf/array_example.js +0 -0
  20. package/examples/tfidf/multiple_terms.js +0 -0
  21. package/examples/tfidf/tfidf_example.js +0 -0
  22. package/index.js +0 -0
  23. package/io_spec/test_data/tfidf/one +0 -0
  24. package/io_spec/test_data/tfidf/two +0 -0
  25. package/io_spec/tfidf_spec.js +0 -0
  26. package/io_spec/wordnet_spec.js +0 -0
  27. package/lib/natural/analyzers/sentence_analyzer.js +16 -13
  28. package/lib/natural/classifiers/bayes_classifier.js +6 -2
  29. package/lib/natural/classifiers/classifier.js +0 -0
  30. package/lib/natural/classifiers/logistic_regression_classifier.js +0 -0
  31. package/lib/natural/distance/dice_coefficient.js +0 -0
  32. package/lib/natural/distance/jaro-winkler_distance.js +13 -8
  33. package/lib/natural/distance/levenshtein_distance.js +0 -0
  34. package/lib/natural/index.js +8 -0
  35. package/lib/natural/inflectors/count_inflector.js +0 -0
  36. package/lib/natural/inflectors/form_set.js +0 -0
  37. package/lib/natural/inflectors/fr/count_inflector.js +0 -0
  38. package/lib/natural/inflectors/fr/noun_inflector.js +0 -0
  39. package/lib/natural/inflectors/ja/noun_inflector.js +0 -0
  40. package/lib/natural/inflectors/noun_inflector.js +0 -0
  41. package/lib/natural/inflectors/present_verb_inflector.js +1 -0
  42. package/lib/natural/inflectors/singular_plural_inflector.js +1 -2
  43. package/lib/natural/ngrams/ngrams.js +45 -8
  44. package/lib/natural/ngrams/ngrams_zh.js +83 -0
  45. package/lib/natural/normalizers/normalizer.js +30 -38
  46. package/lib/natural/normalizers/normalizer_ja.js +26 -8
  47. package/lib/natural/normalizers/normalizer_no.js +59 -0
  48. package/lib/natural/phonetics/double_metaphone.js +9 -4
  49. package/lib/natural/phonetics/metaphone.js +6 -1
  50. package/lib/natural/phonetics/phonetic.js +0 -0
  51. package/lib/natural/phonetics/soundex.js +11 -7
  52. package/lib/natural/spellcheck/spellcheck.js +80 -0
  53. package/lib/natural/stemmers/lancaster_rules.js +4 -4
  54. package/lib/natural/stemmers/lancaster_stemmer.js +0 -0
  55. package/lib/natural/stemmers/porter_stemmer.js +90 -63
  56. package/lib/natural/stemmers/porter_stemmer_es.js +22 -23
  57. package/lib/natural/stemmers/porter_stemmer_fr.js +377 -0
  58. package/lib/natural/stemmers/porter_stemmer_no.js +155 -0
  59. package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
  60. package/lib/natural/stemmers/stemmer.js +0 -0
  61. package/lib/natural/stemmers/stemmer_fr.js +58 -0
  62. package/lib/natural/stemmers/stemmer_no.js +61 -0
  63. package/lib/natural/stemmers/stemmer_pt.js +65 -0
  64. package/lib/natural/stemmers/token.js +163 -0
  65. package/lib/natural/tfidf/tfidf.js +50 -19
  66. package/lib/natural/tokenizers/aggressive_tokenizer.js +0 -0
  67. package/lib/natural/tokenizers/aggressive_tokenizer_es.js +0 -0
  68. package/lib/natural/tokenizers/aggressive_tokenizer_fr.js +36 -0
  69. package/lib/natural/tokenizers/aggressive_tokenizer_nl.js +0 -0
  70. package/lib/natural/tokenizers/aggressive_tokenizer_no.js +39 -0
  71. package/lib/natural/tokenizers/aggressive_tokenizer_pt.js +0 -0
  72. package/lib/natural/tokenizers/regexp_tokenizer.js +0 -0
  73. package/lib/natural/tokenizers/tokenizer.js +2 -2
  74. package/lib/natural/tokenizers/treebank_word_tokenizer.js +0 -0
  75. package/lib/natural/trie/trie.js +47 -0
  76. package/lib/natural/util/bag.js +50 -0
  77. package/lib/natural/util/edge_weighted_digraph.js +112 -0
  78. package/lib/natural/util/longest_path_tree.js +99 -0
  79. package/lib/natural/util/shortest_path_tree.js +100 -0
  80. package/lib/natural/util/stopwords.js +0 -0
  81. package/lib/natural/util/stopwords_fr.js +194 -0
  82. package/lib/natural/util/stopwords_nl.js +43 -0
  83. package/lib/natural/util/stopwords_no.js +42 -0
  84. package/lib/natural/util/stopwords_pt.js +136 -0
  85. package/lib/natural/util/topological.js +98 -0
  86. package/lib/natural/wordnet/data_file.js +0 -0
  87. package/lib/natural/wordnet/index_file.js +0 -0
  88. package/lib/natural/wordnet/wordnet.js +0 -0
  89. package/lib/natural/wordnet/wordnet_file.js +0 -0
  90. package/package.json +2 -2
  91. package/spec/aggressive_tokenizer_fr_spec.js +101 -0
  92. package/spec/aggressive_tokenizer_pt_spec.js +0 -0
  93. package/spec/aggressive_tokenizer_spec.js +0 -0
  94. package/spec/bayes_classifier_spec.js +12 -0
  95. package/spec/classifier_spec.js +84 -0
  96. package/spec/count_inflector_fr_spec.js +0 -0
  97. package/spec/count_inflector_spec.js +0 -0
  98. package/spec/dice_coefficient_spec.js +0 -0
  99. package/spec/double_metaphone_spec.js +10 -1
  100. package/spec/jaro-winkler_spec.js +0 -0
  101. package/spec/lancaster_stemmer_spec.js +10 -1
  102. package/spec/levenshtein_spec.js +0 -0
  103. package/spec/logistic_regression_classifier_spec.js +0 -0
  104. package/spec/longest_path_tree_spec.js +102 -0
  105. package/spec/metaphone_spec.js +10 -0
  106. package/spec/ngram_spec.js +61 -0
  107. package/spec/ngram_zh_spec.js +122 -0
  108. package/spec/normalizer_ja_spec.js +9 -3
  109. package/spec/normalizer_no_spec.js +111 -0
  110. package/spec/normalizer_spec.js +26 -5
  111. package/spec/noun_inflector_fr_spec.js +0 -0
  112. package/spec/noun_inflector_ja_spec.js +0 -0
  113. package/spec/noun_inflector_spec.js +0 -0
  114. package/spec/porter_stemmer_fr_spec.js +101 -0
  115. package/spec/porter_stemmer_no_spec.js +143 -0
  116. package/spec/porter_stemmer_pt_spec.js +50 -0
  117. package/spec/porter_stemmer_spec.js +49 -0
  118. package/spec/present_verb_inflector_spec.js +3 -0
  119. package/spec/remove_diacritics_spec.js +31 -0
  120. package/spec/sentence_analyzer_spec.js +248 -0
  121. package/spec/shortest_path_tree_spec.js +132 -0
  122. package/spec/soundex_spec.js +13 -9
  123. package/spec/spellcheck_spec.js +92 -0
  124. package/spec/stemmer_token_spec.js +161 -0
  125. package/spec/test_data/snowball_fr.txt +20402 -0
  126. package/spec/test_data/snowball_no.txt +20628 -0
  127. package/spec/test_data/snowball_pt.txt +32016 -0
  128. package/spec/test_data/tfdif_testcorpus.txt +0 -0
  129. package/spec/test_data/tfidf_teststopwords.txt +0 -0
  130. package/spec/test_data/wordnet_mini.sql +0 -0
  131. package/spec/tfidf_spec.js +153 -28
  132. package/spec/tokenizer_ja_spec.js +0 -0
  133. package/spec/treebank_word_tokenizer_spec.js +0 -0
  134. package/spec/trie_spec.js +27 -3
File without changes
File without changes
File without changes
@@ -22,7 +22,7 @@ THE SOFTWARE.
22
22
 
23
23
  var TfIdf = require('../lib/natural/tfidf/tfidf');
24
24
  var tfidf;
25
-
25
+
26
26
  describe('tfidf', function() {
27
27
  describe('stateless operations', function() {
28
28
  it('should tf', function() {
@@ -36,15 +36,55 @@ describe('tfidf', function() {
36
36
  it('should store and recall keys', function() {
37
37
  tfidf = new TfIdf();
38
38
  tfidf.addDocument('document one', 'un');
39
- tfidf.addDocument('document Two', 'deux');
40
-
39
+ tfidf.addDocument('document Two', 'deux');
40
+
41
+ tfidf.tfidfs('two', function(i, tfidf, key) {
42
+ if(i === 0)
43
+ expect(key).toBe('un');
44
+ else
45
+ expect(key).toBe('deux');
46
+ });
47
+ });
48
+
49
+ it('should handle a deserialized object passed to the constructor', function () {
50
+ tfidf = new TfIdf({
51
+ documents: [
52
+ {__key: 'un', document: 1, one: 1},
53
+ {__key: 'deux', document: 1, two: 1}
54
+ ]
55
+ });
56
+ tfidf.tfidfs('two', function(i, tfidf, key) {
57
+ if(i === 0)
58
+ expect(key).toBe('un');
59
+ else
60
+ expect(key).toBe('deux');
61
+ });
62
+ });
63
+
64
+ it('should work when called without a callback', function () {
65
+ tfidf = new TfIdf({
66
+ documents: [
67
+ {__key: 'un', document: 1, one: 1},
68
+ {__key: 'deux', document: 1, two: 1}
69
+ ]
70
+ });
71
+ tfidfs = tfidf.tfidfs('two');
72
+ expect(tfidfs[1]).toBe(1 + Math.log( 2.0 / 2.0 ));
73
+ });
74
+
75
+ it('should work with the restoreCache flag set to true', function() {
76
+ tfidf = new TfIdf();
77
+ tfidf.addDocument('document one', 'un');
78
+ expect(tfidf.idf("one")).toBe(1 + Math.log( 1.0 / 2.0 ));
79
+ tfidf.addDocument('document Two', 'deux', true);
80
+
41
81
  tfidf.tfidfs('two', function(i, tfidf, key) {
42
- if(i == 0)
82
+ if(i === 0)
43
83
  expect(key).toBe('un');
44
84
  else
45
85
  expect(key).toBe('deux');
46
86
  });
47
- });
87
+ });
48
88
  });
49
89
 
50
90
  describe('stateful operations', function() {
@@ -54,15 +94,15 @@ describe('tfidf', function() {
54
94
  tfidf.addDocument('document Two');
55
95
  });
56
96
 
57
- it('should list important terms', function() {
97
+ it('should list important terms', function() {
58
98
  var terms = tfidf.listTerms(0);
59
99
  expect(terms[0].tfidf).toBeGreaterThan(terms[1].tfidf);
60
- });
100
+ });
61
101
  });
62
102
 
63
103
  describe("special cases", function(){
64
104
 
65
- // In response to
105
+ // In response to
66
106
  it("should handle reserved function names correctly in documents", function(){
67
107
  var reservedWords = [
68
108
  'toString',
@@ -75,11 +115,18 @@ describe('tfidf', function() {
75
115
  ];
76
116
  tfidf = new TfIdf();
77
117
  tfidf.addDocument(reservedWords.join(" "));
78
-
118
+
79
119
  for(var i in reservedWords) {
80
- expect(tfidf.tfidf(reservedWords[i], 0)).toBe(0);
120
+ expect(tfidf.tfidf(reservedWords[i], 0)).toBe(1*(1+Math.log(1/2)));
81
121
  }
82
122
  });
123
+
124
+ it('should handle an array passed to tfidf()', function() {
125
+ tfidf = new TfIdf();
126
+ var terms = ['this', 'document', 'is', 'about', 'poetry'];
127
+ tfidf.addDocument(terms.join(" "));
128
+ expect(tfidf.tfidf(terms, 0)).toBe( 2 * (1 + Math.log( 1.0 / 2.0 )) );
129
+ });
83
130
  });
84
131
 
85
132
  describe("correct calculations", function(){
@@ -92,7 +139,20 @@ describe('tfidf', function() {
92
139
  tfidf.addDocument('this document is about ruby and node.');
93
140
  tfidf.addDocument('this document is about node. it has node examples');
94
141
 
95
- expect(tfidf.idf("node")).toBe(Math.log( 4.0 / 3.0 ));
142
+ expect(tfidf.idf("node")).toBe(1 + Math.log( 4.0 / 4.0 ));
143
+ });
144
+
145
+ it("should compute idf correctly with non-string documents", function(){
146
+
147
+ tfidf = new TfIdf();
148
+ tfidf.addDocument('this document is about node.');
149
+ tfidf.addDocument('this document is about ruby.');
150
+ tfidf.addDocument('this document is about ruby and node.');
151
+ tfidf.addDocument('this document is about node. it has node examples');
152
+ tfidf.addDocument({text: 'this document is about python'});
153
+ tfidf.addDocument(['this', 'document', 'is', 'about', 'node', 'and', 'JavaScript']);
154
+
155
+ expect(tfidf.idf("node")).toBe(1 + Math.log( 6.0 / 5.0 ));
96
156
  });
97
157
 
98
158
  it("should compute tf correctly", function(){
@@ -106,10 +166,10 @@ describe('tfidf', function() {
106
166
  it("should compute tf-idf correctly", function(){
107
167
 
108
168
  var correctCalculations = [
109
- 1 * Math.log( 4.0 / 3.0 ),
169
+ 1 * (1 + Math.log( 4.0 / 4.0 )),
110
170
  0,
111
- 2 * Math.log( 4.0 / 3.0 ),
112
- 1 * Math.log( 4.0 / 2.0 )
171
+ 2 * (1 + Math.log( 4.0 / 4.0 )),
172
+ 1 * (1 + Math.log( 4.0 / 3.0 ))
113
173
  ];
114
174
 
115
175
  tfidf = new TfIdf();
@@ -119,15 +179,22 @@ describe('tfidf', function() {
119
179
  tfidf.addDocument('this document is about node. it has node examples', {node:2, ruby:1});
120
180
 
121
181
  tfidf.tfidfs('node', function(i, measure, k) {
122
- expect(measure).toBe(correctCalculations[k.node])
182
+ expect(measure).toBe(correctCalculations[k.node]);
123
183
  });
124
184
 
125
185
  tfidf.tfidfs('ruby', function(i, measure, k) {
126
- expect(measure).toBe(correctCalculations[k.ruby])
186
+ expect(measure).toBe(correctCalculations[k.ruby]);
127
187
  });
128
188
 
129
189
  });
130
190
 
191
+ it("should not return NaN if a term is not present in any documents", function() {
192
+ tfidf = new TfIdf();
193
+ tfidf.addDocument('this document is about node.');
194
+
195
+ expect(tfidf.tfidf('ruby', 0)).toBe(0);
196
+ });
197
+
131
198
  // This test assures that tf-idf is computed correctly before and after a document is added
132
199
  // Computes and tests a few tf-idfs, then adds a document and ensures that those terms tf-idf value
133
200
  // is updated accordingly.
@@ -140,14 +207,14 @@ describe('tfidf', function() {
140
207
  tfidf.addDocument('this document is about ruby.', 1);
141
208
 
142
209
  // check the tf-idf for 'node'
143
- expect( tfidf.tfidf("node", 0) ).toBe( 1 * Math.log( 2.0 / 1.0 ) );
210
+ expect( tfidf.tfidf("node", 0) ).toBe( 1 * ( 1 + Math.log( 2.0 / 2.0 ) ));
144
211
 
145
212
  // Add 2 more documents
146
213
  tfidf.addDocument('this document is about ruby and node.');
147
214
  tfidf.addDocument('this document is about node. it has node examples');
148
215
 
149
216
  // Ensure that the tf-idf in the same document has changed to reflect the new idf.
150
- expect( tfidf.tfidf("node", 0) ).toBe( 1 * Math.log( 4.0 / 3.0 ) );
217
+ expect( tfidf.tfidf("node", 0) ).toBe( 1 * ( 1 + Math.log( 4.0 / 4.0 ) ));
151
218
  });
152
219
 
153
220
  // Test tf-idf computation on files loaded using readFileSync
@@ -161,38 +228,96 @@ describe('tfidf', function() {
161
228
  tfidf.addFileSync("spec/test_data/tfidf_document4.txt", null, {node:2, ruby:1});
162
229
 
163
230
  var correctCalculations = [
164
- 1 * Math.log( 4.0 / 3.0 ),
231
+ 1 * (1 + Math.log( 4.0 / 4.0 )),
165
232
  0,
166
- 2 * Math.log( 4.0 / 3.0 ),
167
- 1 * Math.log( 4.0 / 2.0 )
233
+ 2 * (1 + Math.log( 4.0 / 4.0 )),
234
+ 1 * (1 + Math.log( 4.0 / 3.0 ))
168
235
  ];
169
236
 
170
237
  tfidf.tfidfs('node', function(i, measure, k) {
171
- expect(measure).toBe(correctCalculations[k.node])
238
+ expect(measure).toBe(correctCalculations[k.node]);
172
239
  });
173
240
 
174
241
  tfidf.tfidfs('ruby', function(i, measure, k) {
175
- expect(measure).toBe(correctCalculations[k.ruby])
242
+ expect(measure).toBe(correctCalculations[k.ruby]);
176
243
  });
244
+
245
+ // addFileSync with restoreCache flag set to true.
246
+ tfidf.addFileSync("spec/test_data/tfidf_document4.txt", null, {node:2, ruby:1}, true);
177
247
  });
178
248
 
179
249
  // Test idf caching when adding documents from addFileSync
180
- if("should update a terms tf-idf score after adding documents from addFileSync", function(){
250
+ it("should update a terms tf-idf score after adding documents from addFileSync", function(){
181
251
  tfidf = new TfIdf();
182
252
 
183
253
  // Add 2 documents
184
- tfidf.addFileSync("spec/test_data/tfidf_document1.txt", 0);
185
- tfidf.addFileSync("spec/test_data/tfidf_document2.txt", 1);
254
+ tfidf.addFileSync("spec/test_data/tfidf_document1.txt", null, 0);
255
+ tfidf.addFileSync("spec/test_data/tfidf_document2.txt", null, 1);
186
256
 
187
257
  // check the tf-idf for 'node'
188
- expect( tfidf.tfidf("node", 0) ).toBe( 1 * Math.log( 2.0 / 1.0 ) );
258
+ expect( tfidf.tfidf("node", 0) ).toBe( 1 * (1 + Math.log( 2.0 / 2.0 ) ));
189
259
 
190
260
  // Add 2 more documents
191
261
  tfidf.addFileSync("spec/test_data/tfidf_document3.txt");
192
262
  tfidf.addFileSync("spec/test_data/tfidf_document4.txt");
193
263
 
194
264
  // Ensure that the tf-idf in the same document has changed to reflect the new idf.
195
- expect( tfidf.tfidf("node", 0) ).toBe( 1 * Math.log( 4.0 / 3.0 ) );
265
+ expect( tfidf.tfidf("node", 0) ).toBe( 1 * (1 + Math.log( 4.0 / 4.0 ) ));
266
+ });
267
+
268
+ // Test idf.setTokenizer
269
+ it('should allow for specific types of Tokenizers', function(){
270
+ tfidf = new TfIdf();
271
+
272
+ tfidf.addDocument('this document isn\'t about node.', 0);
273
+ tfidf.addDocument('that doc is about node.', 1);
274
+ expect( tfidf.tfidf('n\'t', 0) ).toBe(0);
275
+ expect( tfidf.tfidf('isn', 0) ).toBe( 1 * (1 + Math.log( 2 / 2 ) ));
276
+
277
+ tfidf = new TfIdf();
278
+
279
+ tfidf.addDocument('this document isn\'t about node.', 0);
280
+ tfidf.addDocument('this document isn\'t about node.', 1);
281
+
282
+ expect( tfidf.tfidf('isn', 0) ).toBe(1 * (1 + Math.log (2/3)));
283
+
284
+ tfidf = new TfIdf();
285
+ var TreebankWordTokenizer = require('../lib/natural/tokenizers/treebank_word_tokenizer');
286
+ var tokenizer = new TreebankWordTokenizer();
287
+
288
+ tfidf.addDocument('this document isn\'t about node.', 0);
289
+ tfidf.setTokenizer(tokenizer);
290
+ tfidf.addDocument('this doc isn\'t about node.', 1);
291
+
292
+ expect( tfidf.tfidf('isn', 0) ).toBe( 1 * ( 1 + Math.log( 2 / 2 ) ));
293
+ expect( tfidf.tfidf('n\'t', 1) ).toBe( 1 * ( 1 + Math.log( 2 / 2 ) ));
294
+ expect( tfidf.tfidf('isn', 1) ).toBe(0);
295
+ });
296
+
297
+ it('should require a valid tokenizer when using setTokenizer', function(){
298
+ tfidf = new TfIdf();
299
+
300
+ expect( function() { tfidf.setTokenizer(1); } ).toThrow(new Error('Expected a valid Tokenizer'));
301
+ expect( function() { tfidf.setTokenizer({}); } ).toThrow(new Error('Expected a valid Tokenizer'));
302
+ });
303
+
304
+ // Test encoding for addFileSync
305
+ it('should use the specified encoding for addFileSync', function(){
306
+
307
+ tfidf = new TfIdf();
308
+
309
+ tfidf.addFileSync('spec/test_data/tfidf_document1.txt', 'base64');
310
+ tfidf.addFileSync('spec/test_data/tfidf_document1.txt', 'utf8');
311
+
312
+ expect( tfidf.tfidf('dghpcybkb2n1bwvudcbpcybhym91dcbub2rllg', 0) ).toBe( 1 * ( 1 + Math.log( 2.0 / 2.0 ) ));
313
+ });
314
+
315
+ // Test encoding check for addFileSync
316
+ it('should require a valid encoding for addFileSync', function(){
317
+
318
+ tfidf = new TfIdf();
319
+
320
+ expect( function() { tfidf.addFileSync('spec/test_data/tfidf_document1.txt', 'foobar'); } ).toThrow(new Error('Invalid encoding: foobar'));
196
321
  });
197
322
  });
198
323
  });
File without changes
File without changes
package/spec/trie_spec.js CHANGED
@@ -123,7 +123,24 @@ describe('trie', function() {
123
123
  expect(results).not.toContain("cd");
124
124
  });
125
125
 
126
- it("should be able to execute the find_prefix search with a match", function(){
126
+ it("should be able to guess all full prefix matched words.", function(){
127
+ var trie = new Trie();
128
+ trie.addStrings(["a","ab","bc","cd","abc"]);
129
+ var results = trie.keysWithPrefix("a");
130
+ expect(results).toContain("a");
131
+ expect(results).toContain("ab");
132
+ expect(results).toContain("abc");
133
+ expect(results).not.toContain("bc");
134
+ expect(results).not.toContain("cd");
135
+ results = trie.keysWithPrefix("ab");
136
+ expect(results).toContain("ab");
137
+ expect(results).toContain("abc");
138
+ expect(results).not.toContain("a");
139
+ expect(results).not.toContain("bc");
140
+ expect(results).not.toContain("cd");
141
+ });
142
+
143
+ it("should be able to execute the find_prefix search with a match", function(){
127
144
  var trie = new Trie();
128
145
  trie.addStrings(["their", "and", "they"]);
129
146
  var results = trie.findPrefix("theyre");
@@ -131,7 +148,14 @@ describe('trie', function() {
131
148
  expect(results[1]).toBe("re");
132
149
  });
133
150
 
134
- it("should be able to execute the find_prefix search without a match", function(){
151
+ it("should return empty array if no full prefix matches found.", function(){
152
+ var trie = new Trie();
153
+ trie.addStrings(["a","ab","bc","cd","abc"]);
154
+ var results = trie.keysWithPrefix("not-found");
155
+ expect(results.length).toEqual(0);
156
+ });
157
+
158
+ it("should be able to execute the find_prefix search without a match", function(){
135
159
  var trie = new Trie();
136
160
  trie.addStrings(["their", "and"]);
137
161
  var results = trie.findPrefix("theyre");
@@ -179,4 +203,4 @@ describe('trie', function() {
179
203
  expect(results[1]).toBe("re");
180
204
  });
181
205
  });
182
- });
206
+ });