natural 7.0.3 → 7.0.5

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 (69) hide show
  1. package/.github/workflows/npm-publish.yml +2 -0
  2. package/.nycrc +9 -0
  3. package/package.json +3 -4
  4. package/tsconfig.json +1 -1
  5. package/ts_spec/MaxEntClassifier_spec.ts +0 -130
  6. package/ts_spec/SentimentAnalyzer_spec.ts +0 -232
  7. package/ts_spec/WordPunctTokenizer_spec.ts +0 -57
  8. package/ts_spec/aggressive_tokenizer_de_spec.ts +0 -36
  9. package/ts_spec/aggressive_tokenizer_es_spec.ts +0 -39
  10. package/ts_spec/aggressive_tokenizer_fr_spec.ts +0 -111
  11. package/ts_spec/aggressive_tokenizer_hi_spec.ts +0 -70
  12. package/ts_spec/aggressive_tokenizer_nl_spec.ts +0 -39
  13. package/ts_spec/aggressive_tokenizer_pt_spec.ts +0 -48
  14. package/ts_spec/aggressive_tokenizer_spec.ts +0 -57
  15. package/ts_spec/aggressive_tokenizer_sv_spec.ts +0 -52
  16. package/ts_spec/aggressive_tokenizer_vi_spec.ts +0 -48
  17. package/ts_spec/bayes_classifier_spec.ts +0 -165
  18. package/ts_spec/brill_pos_tagger_spec.ts +0 -79
  19. package/ts_spec/brill_pos_trainer_spec.ts +0 -107
  20. package/ts_spec/carry_stemmer_fr_spec.ts +0 -97
  21. package/ts_spec/classifier_spec.ts +0 -104
  22. package/ts_spec/count_inflector_fr_spec.ts +0 -47
  23. package/ts_spec/count_inflector_spec.ts +0 -76
  24. package/ts_spec/damerau_levenshtein_spec.ts +0 -53
  25. package/ts_spec/dice_coefficient_spec.ts +0 -37
  26. package/ts_spec/double_metaphone_spec.ts +0 -739
  27. package/ts_spec/hamming_distance_spec.ts +0 -66
  28. package/ts_spec/jaro-winkler_spec.ts +0 -79
  29. package/ts_spec/lancaster_stemmer_spec.ts +0 -63
  30. package/ts_spec/levenshtein_spec.ts +0 -107
  31. package/ts_spec/logistic_regression_classifier_spec.ts +0 -93
  32. package/ts_spec/longest_path_tree_spec.ts +0 -111
  33. package/ts_spec/metaphone_spec.ts +0 -258
  34. package/ts_spec/ngram_spec.ts +0 -145
  35. package/ts_spec/ngram_zh_spec.ts +0 -124
  36. package/ts_spec/normalizer_ja_spec.ts +0 -165
  37. package/ts_spec/normalizer_no_spec.ts +0 -112
  38. package/ts_spec/normalizer_spec.ts +0 -141
  39. package/ts_spec/noun_inflector_fr_spec.ts +0 -472
  40. package/ts_spec/noun_inflector_ja_spec.ts +0 -116
  41. package/ts_spec/noun_inflector_spec.ts +0 -369
  42. package/ts_spec/orthography_tokenizer_spec.ts +0 -47
  43. package/ts_spec/porter_stemmer_de_spec.ts +0 -53
  44. package/ts_spec/porter_stemmer_es_spec.ts +0 -63
  45. package/ts_spec/porter_stemmer_fr_spec.ts +0 -103
  46. package/ts_spec/porter_stemmer_it_spec.ts +0 -56
  47. package/ts_spec/porter_stemmer_nl_spec.ts +0 -73
  48. package/ts_spec/porter_stemmer_no_spec.ts +0 -148
  49. package/ts_spec/porter_stemmer_pt_spec.ts +0 -50
  50. package/ts_spec/porter_stemmer_ru_spec.ts +0 -67
  51. package/ts_spec/porter_stemmer_spec.ts +0 -202
  52. package/ts_spec/porter_stemmer_sv_spec.ts +0 -41
  53. package/ts_spec/present_verb_inflector_spec.ts +0 -127
  54. package/ts_spec/remove_diacritics_spec.ts +0 -30
  55. package/ts_spec/sentence_analyzer_spec.ts +0 -293
  56. package/ts_spec/sentence_tokenizer_parser_spec.ts +0 -200
  57. package/ts_spec/sentence_tokenizer_spec.ts +0 -189
  58. package/ts_spec/shortest_path_tree_spec.ts +0 -141
  59. package/ts_spec/soundex_spec.ts +0 -162
  60. package/ts_spec/spellcheck_spec.ts +0 -112
  61. package/ts_spec/stemmer_id_spec.ts +0 -374
  62. package/ts_spec/stemmer_ja_spec.ts +0 -69
  63. package/ts_spec/stemmer_token_spec.ts +0 -163
  64. package/ts_spec/tfidf_spec.ts +0 -275
  65. package/ts_spec/tokenizer_case_spec.ts +0 -242
  66. package/ts_spec/tokenizer_ja_spec.ts +0 -63
  67. package/ts_spec/transliterator_ja_spec.ts +0 -105
  68. package/ts_spec/treebank_word_tokenizer_spec.ts +0 -38
  69. package/ts_spec/trie_spec.ts +0 -197
@@ -1,258 +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
- 'use strict'
24
-
25
- import { Metaphone } from 'lib/natural'
26
- const metaphone = new Metaphone()
27
-
28
- describe('metaphone', function () {
29
- it('should drop duplicate adjacent letters, except C', function () {
30
- expect(metaphone.dedup('dropping')).toBe('droping')
31
- })
32
-
33
- it('should not drop duplicat C', function () {
34
- expect(metaphone.dedup('accelerate')).toBe('accelerate')
35
- })
36
-
37
- it('should drop some initial letters', function () {
38
- expect(metaphone.dropInitialLetters('knuth')).toBe('nuth')
39
- expect(metaphone.dropInitialLetters('gnat')).toBe('nat')
40
- expect(metaphone.dropInitialLetters('aegis')).toBe('egis')
41
- expect(metaphone.dropInitialLetters('pneumatic')).toBe('neumatic')
42
- expect(metaphone.dropInitialLetters('wrack')).toBe('rack')
43
- })
44
-
45
- it('should not drop other initial letters', function () {
46
- expect(metaphone.dropInitialLetters('garbage')).toBe('garbage')
47
- })
48
-
49
- it('should b if if words end with mb', function () {
50
- expect(metaphone.dropBafterMAtEnd('dumb')).toBe('dum')
51
- })
52
-
53
- it('should not drop b after m if not at end of word', function () {
54
- expect(metaphone.dropBafterMAtEnd('dumbo')).toBe('dumbo')
55
- })
56
-
57
- it('should replace CH to X', function () {
58
- expect(metaphone.cTransform('change')).toBe('xhange')
59
- })
60
-
61
- it('should not replace CH to X if part of SCH', function () {
62
- expect(metaphone.cTransform('discharger')).toBe('diskharger')
63
- })
64
-
65
- it('should replace CIA to X', function () {
66
- expect(metaphone.cTransform('aesthetician')).toBe('aesthetixian')
67
- })
68
-
69
- it('C should become S if followed by I, E, or Y', function () {
70
- expect(metaphone.cTransform('cieling')).toBe('sieling')
71
- })
72
-
73
- it('should transform other C\'s to K', function () {
74
- expect(metaphone.cTransform('cuss')).toBe('kuss')
75
- })
76
-
77
- it('should transform D to J if followed by GE, GY, GI', function () {
78
- expect(metaphone.dTransform('abridge')).toBe('abrijge')
79
- })
80
-
81
- it('should transform D to T if not followed by GE, GY, GI', function () {
82
- expect(metaphone.dTransform('bid')).toBe('bit')
83
- })
84
-
85
- it('should drop G before H if not at the end or before vowell', function () {
86
- expect(metaphone.dropG('alight')).toBe('aliht')
87
- expect(metaphone.dropG('fright')).toBe('friht')
88
- })
89
-
90
- it('should drop G if followed by N or NED at the end', function () {
91
- expect(metaphone.dropG('aligned')).toBe('alined')
92
- expect(metaphone.dropG('align')).toBe('alin')
93
- })
94
-
95
- it('should transform G to J if followed by I, E or Y and not preceeded by G', function () {
96
- expect(metaphone.transformG('age')).toBe('aje')
97
- expect(metaphone.transformG('gin')).toBe('jin')
98
- })
99
-
100
- it('should transform G to K', function () {
101
- expect(metaphone.transformG('august')).toBe('aukust')
102
- })
103
-
104
- it('should reduce GG to G before turning to K', function () {
105
- expect(metaphone.transformG('aggrade')).toBe('akrade')
106
- })
107
-
108
- it('should drop H if after vowell and not before vowell', function () {
109
- expect(metaphone.dropH('alriht')).toBe('alrit')
110
- })
111
-
112
- it('should not drop H if after vowell', function () {
113
- expect(metaphone.dropH('that')).toBe('that')
114
- })
115
-
116
- it('should not drop H if not before vowell', function () {
117
- expect(metaphone.dropH('chump')).toBe('chump')
118
- })
119
-
120
- it('should transform CK to K', function () {
121
- expect(metaphone.transformCK('check')).toBe('chek')
122
- })
123
-
124
- it('should transform PH to F', function () {
125
- expect(metaphone.transformPH('phone')).toBe('fone')
126
- })
127
-
128
- it('should transform Q to K', function () {
129
- expect(metaphone.transformQ('quack')).toBe('kuack')
130
- })
131
-
132
- it('should transform S to X if followed by H, IO, or IA', function () {
133
- expect(metaphone.transformS('shack')).toBe('xhack')
134
- expect(metaphone.transformS('sialagogues')).toBe('xialagogues')
135
- expect(metaphone.transformS('asia')).toBe('axia')
136
- })
137
-
138
- it('should not transform S to X if not followed by H, IO, or IA', function () {
139
- expect(metaphone.transformS('substance')).toBe('substance')
140
- })
141
-
142
- it('should transform T to X if followed by IA or IO', function () {
143
- expect(metaphone.transformT('dementia')).toBe('demenxia')
144
- expect(metaphone.transformT('abbreviation')).toBe('abbreviaxion')
145
- })
146
-
147
- it('should transform TH to 0', function () {
148
- expect(metaphone.transformT('that')).toBe('0at')
149
- })
150
-
151
- it('should drop T if followed by CH', function () {
152
- expect(metaphone.dropT('backstitch')).toBe('backstich')
153
- })
154
-
155
- it('should transform V to F', function () {
156
- expect(metaphone.transformV('vestige')).toBe('festige')
157
- })
158
-
159
- it('should transform WH to W if at beginning', function () {
160
- expect(metaphone.transformWH('whisper')).toBe('wisper')
161
- })
162
-
163
- it('should drop W if not followed by vowell', function () {
164
- expect(metaphone.dropW('bowl')).toBe('bol')
165
- expect(metaphone.dropW('warsaw')).toBe('warsa')
166
- })
167
-
168
- it('should transform X to S if at beginning', function () {
169
- expect(metaphone.transformX('xenophile')).toBe('senophile')
170
- })
171
-
172
- it('should transform X to KS if not at beginning', function () {
173
- expect(metaphone.transformX('admixed')).toBe('admiksed')
174
- })
175
-
176
- it('should drop Y of not followed by a vowell', function () {
177
- expect(metaphone.dropY('analyzer')).toBe('analzer')
178
- expect(metaphone.dropY('specify')).toBe('specif')
179
- })
180
-
181
- it('should not drop Y of followed by a vowell', function () {
182
- expect(metaphone.dropY('allying')).toBe('allying')
183
- })
184
-
185
- it('should transform Z to S', function () {
186
- expect(metaphone.transformZ('blaze')).toBe('blase')
187
- })
188
-
189
- it('should drop all vowels except initial', function () {
190
- expect(metaphone.dropVowels('ablaze')).toBe('ablz')
191
- expect(metaphone.dropVowels('adamantium')).toBe('admntm')
192
- })
193
-
194
- it('should do all', function () {
195
- expect(metaphone.process('ablaze')).toBe('ABLS')
196
- expect(metaphone.process('transition')).toBe('TRNSXN')
197
- expect(metaphone.process('astronomical')).toBe('ASTRNMKL')
198
- expect(metaphone.process('buzzard')).toBe('BSRT')
199
- expect(metaphone.process('wonderer')).toBe('WNTRR')
200
- expect(metaphone.process('district')).toBe('TSTRKT')
201
- expect(metaphone.process('hockey')).toBe('HK')
202
- expect(metaphone.process('capital')).toBe('KPTL')
203
- expect(metaphone.process('penguin')).toBe('PNKN')
204
- expect(metaphone.process('garbonzo')).toBe('KRBNS')
205
- expect(metaphone.process('lightning')).toBe('LTNNK')
206
- expect(metaphone.process('light')).toBe('LT')
207
- })
208
-
209
- it('should compare strings', function () {
210
- expect(metaphone.compare('phonetics', 'fonetix')).toBeTruthy()
211
- expect(metaphone.compare('phonetics', 'garbonzo')).toBeFalsy()
212
- expect(metaphone.compare('PHONETICS', 'fonetix')).toBeTruthy()
213
- expect(metaphone.compare('PHONETICS', 'garbonzo')).toBeFalsy()
214
- })
215
-
216
- /*
217
- it('#173', function () {
218
- expect(metaphone.process('caesar')).toBe('KSR')
219
- expect(metaphone.process('chemical')).toBe('KMKL')
220
- })
221
- */
222
-
223
- /*
224
- it('should compare strings with string patch', function() {
225
- metaphone.attach();
226
- expect('phonetics'.soundsLike('fonetix')).toBeTruthy();
227
- expect('phonetics'.soundsLike('garbonzo')).toBeFalsy();
228
- expect('PHONETICS'.soundsLike('fonetix')).toBeTruthy();
229
- expect('PHONETICS'.soundsLike('garbonzo')).toBeFalsy();
230
- });
231
-
232
- it('should return string phonetics with string patch', function() {
233
- metaphone.attach();
234
- expect('phonetics'.phonetics()).toBe('FNTKS');
235
- expect('PHONETICS'.phonetics()).toBe('FNTKS');
236
- });
237
-
238
- it('should transform PH to F #169', function() {
239
- expect('pharaoh'.phonetics()).toBe('FR');
240
- expect('tough'.phonetics()).toBe('TF');
241
- });
242
-
243
- it('should tokenize and return string phonetics with string patch', function() {
244
- metaphone.attach();
245
- expect('phonetics'.tokenizeAndPhoneticize()).toEqual(['FNTKS']);
246
- expect('phonetics garbonzo'.tokenizeAndPhoneticize()).toEqual(['FNTKS', 'KRBNS']);
247
- expect('phonetics garbonzo lightning'.tokenizeAndPhoneticize()).toEqual(['FNTKS', 'KRBNS', 'LTNNK']);
248
- });
249
- */
250
-
251
- it('should truncate to length specified if code exceeds', function () {
252
- expect(metaphone.process('phonetics', 4)).toBe('FNTK')
253
- })
254
-
255
- it('should not truncate to length specified if code does not exceed', function () {
256
- expect(metaphone.process('phonetics', 8)).toBe('FNTKS')
257
- })
258
- })
@@ -1,145 +0,0 @@
1
- /*
2
- Copyright (c) 2019, Rob Ellis, Chris Umbel, Hugo W.L. ter Doest
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
- 'use strict'
24
-
25
- import { NGrams, AggressiveTokenizerFr, AggressiveTokenizer } from 'lib/natural'
26
- import text from '../spec/test_data/NYT-20150205-picassos-granddaughter-plans-to-sell-art-worrying-the-market.json'
27
-
28
- describe('ngrams', function () {
29
- it('should bigram a string via ngrams', function () {
30
- expect(NGrams.ngrams('these are some words', 2)).toEqual([['these', 'are'],
31
- ['are', 'some'], ['some', 'words']])
32
- })
33
-
34
- it('should bigram an array via ngrams', function () {
35
- expect(NGrams.ngrams(['these', 'are', 'some', 'words'], 2)).toEqual([['these', 'are'],
36
- ['are', 'some'], ['some', 'words']])
37
- })
38
-
39
- it('should trigram a string via ngrams', function () {
40
- expect(NGrams.ngrams('these are some words', 3)).toEqual([['these', 'are', 'some'],
41
- ['are', 'some', 'words']])
42
- })
43
-
44
- it('should trigram an array via ngrams', function () {
45
- expect(NGrams.ngrams(['these', 'are', 'some', 'words'], 3)).toEqual([['these', 'are', 'some'],
46
- ['are', 'some', 'words']])
47
- })
48
-
49
- describe('bigrams', function () {
50
- it('should bigram a string', function () {
51
- expect(NGrams.bigrams('these are some words')).toEqual([['these', 'are'],
52
- ['are', 'some'], ['some', 'words']])
53
- })
54
-
55
- it('should bigram an array', function () {
56
- expect(NGrams.bigrams(['these', 'are', 'some', 'words'])).toEqual([['these', 'are'],
57
- ['are', 'some'], ['some', 'words']])
58
- })
59
- })
60
-
61
- describe('trigrams', function () {
62
- it('should bigram a string', function () {
63
- expect(NGrams.trigrams('these are some words')).toEqual([['these', 'are', 'some'],
64
- ['are', 'some', 'words']])
65
- })
66
-
67
- it('should bigram an array', function () {
68
- expect(NGrams.trigrams(['these', 'are', 'some', 'words'])).toEqual([['these', 'are', 'some'],
69
- ['are', 'some', 'words']])
70
- })
71
- })
72
-
73
- // New Start/End Symbols Feature
74
- it('should bigram a string with start and end symbols', function () {
75
- expect(NGrams.ngrams('these are some words', 2, '[start]', '[end]')).toEqual([
76
- ['[start]', 'these'],
77
- ['these', 'are'],
78
- ['are', 'some'],
79
- ['some', 'words'],
80
- ['words', '[end]']
81
- ])
82
- })
83
-
84
- it('should bigram a string with start symbols only', function () {
85
- expect(NGrams.ngrams('these are some words', 2, '[start]')).toEqual([
86
- ['[start]', 'these'],
87
- ['these', 'are'],
88
- ['are', 'some'],
89
- ['some', 'words']
90
- ])
91
- })
92
-
93
- it('should bigram a string with end symbols only', function () {
94
- expect(NGrams.ngrams('these are some words', 2, null, '[end]')).toEqual([
95
- ['these', 'are'],
96
- ['are', 'some'],
97
- ['some', 'words'],
98
- ['words', '[end]']
99
- ])
100
- })
101
-
102
- it('should trigram a string with start and end symbols', function () {
103
- expect(NGrams.ngrams('these are some words', 3, '[start]', '[end]')).toEqual([
104
- ['[start]', '[start]', 'these'],
105
- ['[start]', 'these', 'are'],
106
- ['these', 'are', 'some'],
107
- ['are', 'some', 'words'],
108
- ['some', 'words', '[end]'],
109
- ['words', '[end]', '[end]']
110
- ])
111
- })
112
-
113
- it('should 4-gram a string with start and end symbols', function () {
114
- expect(NGrams.ngrams('these are some words', 4, '[start]', '[end]')).toEqual([
115
- ['[start]', '[start]', '[start]', 'these'],
116
- ['[start]', '[start]', 'these', 'are'],
117
- ['[start]', 'these', 'are', 'some'],
118
- ['these', 'are', 'some', 'words'],
119
- ['are', 'some', 'words', '[end]'],
120
- ['some', 'words', '[end]', '[end]'],
121
- ['words', '[end]', '[end]', '[end]']
122
- ])
123
- })
124
-
125
- it('should use french tokenizer', function () {
126
- const t = new AggressiveTokenizerFr()
127
- NGrams.setTokenizer(t)
128
- expect(NGrams.ngrams('Un Éléphant rouge', 2)).toEqual([['Un', 'Éléphant'],
129
- ['Éléphant', 'rouge']])
130
- })
131
-
132
- it('should trigram a string via ngrams including statistics', function () {
133
- const t = new AggressiveTokenizer()
134
- NGrams.setTokenizer(t)
135
- text.sentences.forEach(sentence => {
136
- const result = NGrams.ngrams(sentence, 3, null, null, true)
137
- let nrNgrams = 0
138
- Object.keys(result.Nr).forEach(function (f) {
139
- const n = parseInt(f, 10)
140
- nrNgrams += result.Nr[n] * n
141
- })
142
- expect(nrNgrams).toEqual(result.numberOfNgrams)
143
- })
144
- })
145
- })
@@ -1,124 +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
-
23
- 'use strict'
24
-
25
- import { NGramsZH } from 'lib/natural'
26
-
27
- describe('ngrams', function () {
28
- it('should bigram a string via ngrams', function () {
29
- expect(NGramsZH.ngrams('中文文本测试', 2)).toEqual([['中', '文'],
30
- ['文', '文'], ['文', '本'], ['本', '测'], ['测', '试']])
31
- })
32
-
33
- it('should bigram an array via ngrams', function () {
34
- expect(NGramsZH.ngrams(['中', '文', '文', '本', '测', '试'], 2)).toEqual([['中', '文'],
35
- ['文', '文'], ['文', '本'], ['本', '测'], ['测', '试']])
36
- })
37
-
38
- it('should trigram a string via ngrams', function () {
39
- expect(NGramsZH.ngrams('中文文本测试', 3)).toEqual([['中', '文', '文'],
40
- ['文', '文', '本'], ['文', '本', '测'], ['本', '测', '试']])
41
- })
42
-
43
- it('should trigram an array via ngrams', function () {
44
- expect(NGramsZH.ngrams(['中', '文', '文', '本', '测', '试'], 3)).toEqual([['中', '文', '文'],
45
- ['文', '文', '本'], ['文', '本', '测'], ['本', '测', '试']])
46
- })
47
-
48
- describe('bigrams', function () {
49
- it('should bigram a string', function () {
50
- expect(NGramsZH.bigrams('中文文本测试')).toEqual([['中', '文'],
51
- ['文', '文'], ['文', '本'], ['本', '测'], ['测', '试']])
52
- })
53
-
54
- it('should bigram an array', function () {
55
- expect(NGramsZH.bigrams(['中', '文', '文', '本', '测', '试'])).toEqual([['中', '文'],
56
- ['文', '文'], ['文', '本'], ['本', '测'], ['测', '试']])
57
- })
58
- })
59
-
60
- describe('trigrams', function () {
61
- /*
62
- it('should trigram a string', function () {
63
- expect(NGramsZH.ngrams('中文文本测试', 3)).toEqual([['中', '文', '文'],
64
- ['文', '文', '本'], ['文', '本', '测'], ['本', '测', '试']])
65
- })
66
- */
67
-
68
- it('should bigram an array', function () {
69
- expect(NGramsZH.ngrams(['中', '文', '文', '本', '测', '试'], 3)).toEqual([['中', '文', '文'],
70
- ['文', '文', '本'], ['文', '本', '测'], ['本', '测', '试']])
71
- })
72
- })
73
-
74
- it('should bigram a string with start and end symbols', function () {
75
- expect(NGramsZH.ngrams('中文测试', 2, '[start]', '[end]')).toEqual([
76
- ['[start]', '中'],
77
- ['中', '文'],
78
- ['文', '测'],
79
- ['测', '试'],
80
- ['试', '[end]']
81
- ])
82
- })
83
-
84
- it('should bigram a string with start symbols only', function () {
85
- expect(NGramsZH.ngrams('中文测试', 2, '[start]')).toEqual([
86
- ['[start]', '中'],
87
- ['中', '文'],
88
- ['文', '测'],
89
- ['测', '试']
90
- ])
91
- })
92
-
93
- it('should bigram a string with end symbols only', function () {
94
- expect(NGramsZH.ngrams('中文测试', 2, null, '[end]')).toEqual([
95
- ['中', '文'],
96
- ['文', '测'],
97
- ['测', '试'],
98
- ['试', '[end]']
99
- ])
100
- })
101
-
102
- it('should trigram a string with start and end symbols', function () {
103
- expect(NGramsZH.ngrams('中文测试', 3, '[start]', '[end]')).toEqual([
104
- ['[start]', '[start]', '中'],
105
- ['[start]', '中', '文'],
106
- ['中', '文', '测'],
107
- ['文', '测', '试'],
108
- ['测', '试', '[end]'],
109
- ['试', '[end]', '[end]']
110
- ])
111
- })
112
-
113
- it('should 4-gram a string with start and end symbols', function () {
114
- expect(NGramsZH.ngrams('中文测试', 4, '[start]', '[end]')).toEqual([
115
- ['[start]', '[start]', '[start]', '中'],
116
- ['[start]', '[start]', '中', '文'],
117
- ['[start]', '中', '文', '测'],
118
- ['中', '文', '测', '试'],
119
- ['文', '测', '试', '[end]'],
120
- ['测', '试', '[end]', '[end]'],
121
- ['试', '[end]', '[end]', '[end]']
122
- ])
123
- })
124
- })