natural 0.1.28 → 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 (117) hide show
  1. package/.editorconfig +7 -0
  2. package/.npmignore +4 -11
  3. package/README.md +190 -50
  4. package/bayes_classifier.json +1 -0
  5. package/lib/natural/analyzers/sentence_analyzer.js +8 -5
  6. package/lib/natural/brill_pos_tagger/data/Dutch/README.txt +2 -0
  7. package/lib/natural/brill_pos_tagger/data/Dutch/brill_CONTEXTRULES.jg +285 -0
  8. package/lib/natural/brill_pos_tagger/data/Dutch/brill_LEXICON.jg +11699 -0
  9. package/lib/natural/brill_pos_tagger/data/English/README.txt +8 -0
  10. package/lib/natural/brill_pos_tagger/data/English/lexicon_from_posjs.json +297827 -0
  11. package/lib/natural/brill_pos_tagger/data/English/tr_from_brill_paper.txt +10 -0
  12. package/lib/natural/brill_pos_tagger/data/English/tr_from_posjs.txt +18 -0
  13. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +136 -0
  14. package/lib/natural/brill_pos_tagger/lib/Predicate.js +410 -0
  15. package/lib/natural/brill_pos_tagger/lib/TF_Parser.js +717 -0
  16. package/lib/natural/brill_pos_tagger/lib/TF_Parser.pegjs +55 -0
  17. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +49 -0
  18. package/lib/natural/classifiers/bayes_classifier.js +6 -5
  19. package/lib/natural/classifiers/classifier.js +3 -2
  20. package/lib/natural/classifiers/logistic_regression_classifier.js +9 -5
  21. package/lib/natural/distance/dice_coefficient.js +22 -12
  22. package/lib/natural/distance/jaro-winkler_distance.js +13 -8
  23. package/lib/natural/index.js +6 -0
  24. package/lib/natural/inflectors/present_verb_inflector.js +1 -0
  25. package/lib/natural/ngrams/ngrams.js +6 -0
  26. package/lib/natural/normalizers/normalizer_ja.js +26 -8
  27. package/lib/natural/phonetics/double_metaphone.js +9 -4
  28. package/lib/natural/phonetics/metaphone.js +4 -0
  29. package/lib/natural/phonetics/soundex.js +11 -7
  30. package/lib/natural/spellcheck/spellcheck.js +80 -0
  31. package/lib/natural/stemmers/porter_stemmer.js +90 -62
  32. package/lib/natural/stemmers/porter_stemmer_fr.js +8 -3
  33. package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
  34. package/lib/natural/stemmers/stemmer.js +31 -6
  35. package/lib/natural/stemmers/stemmer_pt.js +65 -0
  36. package/lib/natural/stemmers/token.js +163 -0
  37. package/lib/natural/tfidf/tfidf.js +49 -18
  38. package/lib/natural/tokenizers/regexp_tokenizer.js +3 -3
  39. package/{examples/inflection/noun.js → lib/natural/tokenizers/sentence_tokenizer.js} +14 -10
  40. package/lib/natural/tokenizers/tokenizer_case.js +58 -0
  41. package/lib/natural/util/bag.js +1 -0
  42. package/lib/natural/util/stopwords_pt.js +136 -0
  43. package/lib/natural/wordnet/wordnet.js +2 -2
  44. package/lib/natural/wordnet/wordnet_file.js +1 -1
  45. package/lr_classifier.json +1 -0
  46. package/package.json +7 -4
  47. package/package.json~ +66 -0
  48. package/benchmarks/index.js +0 -32
  49. package/benchmarks/metaphone.js +0 -27
  50. package/benchmarks/soundex.js +0 -27
  51. package/examples/classification/basic.js +0 -35
  52. package/examples/classification/recall.js +0 -28
  53. package/examples/classification/store.js +0 -37
  54. package/examples/inflection/count.js +0 -35
  55. package/examples/inflection/noun_attach.js +0 -33
  56. package/examples/phonetics/compare.js +0 -39
  57. package/examples/phonetics/sounds_like.js +0 -40
  58. package/examples/phonetics/tokenize_and_phoneticize.js +0 -54
  59. package/examples/stemming/stem_corpus.js +0 -29
  60. package/examples/stemming/stem_word.js +0 -26
  61. package/examples/tfidf/array_example.js +0 -34
  62. package/examples/tfidf/multiple_terms.js +0 -33
  63. package/examples/tfidf/tfidf_example.js +0 -44
  64. package/io_spec/test_data/tfidf/one +0 -1
  65. package/io_spec/test_data/tfidf/two +0 -1
  66. package/io_spec/tfidf_spec.js +0 -50
  67. package/io_spec/wordnet_spec.js +0 -81
  68. package/spec/aggressive_tokenizer_es_spec.js +0 -36
  69. package/spec/aggressive_tokenizer_fr_spec.js +0 -101
  70. package/spec/aggressive_tokenizer_nl_spec.js +0 -36
  71. package/spec/aggressive_tokenizer_pt_spec.js +0 -56
  72. package/spec/aggressive_tokenizer_spec.js +0 -56
  73. package/spec/bayes_classifier_spec.js +0 -173
  74. package/spec/classifier_spec.js +0 -91
  75. package/spec/count_inflector_fr_spec.js +0 -44
  76. package/spec/count_inflector_spec.js +0 -73
  77. package/spec/dice_coefficient_spec.js +0 -26
  78. package/spec/double_metaphone_spec.js +0 -743
  79. package/spec/jaro-winkler_spec.js +0 -53
  80. package/spec/lancaster_stemmer_spec.js +0 -73
  81. package/spec/levenshtein_spec.js +0 -66
  82. package/spec/logistic_regression_classifier_spec.js +0 -122
  83. package/spec/longest_path_tree_spec.js +0 -102
  84. package/spec/metaphone_spec.js +0 -247
  85. package/spec/ngram_spec.js +0 -130
  86. package/spec/ngram_zh_spec.js +0 -122
  87. package/spec/normalizer_ja_spec.js +0 -154
  88. package/spec/normalizer_no_spec.js +0 -111
  89. package/spec/normalizer_spec.js +0 -118
  90. package/spec/noun_inflector_fr_spec.js +0 -476
  91. package/spec/noun_inflector_ja_spec.js +0 -112
  92. package/spec/noun_inflector_spec.js +0 -270
  93. package/spec/porter_stemmer_fr_spec.js +0 -101
  94. package/spec/porter_stemmer_it_spec.js +0 -44
  95. package/spec/porter_stemmer_no_spec.js +0 -143
  96. package/spec/porter_stemmer_ru_spec.js +0 -63
  97. package/spec/porter_stemmer_spec.js +0 -137
  98. package/spec/present_verb_inflector_spec.js +0 -125
  99. package/spec/sentence_analyzer_spec.js +0 -29
  100. package/spec/shortest_path_tree_spec.js +0 -132
  101. package/spec/soundex_spec.js +0 -154
  102. package/spec/stemmer_ja_spec.js +0 -66
  103. package/spec/test_data/snowball_fr.txt +0 -20402
  104. package/spec/test_data/snowball_it.txt +0 -35482
  105. package/spec/test_data/snowball_no.txt +0 -20628
  106. package/spec/test_data/tfdif_testcorpus.txt +0 -7
  107. package/spec/test_data/tfidf_document1.txt +0 -1
  108. package/spec/test_data/tfidf_document2.txt +0 -1
  109. package/spec/test_data/tfidf_document3.txt +0 -1
  110. package/spec/test_data/tfidf_document4.txt +0 -1
  111. package/spec/test_data/tfidf_teststopwords.txt +0 -1
  112. package/spec/test_data/wordnet_mini.sql +0 -95
  113. package/spec/tfidf_spec.js +0 -198
  114. package/spec/tokenizer_ja_spec.js +0 -58
  115. package/spec/transliterator_ja_spec.js +0 -103
  116. package/spec/treebank_word_tokenizer_spec.js +0 -36
  117. package/spec/trie_spec.js +0 -206
@@ -1,270 +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 NounInflector = require('../lib/natural/inflectors/noun_inflector'),
24
- inflector = new NounInflector();
25
-
26
- describe('noun inflector', function() {
27
- describe('singularization', function() {
28
- it('should drop an S by default', function() {
29
- expect(inflector.singularize('rrrs')).toBe('rrr');
30
- expect(inflector.singularize('hackers')).toBe('hacker');
31
- expect(inflector.singularize('movies')).toBe('movie');
32
-
33
- // MAN cases that don't pluralize to MEN
34
- expect(inflector.singularize('talismans')).toBe('talisman');
35
- expect(inflector.singularize('humans')).toBe('human');
36
- expect(inflector.singularize('prehumans')).toBe('prehuman');
37
- });
38
-
39
- it('should handle ambiguous form', function() {
40
- expect(inflector.singularize('deer')).toBe('deer');
41
- expect(inflector.singularize('fish')).toBe('fish');
42
- expect(inflector.singularize('series')).toBe('series');
43
- expect(inflector.singularize('sheep')).toBe('sheep');
44
- expect(inflector.singularize('trout')).toBe('trout');
45
- });
46
-
47
- it('should convert plurals ending SES to S', function() {
48
- expect(inflector.singularize('statuses')).toBe('status');
49
- expect(inflector.singularize('buses')).toBe('bus');
50
- });
51
-
52
- it('should match irregulars', function() {
53
- expect(inflector.singularize('people')).toBe('person');
54
- expect(inflector.singularize('children')).toBe('child');
55
- expect(inflector.singularize('oxen')).toBe('ox');
56
- });
57
-
58
- it('should handle IX cases', function() {
59
- expect(inflector.singularize('matrices')).toBe('matrix');
60
- expect(inflector.singularize('indices')).toBe('index');
61
- expect(inflector.singularize('cortices')).toBe('cortex');
62
-
63
- // our pluralizer won''t cause this form of appendix (appendicies)
64
- // but we should handle it
65
- expect(inflector.singularize('appendices')).toBe('appendix');
66
- });
67
-
68
- it('should regulars to ES', function() {
69
- expect(inflector.singularize('churches')).toBe('church');
70
- expect(inflector.singularize('appendixes')).toBe('appendix');
71
- expect(inflector.singularize('messes')).toBe('mess');
72
- expect(inflector.singularize('quizes')).toBe('quiz');
73
- expect(inflector.singularize('shoes')).toBe('shoe');
74
- expect(inflector.singularize('funguses')).toBe('fungus');
75
- });
76
-
77
- it('should handle SIS cases', function() {
78
- expect(inflector.singularize('synopses')).toBe('synopsis');
79
- expect(inflector.singularize('parentheses')).toBe('parenthesis');
80
- });
81
-
82
- it('should handle special OES cases', function() {
83
- expect(inflector.singularize('tomatoes')).toBe('tomato');
84
- });
85
-
86
- it('should handle I cases', function() {
87
- expect(inflector.singularize('octopi')).toBe('octopus');
88
- expect(inflector.singularize('stimuli')).toBe('stimulus');
89
- expect(inflector.singularize('radii')).toBe('radius');
90
- expect(inflector.singularize('nuclei')).toBe('nucleus');
91
- expect(inflector.singularize('fungi')).toBe('fungus');
92
- expect(inflector.singularize('cacti')).toBe('cactus');
93
- });
94
-
95
- it('should handle IVES cases', function() {
96
- expect(inflector.singularize('lives')).toBe('life');
97
- expect(inflector.singularize('knives')).toBe('knife');
98
- });
99
-
100
- it('should handle Y cases', function() {
101
- expect(inflector.singularize('parties')).toBe('party');
102
- expect(inflector.singularize('flies')).toBe('fly');
103
- expect(inflector.singularize('victories')).toBe('victory');
104
- expect(inflector.singularize('monstrosities')).toBe('monstrosity');
105
- });
106
-
107
- it('should handle MAN->MAN cases', function() {
108
- expect(inflector.singularize('men')).toBe('man');
109
- expect(inflector.singularize('women')).toBe('woman');
110
- expect(inflector.singularize('workmen')).toBe('workman');
111
- expect(inflector.singularize('riflemen')).toBe('rifleman');
112
- });
113
-
114
- it('should handle irregular cases', function() {
115
- expect(inflector.singularize('feet')).toBe('foot');
116
- expect(inflector.singularize('geese')).toBe('goose');
117
- expect(inflector.singularize('teeth')).toBe('tooth');
118
- expect(inflector.singularize('ephemerides')).toBe('ephemeris');
119
- });
120
-
121
- it('should handle AE cases', function() {
122
- expect(inflector.singularize('antennae')).toBe('antenna');
123
- expect(inflector.singularize('formulae')).toBe('formula');
124
- expect(inflector.singularize('nebulae')).toBe('nebula');
125
- expect(inflector.singularize('vertebrae')).toBe('vertebra');
126
- expect(inflector.singularize('vitae')).toBe('vita');
127
- });
128
-
129
- it('should allow AE cases to be S', function() {
130
- expect(inflector.singularize('antennas')).toBe('antenna');
131
- expect(inflector.singularize('formulas')).toBe('formula');
132
- });
133
- });
134
-
135
- describe('pluralization', function() {
136
- it('should append an S by default', function() {
137
- expect(inflector.pluralize('rrr')).toBe('rrrs');
138
- expect(inflector.pluralize('hacker')).toBe('hackers');
139
- expect(inflector.pluralize('movie')).toBe('movies');
140
- });
141
-
142
- it('should handle ambiguous form', function() {
143
- expect(inflector.pluralize('deer')).toBe('deer');
144
- expect(inflector.pluralize('fish')).toBe('fish');
145
- expect(inflector.pluralize('series')).toBe('series');
146
- expect(inflector.pluralize('sheep')).toBe('sheep');
147
- expect(inflector.pluralize('trout')).toBe('trout');
148
- });
149
-
150
- it('should convert singulars ending s to ses', function() {
151
- expect(inflector.pluralize('status')).toBe('statuses');
152
- expect(inflector.pluralize('bus')).toBe('buses');
153
- });
154
-
155
- it('should match irregulars', function() {
156
- expect(inflector.pluralize('person')).toBe('people');
157
- expect(inflector.pluralize('child')).toBe('children');
158
- expect(inflector.pluralize('ox')).toBe('oxen');
159
- });
160
-
161
- it('should maintain case of irregulars', function() {
162
- expect(inflector.pluralize('OX')).toBe('OXEN');
163
- expect(inflector.pluralize('Person')).toBe('People');
164
- expect(inflector.pluralize('child')).toBe('children');
165
- });
166
-
167
- it('should handle IX cases', function() {
168
- expect(inflector.pluralize('matrix')).toBe('matrices');
169
- expect(inflector.pluralize('index')).toBe('indices');
170
- expect(inflector.pluralize('cortex')).toBe('cortices');
171
- });
172
-
173
- it('should regulars to ES', function() {
174
- expect(inflector.pluralize('church')).toBe('churches');
175
- expect(inflector.pluralize('appendix')).toBe('appendixes');
176
- expect(inflector.pluralize('mess')).toBe('messes');
177
- expect(inflector.pluralize('quiz')).toBe('quizes');
178
- expect(inflector.pluralize('shoe')).toBe('shoes');
179
- });
180
-
181
- it('should handle SIS cases', function() {
182
- expect(inflector.pluralize('synopsis')).toBe('synopses');
183
- expect(inflector.pluralize('parenthesis')).toBe('parentheses');
184
- });
185
-
186
- it('should handle special OES cases', function() {
187
- expect(inflector.pluralize('tomato')).toBe('tomatoes');
188
- expect(inflector.pluralize('buffalo')).toBe('buffaloes');
189
- expect(inflector.pluralize('tornado')).toBe('tornadoes');
190
- });
191
-
192
- it('should handle I cases', function() {
193
- expect(inflector.pluralize('radius')).toBe('radii');
194
- expect(inflector.pluralize('octopus')).toBe('octopi');
195
- expect(inflector.pluralize('stimulus')).toBe('stimuli');
196
- expect(inflector.pluralize('nucleus')).toBe('nuclei');
197
- expect(inflector.pluralize('fungus')).toBe('fungi');
198
- expect(inflector.pluralize('cactus')).toBe('cacti');
199
- });
200
-
201
- it('should handle IVES cases', function() {
202
- expect(inflector.pluralize('knife')).toBe('knives');
203
- expect(inflector.pluralize('life')).toBe('lives');
204
- });
205
-
206
- it('should handle Y cases', function() {
207
- expect(inflector.pluralize('party')).toBe('parties');
208
- expect(inflector.pluralize('fly')).toBe('flies');
209
- expect(inflector.pluralize('victory')).toBe('victories');
210
- expect(inflector.pluralize('monstrosity')).toBe('monstrosities');
211
- });
212
-
213
- it('should handle MAN->MEN cases', function() {
214
- expect(inflector.pluralize('man')).toBe('men');
215
- expect(inflector.pluralize('woman')).toBe('women');
216
- expect(inflector.pluralize('workman')).toBe('workmen');
217
- expect(inflector.pluralize('rifleman')).toBe('riflemen');
218
- });
219
-
220
- it('should handle irregular cases', function() {
221
- expect(inflector.pluralize('foot')).toBe('feet');
222
- expect(inflector.pluralize('goose')).toBe('geese');
223
- expect(inflector.pluralize('tooth')).toBe('teeth');
224
- expect(inflector.pluralize('ephemeris')).toBe('ephemerides');
225
-
226
- // MAN cases that don't pluralize to MEN
227
- expect(inflector.pluralize('talisman')).toBe('talismans');
228
- expect(inflector.pluralize('human')).toBe('humans');
229
- expect(inflector.pluralize('prehuman')).toBe('prehumans');
230
- });
231
-
232
- it('should handle AE cases', function() {
233
- expect(inflector.pluralize('antenna')).toBe('antennae');
234
- expect(inflector.pluralize('formula')).toBe('formulae');
235
- expect(inflector.pluralize('nebula')).toBe('nebulae');
236
- expect(inflector.pluralize('vertebra')).toBe('vertebrae');
237
- expect(inflector.pluralize('vita')).toBe('vitae');
238
- });
239
- });
240
-
241
- describe('should pluralize and singularize string from patch', function() {
242
- inflector.attach();
243
- expect('synopsis'.pluralizeNoun()).toBe('synopses');
244
- expect('synopses'.singularizeNoun()).toBe('synopsis');
245
- expect('mess'.pluralizeNoun()).toBe('messes');
246
- expect('messes'.singularizeNoun()).toBe('mess');
247
- });
248
-
249
- describe('custom inflections', function() {
250
- describe('should pluralize and singularize custom forms', function() {
251
- var myInflector = new NounInflector();
252
- myInflector.attach();
253
- myInflector.addPlural(/(code|ware)/i, '$1z');
254
- myInflector.addSingular(/(code|ware)z/i, '$1');
255
- expect('code'.pluralizeNoun()).toBe('codez');
256
- expect('ware'.pluralizeNoun()).toBe('warez');
257
- expect('codez'.singularizeNoun()).toBe('code');
258
- expect('warez'.singularizeNoun()).toBe('ware');
259
- });
260
-
261
- describe('should not break regular forms', function() {
262
- var myInflector = new NounInflector();
263
- myInflector.attach();
264
- myInflector.addPlural(/(code|ware)/i, '$1z');
265
- myInflector.addSingular(/(code|ware)z/i, '$1');
266
- expect('bus'.pluralizeNoun()).toBe('buses');
267
- expect('buses'.singularizeNoun()).toBe('bus');
268
- });
269
- });
270
- });
@@ -1,101 +0,0 @@
1
- /*
2
- Copyright (c) 2014, Ismaël Héry
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 stemmer = require('../lib/natural/stemmers/porter_stemmer_fr');
24
- var fs = require('fs');
25
-
26
- describe('porter_stemmer', function() {
27
-
28
- it('should prelude', function() {
29
- expect(stemmer.prelude('JOUER')).toBe('joUer');
30
- expect(stemmer.prelude('ennuie')).toBe('ennuIe');
31
- expect(stemmer.prelude('yeux')).toBe('Yeux');
32
- expect(stemmer.prelude('quand')).toBe('qUand');
33
- });
34
-
35
- it('should compute regions', function() {
36
- expect(stemmer.regions('fameusement').r1).toBe(3);
37
- expect(stemmer.regions('fameusement').r2).toBe(6);
38
-
39
- expect(stemmer.regions('taii').r1).toBe(4);
40
- expect(stemmer.regions('taii').r2).toBe(4);
41
-
42
- expect(stemmer.regions('parade').rv).toBe(3);
43
- expect(stemmer.regions('colet').rv).toBe(3);
44
- expect(stemmer.regions('tapis').rv).toBe(3);
45
- expect(stemmer.regions('aimer').rv).toBe(3);
46
- expect(stemmer.regions('adorer').rv).toBe(3);
47
- expect(stemmer.regions('voler').rv).toBe(2);
48
- expect(stemmer.regions('tue').rv).toBe(2);
49
- });
50
-
51
- it('should compute longest suffix ends in Arr', function() {
52
- expect(stemmer.endsinArr('voudriez', ['ez', 'iez', 'z'])).toBe('iez');
53
- });
54
-
55
- it('should stem some word', function() {
56
- expect(stemmer.stem('volera')).toBe('vol');
57
- expect(stemmer.stem('volerait')).toBe('vol');
58
- expect(stemmer.stem('subitement')).toBe('subit');
59
- expect(stemmer.stem('tempérament')).toBe('temper');
60
- expect(stemmer.stem('voudriez')).toBe('voudr');
61
- expect(stemmer.stem('vengeait')).toBe('veng');
62
- expect(stemmer.stem('saisissement')).toBe('sais');
63
- expect(stemmer.stem('transatlantique')).toBe('transatlant');
64
- expect(stemmer.stem('premièrement')).toBe('premi');
65
- expect(stemmer.stem('instruments')).toBe('instrument');
66
- expect(stemmer.stem('trouverions')).toBe('trouv');
67
- expect(stemmer.stem('voyiez')).toBe('voi');
68
- expect(stemmer.stem('publicité')).toBe('publiqu');
69
- expect(stemmer.stem('pitoyable')).toBe('pitoi');
70
- });
71
-
72
- it('should perform stemming on a lot of words', function() {
73
- var ok = [];
74
- var ko = [];
75
- fs.readFileSync('spec/test_data/snowball_fr.txt').toString().split('\n').forEach(function(line) {
76
- if (line) {
77
- var fields = line.replace(/(\s)+/g, ' ').split(' ');
78
- var stemmed = stemmer.stem(fields[0]);
79
- var regs = stemmer.regions(fields[0]);
80
- var txtRegions = {
81
- r1: fields[0].substring(regs.r1),
82
- r2: fields[0].substring(regs.r2),
83
- rv: fields[0].substring(regs.rv)
84
- }
85
-
86
- if (stemmed === fields[1])
87
- ok.push(fields[0]);
88
- else
89
- ko.push({
90
- word: fields[0],
91
- expected: fields[1],
92
- actual: stemmed,
93
- regions: txtRegions
94
- });
95
- }
96
- });
97
-
98
- expect(ko.length).toBe(0);
99
- });
100
-
101
- });
@@ -1,44 +0,0 @@
1
- /*
2
- Copyright (c) 2012, Leonardo Fenu, 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 stemmer = require('lib/natural/stemmers/porter_stemmer_it');
24
- var fs = require('fs');
25
-
26
- describe('porter_stemmer_it', function() {
27
- it('should perform stem', function() {
28
- fs.readFileSync('spec/test_data/snowball_it.txt').toString().replace(/\r/g, '\n').split('\n').forEach(
29
- function(line) {
30
- if (line) {
31
- var fields = line.split(' -> ');
32
- var stemmed = stemmer.stem(fields[0]);
33
- expect(stemmed).toEqual(fields[1]);
34
- }
35
- }
36
- );
37
- });
38
- it('should tokenize and stem attached', function() {
39
- stemmer.attach();
40
-
41
- expect('SOPRA la panca la capra CAMPA'.tokenizeAndStem()).toEqual([ 'sopr', 'panc', 'capr', 'camp' ]);
42
- expect('SOTTO la panca la capra CREPA'.tokenizeAndStem()).toEqual([ 'sott', 'panc', 'capr', 'crep' ]);
43
- });
44
- });
@@ -1,143 +0,0 @@
1
- /*
2
- Copyright (c) 2014, Kristoffer Brabrand
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 stemmer = require('../lib/natural/stemmers/porter_stemmer_no'),
24
- fs = require('fs');
25
-
26
- describe('porter_stemmer_no', function() {
27
- it('should perform step 1a', function() {
28
- expect(stemmer.step1a('forenkla')).toBe('forenkl');
29
- expect(stemmer.step1a('aase')).toBe('aas');
30
- expect(stemmer.step1a('allerede')).toBe('aller');
31
- expect(stemmer.step1a('aukande')).toBe('auk');
32
- expect(stemmer.step1a('avbøtende')).toBe('avbøt');
33
- expect(stemmer.step1a('avdelingane')).toBe('avdeling');
34
- expect(stemmer.step1a('avgiftene')).toBe('avgift');
35
- expect(stemmer.step1a('havnevirksomhetene')).toBe('havnevirksom');
36
- expect(stemmer.step1a('heimelen')).toBe('heimel');
37
- expect(stemmer.step1a('hovedvirksomheten')).toBe('hovedvirksom');
38
- expect(stemmer.step1a('hovudreglar')).toBe('hovudregl');
39
- expect(stemmer.step1a('hugger')).toBe('hugg');
40
- expect(stemmer.step1a('importvirksomheter')).toBe('importvirksom');
41
- expect(stemmer.step1a('ivaretas')).toBe('ivaret');
42
- expect(stemmer.step1a('iverksettes')).toBe('iverksett');
43
- expect(stemmer.step1a('konsekvensutredes')).toBe('konsekvensutr');
44
- expect(stemmer.step1a('oversendes')).toBe('overs');
45
- expect(stemmer.step1a('pensjonenes')).toBe('pensjon');
46
- expect(stemmer.step1a('myndighetenes')).toBe('myndig');
47
- expect(stemmer.step1a('møteleiarens')).toBe('møteleiar');
48
- expect(stemmer.step1a('virksomhetens')).toBe('virksom');
49
- expect(stemmer.step1a('aktørers')).toBe('aktør');
50
- expect(stemmer.step1a('arbeidslivets')).toBe('arbeidsliv');
51
- expect(stemmer.step1a('arbeidskapasitet')).toBe('arbeidskapasit');
52
- expect(stemmer.step1a('arealknapphet')).toBe('arealknapp');
53
- expect(stemmer.step1a('attgjevast')).toBe('attgjev');
54
- });
55
-
56
- it('should perform step 1b', function() {
57
- expect(stemmer.step1b('hinder')).toBe('hinder');
58
- expect(stemmer.step1b('erwerbs')).toBe('erwerb');
59
- expect(stemmer.step1b('alltids')).toBe('alltid');
60
- });
61
-
62
- it('should perform step 1c', function() {
63
- expect(stemmer.step1c('akkumulerte')).toBe('akkumuler');
64
- expect(stemmer.step1c('akseptert')).toBe('aksepter');
65
- });
66
-
67
- it('should perform step 1 (a-c)', function() {
68
- expect(stemmer.step1('andelar')).toBe('andel');
69
- expect(stemmer.step1('andeleigar')).toBe('andeleig');
70
- expect(stemmer.step1('andeleigarane')).toBe('andeleigar');
71
- expect(stemmer.step1('andeleigarbok')).toBe('andeleigarbok');
72
- expect(stemmer.step1('andelen')).toBe('andel');
73
- expect(stemmer.step1('andelene')).toBe('andel');
74
- expect(stemmer.step1('andeler')).toBe('andel');
75
- expect(stemmer.step1('andelsbevis')).toBe('andelsbevis');
76
- expect(stemmer.step1('andelsbok')).toBe('andelsbok');
77
- expect(stemmer.step1('andelsboka')).toBe('andelsbok');
78
- expect(stemmer.step1('andelsboligforening')).toBe('andelsboligforening');
79
- expect(stemmer.step1('andelsboligforeninger')).toBe('andelsboligforening');
80
- expect(stemmer.step1('andelsboligorganisation')).toBe('andelsboligorganisation');
81
- expect(stemmer.step1('andelsboligorganisationer')).toBe('andelsboligorganisation');
82
- expect(stemmer.step1('andelsbrev')).toBe('andelsbrev');
83
- });
84
-
85
- it('should perform step 2', function() {
86
- expect(stemmer.step2('hvorvidt')).toBe('hvorvid');
87
- expect(stemmer.step2('innovativt')).toBe('innovativ');
88
- });
89
-
90
- it('should perform step 3', function() {
91
- expect(stemmer.step3('lovleg')).toBe('lov');
92
- expect(stemmer.step3('konkurranseskadeleg')).toBe('konkurranseskad');
93
- expect(stemmer.step3('lystig')).toBe('lyst');
94
- expect(stemmer.step3('utrolig')).toBe('utro');
95
- expect(stemmer.step3('utrøstelig')).toBe('utrøst');
96
- expect(stemmer.step3('boliglov')).toBe('bolig');
97
- expect(stemmer.step3('samvirkelov')).toBe('samvirk');
98
- expect(stemmer.step3('arveavgiftslov')).toBe('arveavgift');
99
- });
100
-
101
- it('should perform stemming on a lot of words', function() {
102
- var ok = [];
103
- var ko = [];
104
-
105
- fs.readFileSync('spec/test_data/snowball_no.txt').toString().split('\n').forEach(function(line) {
106
- if (line) {
107
- var fields = line.replace(/(\s)+/g, ' ').split(' ');
108
- var stemmed = stemmer.stem(fields[0]);
109
-
110
- if (stemmed === fields[1]) {
111
- ok.push(fields[0]);
112
- } else {
113
- ko.push({
114
- word: fields[0],
115
- expected: fields[1],
116
- actual: stemmed
117
- });
118
- }
119
- }
120
- });
121
-
122
- expect(ko.length).toBe(0);
123
- });
124
-
125
- it('should perform complete stemming', function() {
126
- expect(stemmer.step1a('forenkla')).toBe('forenkl');
127
- expect(stemmer.step1a('aase')).toBe('aas');
128
- expect(stemmer.step1a('allerede')).toBe('aller');
129
- expect(stemmer.step1a('aukande')).toBe('auk');
130
- expect(stemmer.step1a('avbøtende')).toBe('avbøt');
131
- expect(stemmer.step1b('hinder')).toBe('hinder');
132
- expect(stemmer.step1b('erwerbs')).toBe('erwerb');
133
- expect(stemmer.step3('boliglov')).toBe('bolig');
134
- expect(stemmer.step3('samvirkelov')).toBe('samvirk');
135
- expect(stemmer.step3('arveavgiftslov')).toBe('arveavgift');
136
- });
137
-
138
- it('should tokenize and stem attached', function() {
139
- stemmer.attach();
140
- expect('forebygger vedlikeholdsbehovene'.tokenizeAndStem()).toEqual(['forebygg', 'vedlikeholdsbehov']);
141
- expect('FOREBYGGER VEDLIKEHOLDSBEHOVENE'.tokenizeAndStem()).toEqual(['forebygg', 'vedlikeholdsbehov']);
142
- });
143
- });
@@ -1,63 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Polyakov Vladimir, 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
- var stemmer = require('../lib/natural/stemmers/porter_stemmer_ru');
23
-
24
- var test = [
25
- 'в', 'вавиловка', 'вагнера', 'вагон', 'вагона', 'вагоне', 'вагонов', 'вагоном', 'вагоны',
26
- 'важная', 'важнее', 'важнейшие', 'важнейшими', 'важничал', 'важно', 'важного', 'важное',
27
- 'важной', 'важном', 'важному', 'важности', 'важностию', 'важность', 'важностью', 'важную',
28
- 'важны', 'важные', 'важный', 'важным', 'важных', 'вазах', 'вазы', 'вакса', 'вакханка', 'вал',
29
- 'валандался', 'валентина', 'валериановых', 'валерию', 'валетами', 'вали', 'валил', 'валился',
30
- 'валится', 'валов', 'вальдшнепа', 'вальс', 'вальса', 'вальсе', 'вальсишку', 'вальтера', 'валяется',
31
- 'валялась', 'валялись', 'валялось', 'валялся', 'валять', 'валяются', 'вам', 'вами', 'п', 'па', 'пава',
32
- 'павел', 'павильон', 'павильонам', 'павла', 'павлиний', 'павлиньи', 'павлиньим', 'павлович', 'павловна',
33
- 'павловне', 'павловной', 'павловну', 'павловны', 'павловцы', 'павлыч', 'павлыча', 'пагубная', 'падает',
34
- 'падай', 'падал', 'падала', 'падаль', 'падать', 'падаю', 'падают', 'падающего', 'падающие', 'падеж', 'падение',
35
- 'падением', 'падении', 'падений', 'падения', 'паденье', 'паденья', 'падет', 'падут', 'падучая', 'падчерицей',
36
- 'падчерицы', 'падшая', 'падшей', 'падшему', 'падший', 'падшим', 'падших', 'падшую', 'паек', 'пазухи', 'пазуху',
37
- 'пай', 'пакет', 'пакетом', 'пакеты', 'пакостей', 'пакостно', 'пал'];
38
-
39
- var testResult = [
40
- 'в', 'вавиловк', 'вагнер', 'вагон', 'вагон', 'вагон', 'вагон', 'вагон', 'вагон', 'важн', 'важн', 'важн',
41
- 'важн', 'важнича', 'важн', 'важн', 'важн', 'важн', 'важн', 'важн', 'важност', 'важност', 'важност',
42
- 'важност', 'важн', 'важн', 'важн', 'важн', 'важн', 'важн', 'ваз', 'ваз', 'вакс', 'вакханк', 'вал',
43
- 'валанда', 'валентин', 'валерианов', 'валер', 'валет', 'вал', 'вал', 'вал', 'вал', 'вал', 'вальдшнеп',
44
- 'вальс', 'вальс', 'вальс', 'вальсишк', 'вальтер', 'валя', 'валя', 'валя', 'валя', 'валя', 'валя', 'валя',
45
- 'вам', 'вам', 'п', 'па', 'пав', 'павел', 'павильон', 'павильон', 'павл', 'павлин', 'павлин', 'павлин',
46
- 'павлович', 'павловн', 'павловн', 'павловн', 'павловн', 'павловн', 'павловц', 'павлыч', 'павлыч', 'пагубн',
47
- 'пада', 'пада', 'пада', 'пада', 'падал', 'пада', 'пада', 'пада', 'пада', 'пада', 'падеж', 'паден', 'паден',
48
- 'паден', 'паден', 'паден', 'паден', 'паден', 'падет', 'падут', 'падуч', 'падчериц', 'падчериц', 'падш', 'падш',
49
- 'падш', 'падш', 'падш', 'падш', 'падш', 'паек', 'пазух', 'пазух', 'па', 'пакет', 'пакет', 'пакет', 'пакост',
50
- 'пакостн', 'пал'];
51
-
52
- describe('porter_stemmer', function() {
53
- it('should permof stem', function() {
54
- for (var i = 0; i < test.length; i++) {
55
- expect(stemmer.stem(test[i])).toBe(testResult[i]);
56
- }
57
- }),
58
- it('should tokenize and stem attached', function() {
59
- stemmer.attach();
60
- expect('мама мыла раму'.tokenizeAndStem()).toEqual(['мам', 'мыл', 'рам']);
61
- expect('МАМА МЫЛА РАМУ'.tokenizeAndStem()).toEqual(['мам', 'мыл', 'рам']);
62
- });
63
- });