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,112 +0,0 @@
1
- /*
2
- Copyright (c) 2012, Guillaume Marty
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/ja/noun_inflector'),
24
- inflector = new NounInflector();
25
-
26
- describe('NounInflector', function() {
27
- describe('.pluralize()', function() {
28
- describe('should pluralize nouns', function() {
29
- expect(inflector.pluralize('ひと')).toBe('ひとたち');
30
- expect(inflector.pluralize('わたし')).toBe('わたしたち');
31
- expect(inflector.pluralize('私')).toBe('私たち');
32
- });
33
-
34
- describe('should not pluralize exceptions', function() {
35
- expect(inflector.pluralize('ともだち')).toBe('ともだち');
36
- expect(inflector.pluralize('友だち')).toBe('友だち');
37
- expect(inflector.pluralize('友達')).toBe('友達');
38
- });
39
-
40
- describe('should pluralize archaic forms', function() {
41
- expect(inflector.pluralize('神')).toBe('神神');
42
- expect(inflector.pluralize('人')).toBe('人人');
43
- expect(inflector.pluralize('我')).toBe('我我');
44
- });
45
- });
46
-
47
- describe('.singularize()', function() {
48
- describe('should singularize regular nouns ending by -tachi in Hiragana', function() {
49
- expect(inflector.singularize('わたしたち')).toBe('わたし');
50
- expect(inflector.singularize('人たち')).toBe('人');
51
- expect(inflector.singularize('りかたち')).toBe('りか');
52
- });
53
-
54
- describe('should not singularize exception nouns ending by -tachi in Hiragana', function() {
55
- expect(inflector.singularize('ついたち')).toBe('ついたち');
56
- expect(inflector.singularize('かたち')).toBe('かたち');
57
- expect(inflector.singularize('はたち')).toBe('はたち');
58
- });
59
-
60
- describe('should singularize regular nouns ending by -tachi in Kanji', function() {
61
- expect(inflector.singularize('わたし達')).toBe('わたし');
62
- expect(inflector.singularize('人達')).toBe('人');
63
- expect(inflector.singularize('日伊達')).toBe('日伊');
64
- });
65
-
66
- describe('should not singularize exception nouns ending by -tachi in Kanji', function() {
67
- expect(inflector.singularize('上達')).toBe('上達');
68
- expect(inflector.singularize('配達')).toBe('配達');
69
- expect(inflector.singularize('発達')).toBe('発達');
70
- });
71
-
72
- describe('should singularize regular nouns ending by -ra in Kanji', function() {
73
- expect(inflector.singularize('僕等')).toBe('僕');
74
- expect(inflector.singularize('貴様等')).toBe('貴様');
75
- expect(inflector.singularize('圭一等')).toBe('圭一');
76
- });
77
-
78
- describe('should not singularize exception nouns ending by -ra in Kanji', function() {
79
- expect(inflector.singularize('下等')).toBe('下等');
80
- expect(inflector.singularize('初等')).toBe('初等');
81
- expect(inflector.singularize('一等')).toBe('一等');
82
- });
83
-
84
- describe('should singularize regular nouns ending by -gata', function() {
85
- expect(inflector.singularize('神様方')).toBe('神様');
86
- expect(inflector.singularize('先生方')).toBe('先生');
87
- expect(inflector.singularize('あなたがた')).toBe('あなた');
88
- });
89
-
90
- describe('should singularize regular nouns ending by -domo', function() {
91
- expect(inflector.singularize('人間共')).toBe('人間');
92
- expect(inflector.singularize('野郎共')).toBe('野郎');
93
- expect(inflector.singularize('ガキども')).toBe('ガキ');
94
- });
95
-
96
- describe('should pluralize archaic forms', function() {
97
- expect(inflector.singularize('神神')).toBe('神');
98
- expect(inflector.singularize('人人')).toBe('人');
99
- expect(inflector.singularize('我我')).toBe('我');
100
- });
101
- });
102
-
103
- describe('.attach()', function() {
104
- describe('should attach new methods to String', function() {
105
- inflector.attach();
106
- expect('私'.pluralizeNoun()).toBe('私たち');
107
- expect('私たち'.singularizeNoun()).toBe('私');
108
- expect('人'.pluralizeNoun()).toBe('人人');
109
- expect('人人'.singularizeNoun()).toBe('人');
110
- });
111
- });
112
- });
@@ -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
- });