natural 0.2.1 → 0.4.0

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 (106) hide show
  1. package/.npmignore +4 -11
  2. package/README.md +156 -41
  3. package/bayes_classifier.json +1 -0
  4. package/lib/natural/brill_pos_tagger/data/Dutch/README.txt +2 -0
  5. package/lib/natural/brill_pos_tagger/data/Dutch/brill_CONTEXTRULES.jg +285 -0
  6. package/lib/natural/brill_pos_tagger/data/Dutch/brill_LEXICON.jg +11699 -0
  7. package/lib/natural/brill_pos_tagger/data/English/README.txt +8 -0
  8. package/lib/natural/brill_pos_tagger/data/English/lexicon_from_posjs.json +297827 -0
  9. package/lib/natural/brill_pos_tagger/data/English/tr_from_brill_paper.txt +10 -0
  10. package/lib/natural/brill_pos_tagger/data/English/tr_from_posjs.txt +18 -0
  11. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +136 -0
  12. package/lib/natural/brill_pos_tagger/lib/Predicate.js +410 -0
  13. package/lib/natural/brill_pos_tagger/lib/TF_Parser.js +717 -0
  14. package/lib/natural/brill_pos_tagger/lib/TF_Parser.pegjs +55 -0
  15. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +49 -0
  16. package/lib/natural/classifiers/bayes_classifier.js +6 -5
  17. package/lib/natural/classifiers/classifier.js +3 -2
  18. package/lib/natural/classifiers/logistic_regression_classifier.js +9 -5
  19. package/lib/natural/distance/dice_coefficient.js +22 -12
  20. package/lib/natural/index.js +6 -0
  21. package/lib/natural/ngrams/ngrams.js +4 -0
  22. package/lib/natural/stemmers/stemmer.js +31 -6
  23. package/lib/natural/tokenizers/regexp_tokenizer.js +3 -3
  24. package/{examples/inflection/noun.js → lib/natural/tokenizers/sentence_tokenizer.js} +14 -10
  25. package/lib/natural/tokenizers/tokenizer_case.js +58 -0
  26. package/lib/natural/util/bag.js +1 -0
  27. package/lib/natural/wordnet/wordnet.js +2 -2
  28. package/lib/natural/wordnet/wordnet_file.js +1 -1
  29. package/lr_classifier.json +1 -0
  30. package/package.json +6 -3
  31. package/package.json~ +66 -0
  32. package/benchmarks/index.js +0 -32
  33. package/benchmarks/metaphone.js +0 -27
  34. package/benchmarks/soundex.js +0 -27
  35. package/examples/classification/basic.js +0 -35
  36. package/examples/classification/recall.js +0 -28
  37. package/examples/classification/store.js +0 -37
  38. package/examples/inflection/count.js +0 -35
  39. package/examples/inflection/noun_attach.js +0 -33
  40. package/examples/phonetics/compare.js +0 -39
  41. package/examples/phonetics/sounds_like.js +0 -40
  42. package/examples/phonetics/tokenize_and_phoneticize.js +0 -54
  43. package/examples/stemming/stem_corpus.js +0 -29
  44. package/examples/stemming/stem_word.js +0 -26
  45. package/examples/tfidf/array_example.js +0 -34
  46. package/examples/tfidf/multiple_terms.js +0 -33
  47. package/examples/tfidf/tfidf_example.js +0 -44
  48. package/io_spec/test_data/tfidf/one +0 -1
  49. package/io_spec/test_data/tfidf/two +0 -1
  50. package/io_spec/tfidf_spec.js +0 -50
  51. package/io_spec/wordnet_spec.js +0 -81
  52. package/spec/aggressive_tokenizer_es_spec.js +0 -36
  53. package/spec/aggressive_tokenizer_fr_spec.js +0 -101
  54. package/spec/aggressive_tokenizer_nl_spec.js +0 -36
  55. package/spec/aggressive_tokenizer_pt_spec.js +0 -56
  56. package/spec/aggressive_tokenizer_spec.js +0 -56
  57. package/spec/bayes_classifier_spec.js +0 -173
  58. package/spec/classifier_spec.js +0 -175
  59. package/spec/count_inflector_fr_spec.js +0 -44
  60. package/spec/count_inflector_spec.js +0 -73
  61. package/spec/dice_coefficient_spec.js +0 -26
  62. package/spec/double_metaphone_spec.js +0 -752
  63. package/spec/jaro-winkler_spec.js +0 -53
  64. package/spec/lancaster_stemmer_spec.js +0 -73
  65. package/spec/levenshtein_spec.js +0 -66
  66. package/spec/logistic_regression_classifier_spec.js +0 -122
  67. package/spec/longest_path_tree_spec.js +0 -102
  68. package/spec/metaphone_spec.js +0 -252
  69. package/spec/ngram_spec.js +0 -130
  70. package/spec/ngram_zh_spec.js +0 -122
  71. package/spec/normalizer_ja_spec.js +0 -160
  72. package/spec/normalizer_no_spec.js +0 -111
  73. package/spec/normalizer_spec.js +0 -140
  74. package/spec/noun_inflector_fr_spec.js +0 -476
  75. package/spec/noun_inflector_ja_spec.js +0 -112
  76. package/spec/noun_inflector_spec.js +0 -270
  77. package/spec/porter_stemmer_fr_spec.js +0 -101
  78. package/spec/porter_stemmer_it_spec.js +0 -44
  79. package/spec/porter_stemmer_no_spec.js +0 -143
  80. package/spec/porter_stemmer_pt_spec.js +0 -50
  81. package/spec/porter_stemmer_ru_spec.js +0 -63
  82. package/spec/porter_stemmer_spec.js +0 -182
  83. package/spec/present_verb_inflector_spec.js +0 -128
  84. package/spec/remove_diacritics_spec.js +0 -31
  85. package/spec/sentence_analyzer_spec.js +0 -277
  86. package/spec/shortest_path_tree_spec.js +0 -132
  87. package/spec/soundex_spec.js +0 -158
  88. package/spec/spellcheck_spec.js +0 -92
  89. package/spec/stemmer_ja_spec.js +0 -66
  90. package/spec/stemmer_token_spec.js +0 -161
  91. package/spec/test_data/snowball_fr.txt +0 -20402
  92. package/spec/test_data/snowball_it.txt +0 -35482
  93. package/spec/test_data/snowball_no.txt +0 -20628
  94. package/spec/test_data/snowball_pt.txt +0 -32016
  95. package/spec/test_data/tfdif_testcorpus.txt +0 -7
  96. package/spec/test_data/tfidf_document1.txt +0 -1
  97. package/spec/test_data/tfidf_document2.txt +0 -1
  98. package/spec/test_data/tfidf_document3.txt +0 -1
  99. package/spec/test_data/tfidf_document4.txt +0 -1
  100. package/spec/test_data/tfidf_teststopwords.txt +0 -1
  101. package/spec/test_data/wordnet_mini.sql +0 -95
  102. package/spec/tfidf_spec.js +0 -323
  103. package/spec/tokenizer_ja_spec.js +0 -58
  104. package/spec/transliterator_ja_spec.js +0 -103
  105. package/spec/treebank_word_tokenizer_spec.js +0 -36
  106. package/spec/trie_spec.js +0 -206
@@ -1,277 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Rob Ellis, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var SentenceAnalyzer = require('../lib/natural/analyzers/sentence_analyzer');
24
-
25
- describe('sentence analyzer', function() {
26
- it('should load', function() {
27
- var analyzer = new SentenceAnalyzer(null, function() { });
28
- });
29
-
30
- it('should determine PP and SP, given a POS', function () {
31
- var sentenceTags = [
32
- {token: 'The', pos: 'DT'},
33
- {token: 'angry', pos: 'JJ'},
34
- {token: 'bear', pos: 'NN'},
35
- {token: 'chased', pos: 'VB'},
36
- {token: 'the', pos: 'DT'},
37
- {token: 'frightened', pos: 'JJ'},
38
- {token: 'little', pos: 'JJ'},
39
- {token: 'squirrel', pos: 'NN'}
40
- ];
41
- new SentenceAnalyzer({tags: sentenceTags}, function (analyzer) {
42
- analyzer.part(function (part) {
43
- var posTags = part.posObj.tags;
44
- for (var tagNum = 0; tagNum < posTags.length; tagNum++) {
45
- var posTag = posTags[tagNum];
46
- if (posTag.token === 'angry') {
47
- expect(posTag.spos).toEqual('SP');
48
- } else if (posTag.token === 'squirrel') {
49
- expect(posTag.spos).toEqual('PP');
50
- }
51
- }
52
- expect(analyzer.subjectToString().trim()).toEqual('The angry bear');
53
- expect(analyzer.predicateToString().trim()).toEqual('chased the frightened little squirrel');
54
- expect(analyzer.toString().trim()).toEqual('The angry bear chased the frightened little squirrel');
55
- expect(analyzer.implicitYou()).toEqual(false);
56
- });
57
- });
58
- });
59
-
60
- it('should determine PP and SP given a POS that begins with a verb', function () {
61
- var sentenceTags = [
62
- {token: 'Vote', pos: 'VB'},
63
- {token: 'for', pos: 'IN'},
64
- {token: 'me', pos: 'PRP'}
65
- ];
66
- new SentenceAnalyzer({tags: sentenceTags}, function (analyzer) {
67
- analyzer.part(function (part) {
68
- var posTags = part.posObj.tags;
69
- for (var tagNum = 0; tagNum < posTags.length; tagNum++) {
70
- var posTag = posTags[tagNum];
71
- if (posTag.token === 'Vote') {
72
- expect(posTag.spos).toEqual('PP');
73
- } else if (posTag.token === 'me') {
74
- expect(posTag.pp).toEqual(true);
75
- }
76
- }
77
- // Adds implicit you.
78
- var lastTagNum = posTags.length - 1;
79
- expect(posTags[lastTagNum].token).toEqual('You');
80
- expect(posTags[lastTagNum].pos).toEqual('PRP');
81
- expect(posTags[lastTagNum].added).toEqual(true);
82
- expect(analyzer.implicitYou()).toEqual(true);
83
- });
84
- });
85
- });
86
-
87
- it('should look for EX before VB', function () {
88
- var sentenceTags = [
89
- {token: 'There', pos: 'EX'},
90
- {token: 'is', pos: 'VB'},
91
- {token: 'a', pos: 'DT'},
92
- {token: 'house', pos: 'NN'},
93
- {token: 'in', pos: 'IN'},
94
- {token: 'the', pos: 'DT'},
95
- {token: 'valley', pos: 'DT'}
96
- ];
97
- new SentenceAnalyzer({tags: sentenceTags}, function (analyzer) {
98
- analyzer.part(function (part) {
99
- var posTags = part.posObj.tags;
100
- for (var tagNum = 0; tagNum < posTags.length; tagNum++) {
101
- var posTag = posTags[tagNum];
102
- if (posTag.token === 'There') {
103
- expect(posTag.spos).toEqual('SP');
104
- } else if (posTag.token === 'is') {
105
- expect(posTag.spos).toEqual('SP');
106
- }
107
- }
108
- expect(analyzer.subjectToString().trim()).toEqual('There is a house');
109
- expect(analyzer.predicateToString().trim()).toEqual('');
110
- expect(analyzer.toString().trim()).toEqual('There is a house in the valley');
111
- expect(analyzer.implicitYou()).toEqual(false);
112
- });
113
- });
114
- });
115
-
116
- describe('#type', function () {
117
-
118
- it('should determine a command without punctuation', function () {
119
- var sentenceTags = [
120
- {token: 'Vote', pos: 'VB'},
121
- {token: 'for', pos: 'IN'},
122
- {token: 'me', pos: 'PRP'}
123
- ];
124
- var punct = function () {
125
- return [];
126
- };
127
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
128
- analyzer.part(function () {
129
- analyzer.type(function (type) {
130
- expect(analyzer.senType).toEqual('COMMAND');
131
- });
132
- });
133
- });
134
- });
135
-
136
- it('should determine an interrogative beginning with who', function () {
137
- var sentenceTags = [
138
- {token: 'Who', pos: 'WP'},
139
- {token: 'voted', pos: 'VB'}
140
- ];
141
- var punct = function () {
142
- return [];
143
- };
144
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
145
- analyzer.part(function () {
146
- analyzer.type(function (type) {
147
- expect(analyzer.senType).toEqual('INTERROGATIVE');
148
- });
149
- });
150
- });
151
- });
152
-
153
- it('should determine an interrogative ending with a personal pronoun', function () {
154
- var sentenceTags = [
155
- {token: 'Should', pos: 'MD'},
156
- {token: 'we', pos: 'PRP'}
157
- ];
158
- var punct = function () {
159
- return '';
160
- };
161
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
162
- analyzer.part(function () {
163
- analyzer.type(function (type) {
164
- expect(analyzer.senType).toEqual('INTERROGATIVE');
165
- });
166
- });
167
- });
168
- });
169
-
170
- it('should classify other sentences as unknown', function () {
171
- var sentenceTags = [
172
- {token: 'I', pos: 'PRP'},
173
- {token: 'am', pos: 'VB'},
174
- {token: 'unsure', pos: 'JJ'}
175
- ];
176
- var punct = function () {
177
- return '';
178
- };
179
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
180
- analyzer.part(function () {
181
- analyzer.type(function (type) {
182
- expect(analyzer.senType).toEqual('UNKNOWN');
183
- });
184
- });
185
- });
186
- });
187
-
188
- it('should determine an interrogative ending with a question mark', function () {
189
- var sentenceTags = [
190
- {token: 'Do', pos: 'VB'},
191
- {token: 'I', pos: 'PRP'},
192
- {token: 'care', pos: 'VB'}
193
- ];
194
- var punct = function () {
195
- return [{token: '?', pos: '.'}];
196
- };
197
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
198
- analyzer.part(function () {
199
- analyzer.type(function (type) {
200
- expect(analyzer.senType).toEqual('INTERROGATIVE');
201
- });
202
- });
203
- });
204
- });
205
-
206
- it('should determine a command ending in an exclamation point', function () {
207
- var sentenceTags = [
208
- {token: 'Vote', pos: 'VB'},
209
- {token: 'for', pos: 'IN'},
210
- {token: 'me', pos: 'PRP'}
211
- ];
212
- var punct = function () {
213
- return [{token: '!', pos: '.'}];
214
- };
215
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
216
- analyzer.part(function () {
217
- analyzer.type(function (type) {
218
- expect(analyzer.senType).toEqual('COMMAND');
219
- });
220
- });
221
- });
222
- });
223
-
224
- it('should determine an exclamation ending in an exclamation point', function () {
225
- var sentenceTags = [
226
- {token: 'We', pos: 'PRP'},
227
- {token: 'like', pos: 'VB'},
228
- {token: 'sheep', pos: 'NN'}
229
- ];
230
- var punct = function () {
231
- return [{token: '!', pos: '.'}];
232
- };
233
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
234
- analyzer.part(function () {
235
- analyzer.type(function (type) {
236
- expect(analyzer.senType).toEqual('EXCLAMATORY');
237
- });
238
- });
239
- });
240
- });
241
-
242
- it('should determine a command ending with .', function () {
243
- var sentenceTags = [
244
- {token: 'Vote', pos: 'VB'},
245
- {token: 'for', pos: 'IN'},
246
- {token: 'me', pos: 'PRP'}
247
- ];
248
- var punct = function () {
249
- return [{token: '.', pos: '.'}];
250
- };
251
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
252
- analyzer.part(function () {
253
- analyzer.type(function (type) {
254
- expect(analyzer.senType).toEqual('COMMAND');
255
- });
256
- });
257
- });
258
- });
259
-
260
- it('should determine a declaration ending with a .', function () {
261
- var sentenceTags = [
262
- {token: 'We', pos: 'PRP'},
263
- {token: 'like', pos: 'VB'},
264
- {token: 'sheep', pos: 'NN'}
265
- ];
266
- var punct = function () {
267
- return [{token: '.', pos: '.'}];
268
- };
269
- new SentenceAnalyzer({tags: sentenceTags, punct: punct}, function (analyzer) {
270
- analyzer.part(function () {
271
- type = analyzer.type();
272
- expect(type).toEqual('DECLARATIVE');
273
- });
274
- });
275
- });
276
- });
277
- });
@@ -1,132 +0,0 @@
1
- /*
2
- Copyright (c) 2014, Lee Wenzhu
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
- 'use strict';
23
-
24
- var SPT = require('../lib/natural/util/shortest_path_tree'),
25
- Topological = require('../lib/natural/util/topological'),
26
- EdgeWeightedDigraph = require('../lib/natural/util/edge_weighted_digraph');
27
-
28
- describe("shortest path tree", function() {
29
- var digraph = new EdgeWeightedDigraph();
30
- digraph.add(5,4,0.35);
31
- digraph.add(4,7,0.37);
32
- digraph.add(5,7,0.28);
33
- digraph.add(5,1,0.32);
34
- digraph.add(4,0,0.38);
35
- digraph.add(0,2,0.26);
36
- digraph.add(3,7,0.39);
37
- digraph.add(1,3,0.29);
38
- digraph.add(7,2,0.34);
39
- digraph.add(6,2,0.40);
40
- digraph.add(3,6,0.52);
41
- digraph.add(6,0,0.58);
42
- digraph.add(6,4,0.93);
43
- describe("edge weighted digraph normal operations", function() {
44
- it("should get the numbers of vertexs", function() {
45
- expect(digraph.v()).toBe(8);
46
- });
47
- it("should get the numbers of edges", function() {
48
- expect(digraph.e()).toBe(13);
49
- });
50
- it("should print all item in digraph", function() {
51
- expect(digraph.toString()).toBe('0 -> 2, 0.26\n' +
52
- '1 -> 3, 0.29\n' +
53
- '3 -> 7, 0.39\n' +
54
- '3 -> 6, 0.52\n' +
55
- '4 -> 7, 0.37\n' +
56
- '4 -> 0, 0.38\n' +
57
- '5 -> 4, 0.35\n' +
58
- '5 -> 7, 0.28\n' +
59
- '5 -> 1, 0.32\n' +
60
- '6 -> 2, 0.4\n' +
61
- '6 -> 0, 0.58\n' +
62
- '6 -> 4, 0.93\n' +
63
- '7 -> 2, 0.34');
64
- });
65
- });
66
-
67
- describe("topo sort for digraph", function() {
68
- it("should sort all the vertexs", function() {
69
- var topoSort = new Topological(digraph);
70
- expect(topoSort.isDAG()).toBe(true);
71
- expect(topoSort.order()).toEqual([ 5, 1, 3, 6, 4, 7, 0, 2 ]);
72
- });
73
- });
74
-
75
- describe("shortest path tree normal operations", function() {
76
- var lpt = new SPT(digraph, 5);
77
- expect(lpt.hasPathTo(0)).toBe(true);
78
- expect(lpt.hasPathTo(1)).toBe(true);
79
- expect(lpt.hasPathTo(2)).toBe(true);
80
- expect(lpt.hasPathTo(3)).toBe(true);
81
- expect(lpt.hasPathTo(4)).toBe(true);
82
- expect(lpt.hasPathTo(5)).toBe(false);
83
- expect(lpt.hasPathTo(6)).toBe(true);
84
- expect(lpt.hasPathTo(7)).toBe(true);
85
- expect(lpt.pathTo(0)).toEqual([ 5, 4, 0 ]);
86
- expect(lpt.pathTo(1)).toEqual([ 5, 1 ]);
87
- expect(lpt.pathTo(2)).toEqual([ 5, 7, 2 ]);
88
- expect(lpt.pathTo(3)).toEqual([ 5, 1, 3 ]);
89
- expect(lpt.pathTo(4)).toEqual([ 5, 4 ]);
90
- expect(lpt.pathTo(5)).toEqual([ ]);
91
- expect(lpt.pathTo(6)).toEqual([ 5, 1, 3, 6 ]);
92
- expect(lpt.pathTo(7)).toEqual([ 5, 7 ]);
93
- expect(lpt.getDistTo(0)).toBe(0.73);
94
- expect(lpt.getDistTo(1)).toBe(0.32);
95
- expect(lpt.getDistTo(2)).toBe(0.62);
96
- expect(lpt.getDistTo(3)).toBe(0.61);
97
- expect(lpt.getDistTo(4)).toBe(0.35);
98
- expect(lpt.getDistTo(5)).toBe(0);
99
- expect(lpt.getDistTo(6)).toBe(1.13);
100
- expect(lpt.getDistTo(7)).toBe(0.28);
101
- });
102
-
103
- /**
104
- * Check the issue #150
105
- **/
106
- describe("lightest weight path", function(){
107
- it("should find the lightest weight path", function(){
108
- var digraph = new EdgeWeightedDigraph();
109
-
110
- digraph.add(1,3,0.29);
111
- digraph.add(1,6,0);
112
- digraph.add(3,6,0);
113
-
114
- var spt = new SPT(digraph, 1);
115
- var path = spt.pathTo(6);
116
- expect(path).toEqual([1,6]);
117
- });
118
- it("should find the lightest weight path", function(){
119
- var digraph = new EdgeWeightedDigraph();
120
-
121
- digraph.add(1,3,-1);
122
- digraph.add(1,6,0);
123
- digraph.add(3,6,0);
124
-
125
- var spt = new SPT(digraph, 1);
126
- var path = spt.pathTo(6);
127
- var hasPath = spt.hasPathTo(6);
128
- expect(hasPath).toBe(true);
129
- expect(path).toEqual([1,3,6]);
130
- });
131
- });
132
- });
@@ -1,158 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var soundex = require('../lib/natural/phonetics/soundex');
24
-
25
- describe('soundex', function() {
26
- describe('transformLipps', function() {
27
- it('should replace B, F, P, and V with 1', function() {
28
- expect(soundex.transformLipps('bopper')).toBe('1o11er');
29
- expect(soundex.transformLipps('valumf')).toBe('1alum1');
30
- });
31
- });
32
-
33
- describe('transformThroats', function() {
34
- it('should replace C, G, J, K, Q, S, X, Z with 2', function() {
35
- expect(soundex.transformLipps('bopper')).toBe('1o11er');
36
- expect(soundex.transformLipps('valumf')).toBe('1alum1');
37
- });
38
- });
39
-
40
- describe('transformTongue', function() {
41
- it('should replace D and T with 3', function() {
42
- expect(soundex.transformToungue('dat')).toBe('3a3');
43
- });
44
- });
45
-
46
- describe('transformL', function() {
47
- it('should replace L with 4', function() {
48
- expect(soundex.transformL('lala')).toBe('4a4a');
49
- });
50
- });
51
-
52
- describe('transformHum', function() {
53
- it('should replace M and N with 5', function() {
54
- expect(soundex.transformHum('mummification')).toBe('5u55ificatio5');
55
- });
56
- });
57
-
58
- describe('transformR', function() {
59
- it('should replace R with 6', function() {
60
- expect(soundex.transformR('render')).toBe('6ende6');
61
- });
62
- });
63
-
64
- describe('condense', function() {
65
- it('sound condense sequences', function() {
66
- expect(soundex.condense('11222556')).toBe('1256');
67
- });
68
- });
69
-
70
- describe('padRight0', function() {
71
- it('sound padd zeros on the right to a lenght of 3', function() {
72
- expect(soundex.padRight0('1')).toBe('100');
73
- expect(soundex.padRight0('11')).toBe('110');
74
- expect(soundex.padRight0('111')).toBe('111');
75
- });
76
- });
77
-
78
- it('should not code the first character', function() {
79
- expect(soundex.process('render').charAt(0)).toBe('R');
80
- });
81
-
82
- it('should pad right with zeros', function() {
83
- expect(soundex.process('super')).toBe('S160');
84
- expect(soundex.process('butt')).toBe('B300');
85
- expect(soundex.process('a')).toBe('A000');
86
- });
87
-
88
- it('should pad right with zeros', function() {
89
- expect(soundex.process('but')).toBe('B300');
90
- });
91
-
92
- it('should perform soundex', function() {
93
- expect(soundex.process('BLACKBERRY')).toBe('B421');
94
- expect(soundex.process('blackberry')).toBe('B421');
95
- expect(soundex.process('calculate')).toBe('C424');
96
- expect(soundex.process('CALCULATE')).toBe('C424');
97
- expect(soundex.process('fox')).toBe('F200');
98
- expect(soundex.process('FOX')).toBe('F200');
99
- expect(soundex.process('jump')).toBe('J510');
100
- expect(soundex.process('JUMP')).toBe('J510');
101
- expect(soundex.process('phonetics')).toBe('P532');
102
- expect(soundex.process('PHONETICS')).toBe('P532');
103
-
104
- });
105
-
106
- it('should perform soundex via compare method', function() {
107
- expect(soundex.compare('ant', 'and')).toBeTruthy();
108
- expect(soundex.compare('ant', 'anne')).toBeFalsy();
109
- expect(soundex.compare('band', 'bant')).toBeTruthy();
110
- expect(soundex.compare('band', 'gand')).toBeFalsy();
111
- });
112
-
113
- it('should perform soundex via attached soundsLike String patch', function() {
114
- soundex.attach();
115
- expect('ant'.soundsLike('ant')).toBeTruthy();
116
- expect('ant'.soundsLike('anne')).toBeFalsy();
117
- expect('band'.soundsLike('bant')).toBeTruthy();
118
- expect('band'.soundsLike('gand')).toBeFalsy();
119
- });
120
-
121
- it('should return string phonetics with string patch', function() {
122
- soundex.attach();
123
- expect('phonetics'.phonetics()).toBe('P532');
124
- expect('PHONETICS'.phonetics()).toBe('P532');
125
- });
126
-
127
- it('issue 221 -- inital vowels that duplicate cons codes', function() {
128
- soundex.attach();
129
- expect('Lloyd'.phonetics()).toBe('L300');
130
- expect('Pfister'.phonetics()).toBe('P236');
131
-
132
- expect('manhattan'.phonetics()).toBe('M535');
133
- expect('Lukasiewicz'.phonetics()).toBe('L222');
134
-
135
- expect('Gauss'.phonetics()).toBe('G200');
136
- expect('Tymczak'.phonetics()).toBe('T522');
137
- expect('Jackson'.phonetics()).toBe('J250');
138
- });
139
-
140
- it('should tokenize and return string phonetics with string patch', function() {
141
- soundex.attach();
142
- expect('phonetics'.tokenizeAndPhoneticize()).toEqual(['P532']);
143
- expect('phonetics jump'.tokenizeAndPhoneticize()).toEqual(['P532', 'J510']);
144
- expect('phonetics jump calculate'.tokenizeAndPhoneticize()).toEqual(['P532', 'J510', 'C424']);
145
- });
146
-
147
- it('should max out at four characters long by default', function() {
148
- expect(soundex.process('supercalifragilisticexpialidocious').length).toBe(4);
149
- });
150
-
151
- it('should truncate to specified length if maxLength passed', function() {
152
- expect(soundex.process('supercalifragilisticexpialidocious', 8).length).toBe(8);
153
- });
154
-
155
- it('should handle a maxLength beyond code length', function() {
156
- expect(soundex.process('JUMP', 8)).toBe('J510');
157
- });
158
- });
@@ -1,92 +0,0 @@
1
-
2
-
3
- var Spellcheck = require('../lib/natural/spellcheck/spellcheck.js');
4
-
5
- describe('spellcheck', function() {
6
-
7
- describe('distance 1 corrections', function() {
8
- var spellcheck = new Spellcheck(['something']);
9
-
10
- it('should fix deletions', function() {
11
- expect(spellcheck.getCorrections('smething')).toContain('something');
12
- });
13
- it('should fix insertions', function() {
14
- expect(spellcheck.getCorrections('somethhing')).toContain('something');
15
- });
16
- it('should fix transpositions', function() {
17
- expect(spellcheck.getCorrections('somehting')).toContain('something');
18
- });
19
- it('should fix replacements', function() {
20
- expect(spellcheck.getCorrections('sometzing')).toContain('something');
21
- });
22
- });
23
-
24
- describe('distance 2 corrections', function() {
25
- var spellcheck = new Spellcheck(['something']);
26
-
27
- it('should fix a deletion then a transposition', function() {
28
- expect(spellcheck.getCorrections('smtehing', 2)).toContain('something');
29
- });
30
- });
31
-
32
- describe('edits', function() {
33
- var spellcheck = new Spellcheck([]);
34
- var edits = spellcheck.edits('ab');
35
-
36
- it('should compute insertions', function() {
37
- var insertions = ['xab', 'axb', 'abx'];
38
- for(var i in insertions) {
39
- expect(edits.indexOf(insertions[i])).toBeGreaterThan(-1);
40
- }
41
- });
42
- it('should compute deletions', function() {
43
- var deletions = ['a', 'b'];
44
- for(var i in deletions) {
45
- expect(edits.indexOf(deletions[i])).toBeGreaterThan(-1);
46
- }
47
- });
48
- it('should compute transpositions', function() {
49
- var transpositions = ['ba']
50
- for(var i in transpositions) {
51
- expect(edits.indexOf(transpositions[i])).toBeGreaterThan(-1);
52
- }
53
- });
54
- it('should compute replacements', function() {
55
- var replacements = ['zb', 'af']
56
- for(var i in replacements) {
57
- expect(edits.indexOf(replacements[i])).toBeGreaterThan(-1);
58
- }
59
- });
60
- });
61
-
62
- describe('edits up to distance', function() {
63
- var spellcheck = new Spellcheck([]);
64
-
65
- it('should correctly compute edits at distance', function() {
66
- var edits = spellcheck.editsWithMaxDistance('abc', 2);
67
- expect(edits[1].indexOf('abzc')).toBeGreaterThan(-1); // 1 insertion
68
- expect(edits[2].indexOf('a')).toBeGreaterThan(-1); // 2 deletions
69
- });
70
- });
71
-
72
- describe('boolean spellcheck', function() {
73
- var spellcheck = new Spellcheck(['cat']);
74
-
75
- it('should consider cat a word', function() {
76
- expect(spellcheck.isCorrect('cat')).toBe(true);
77
- });
78
-
79
- it('should not consider dog a word', function() {
80
- expect(spellcheck.isCorrect('dog')).toBe(false);
81
- });
82
- });
83
-
84
- describe('special cases', function() {
85
- var spellcheck = new Spellcheck(['cat']);
86
-
87
- it('should return the input word as the most probable correction if it is already correct', function() {
88
- expect(spellcheck.getCorrections('cat').indexOf('cat')).toBe(0);
89
- });
90
-
91
- });
92
- });