natural 7.0.3 → 7.0.6
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.
- package/.github/workflows/npm-publish.yml +2 -0
- package/.nycrc +9 -0
- package/lib/natural/classifiers/logistic_regression_classifier.js +1 -1
- package/package.json +3 -4
- package/tsconfig.json +1 -1
- package/ts_spec/MaxEntClassifier_spec.ts +0 -130
- package/ts_spec/SentimentAnalyzer_spec.ts +0 -232
- package/ts_spec/WordPunctTokenizer_spec.ts +0 -57
- package/ts_spec/aggressive_tokenizer_de_spec.ts +0 -36
- package/ts_spec/aggressive_tokenizer_es_spec.ts +0 -39
- package/ts_spec/aggressive_tokenizer_fr_spec.ts +0 -111
- package/ts_spec/aggressive_tokenizer_hi_spec.ts +0 -70
- package/ts_spec/aggressive_tokenizer_nl_spec.ts +0 -39
- package/ts_spec/aggressive_tokenizer_pt_spec.ts +0 -48
- package/ts_spec/aggressive_tokenizer_spec.ts +0 -57
- package/ts_spec/aggressive_tokenizer_sv_spec.ts +0 -52
- package/ts_spec/aggressive_tokenizer_vi_spec.ts +0 -48
- package/ts_spec/bayes_classifier_spec.ts +0 -165
- package/ts_spec/brill_pos_tagger_spec.ts +0 -79
- package/ts_spec/brill_pos_trainer_spec.ts +0 -107
- package/ts_spec/carry_stemmer_fr_spec.ts +0 -97
- package/ts_spec/classifier_spec.ts +0 -104
- package/ts_spec/count_inflector_fr_spec.ts +0 -47
- package/ts_spec/count_inflector_spec.ts +0 -76
- package/ts_spec/damerau_levenshtein_spec.ts +0 -53
- package/ts_spec/dice_coefficient_spec.ts +0 -37
- package/ts_spec/double_metaphone_spec.ts +0 -739
- package/ts_spec/hamming_distance_spec.ts +0 -66
- package/ts_spec/jaro-winkler_spec.ts +0 -79
- package/ts_spec/lancaster_stemmer_spec.ts +0 -63
- package/ts_spec/levenshtein_spec.ts +0 -107
- package/ts_spec/logistic_regression_classifier_spec.ts +0 -93
- package/ts_spec/longest_path_tree_spec.ts +0 -111
- package/ts_spec/metaphone_spec.ts +0 -258
- package/ts_spec/ngram_spec.ts +0 -145
- package/ts_spec/ngram_zh_spec.ts +0 -124
- package/ts_spec/normalizer_ja_spec.ts +0 -165
- package/ts_spec/normalizer_no_spec.ts +0 -112
- package/ts_spec/normalizer_spec.ts +0 -141
- package/ts_spec/noun_inflector_fr_spec.ts +0 -472
- package/ts_spec/noun_inflector_ja_spec.ts +0 -116
- package/ts_spec/noun_inflector_spec.ts +0 -369
- package/ts_spec/orthography_tokenizer_spec.ts +0 -47
- package/ts_spec/porter_stemmer_de_spec.ts +0 -53
- package/ts_spec/porter_stemmer_es_spec.ts +0 -63
- package/ts_spec/porter_stemmer_fr_spec.ts +0 -103
- package/ts_spec/porter_stemmer_it_spec.ts +0 -56
- package/ts_spec/porter_stemmer_nl_spec.ts +0 -73
- package/ts_spec/porter_stemmer_no_spec.ts +0 -148
- package/ts_spec/porter_stemmer_pt_spec.ts +0 -50
- package/ts_spec/porter_stemmer_ru_spec.ts +0 -67
- package/ts_spec/porter_stemmer_spec.ts +0 -202
- package/ts_spec/porter_stemmer_sv_spec.ts +0 -41
- package/ts_spec/present_verb_inflector_spec.ts +0 -127
- package/ts_spec/remove_diacritics_spec.ts +0 -30
- package/ts_spec/sentence_analyzer_spec.ts +0 -293
- package/ts_spec/sentence_tokenizer_parser_spec.ts +0 -200
- package/ts_spec/sentence_tokenizer_spec.ts +0 -189
- package/ts_spec/shortest_path_tree_spec.ts +0 -141
- package/ts_spec/soundex_spec.ts +0 -162
- package/ts_spec/spellcheck_spec.ts +0 -112
- package/ts_spec/stemmer_id_spec.ts +0 -374
- package/ts_spec/stemmer_ja_spec.ts +0 -69
- package/ts_spec/stemmer_token_spec.ts +0 -163
- package/ts_spec/tfidf_spec.ts +0 -275
- package/ts_spec/tokenizer_case_spec.ts +0 -242
- package/ts_spec/tokenizer_ja_spec.ts +0 -63
- package/ts_spec/transliterator_ja_spec.ts +0 -105
- package/ts_spec/treebank_word_tokenizer_spec.ts +0 -38
- package/ts_spec/trie_spec.ts +0 -197
|
@@ -1,739 +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 { DoubleMetaphone } from 'lib/natural'
|
|
26
|
-
const doubleMetaphone = new DoubleMetaphone()
|
|
27
|
-
|
|
28
|
-
describe('double metaphone', function () {
|
|
29
|
-
describe('vowels', function () {
|
|
30
|
-
it('should consider initial vowels to be A', function () {
|
|
31
|
-
let encodings = doubleMetaphone.process('England')
|
|
32
|
-
expect(encodings[0]).toMatch(/^A/)
|
|
33
|
-
expect(encodings[1]).toMatch(/^A/)
|
|
34
|
-
|
|
35
|
-
encodings = doubleMetaphone.process('astromech')
|
|
36
|
-
expect(encodings[0]).toMatch(/^A/)
|
|
37
|
-
expect(encodings[1]).toMatch(/^A/)
|
|
38
|
-
|
|
39
|
-
encodings = doubleMetaphone.process('être')
|
|
40
|
-
expect(encodings[0]).toMatch(/^A/)
|
|
41
|
-
expect(encodings[1]).toMatch(/^A/)
|
|
42
|
-
|
|
43
|
-
encodings = doubleMetaphone.process('éte')
|
|
44
|
-
expect(encodings[0]).toMatch(/^A/)
|
|
45
|
-
expect(encodings[1]).toMatch(/^A/)
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
describe('B', function () {
|
|
50
|
-
it('should encode B to P', function () {
|
|
51
|
-
const encodings = doubleMetaphone.process('berry')
|
|
52
|
-
expect(encodings[0]).toMatch(/^P/)
|
|
53
|
-
expect(encodings[1]).toMatch(/^P/)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('should encode BB to P', function () {
|
|
57
|
-
const encodings = doubleMetaphone.process('tabby')
|
|
58
|
-
expect(encodings[0]).toContain('P')
|
|
59
|
-
expect(encodings[0]).not.toContain('PP')
|
|
60
|
-
expect(encodings[0]).not.toContain('PB')
|
|
61
|
-
expect(encodings[1]).toContain('P')
|
|
62
|
-
expect(encodings[1]).not.toContain('PP')
|
|
63
|
-
expect(encodings[1]).not.toContain('PB')
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
describe('C', function () {
|
|
68
|
-
it("should encode MACHER's C to K", function () {
|
|
69
|
-
const encodings = doubleMetaphone.process('stomacher')
|
|
70
|
-
expect(encodings[0]).toContain('K')
|
|
71
|
-
expect(encodings[1]).toContain('K')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it("should encode CEASAR's C to S", function () {
|
|
75
|
-
const encodings = doubleMetaphone.process('ceasar')
|
|
76
|
-
expect(encodings[0]).toMatch(/^S/)
|
|
77
|
-
expect(encodings[1]).toMatch(/S/)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it("should encode chianti's C to K", function () {
|
|
81
|
-
const encodings = doubleMetaphone.process('chianti')
|
|
82
|
-
expect(encodings[0]).toMatch(/^K/)
|
|
83
|
-
expect(encodings[1]).toMatch(/^K/)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('should encode CHAE to K,X', function () {
|
|
87
|
-
const encodings = doubleMetaphone.process('archaeology')
|
|
88
|
-
expect(encodings[0]).toContain('K')
|
|
89
|
-
expect(encodings[1]).toContain('X')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('should encode CHarac to K', function () {
|
|
93
|
-
const encodings = doubleMetaphone.process('character')
|
|
94
|
-
expect(encodings[0]).toMatch(/^K/)
|
|
95
|
-
expect(encodings[1]).toMatch(/^K/)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('should encode C after von to K', function () {
|
|
99
|
-
const encodings = doubleMetaphone.process('von Chor')
|
|
100
|
-
expect(encodings[0]).toMatch(/^..K/)
|
|
101
|
-
expect(encodings[1]).toMatch(/^..K/)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('should encode some CH to K', function () {
|
|
105
|
-
const encodings = doubleMetaphone.process('orchestrational')
|
|
106
|
-
expect(encodings[0]).toMatch(/^..K/)
|
|
107
|
-
expect(encodings[1]).toMatch(/^..K/)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('should encode CH before some cons as K', function () {
|
|
111
|
-
const encodings = doubleMetaphone.process('chthonic')
|
|
112
|
-
expect(encodings[0]).toMatch(/^K/)
|
|
113
|
-
expect(encodings[1]).toMatch(/^K/)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('should encode Irish mC to K', function () {
|
|
117
|
-
const encodings = doubleMetaphone.process('McHenry')
|
|
118
|
-
expect(encodings[0]).toMatch(/^.K/)
|
|
119
|
-
expect(encodings[1]).toMatch(/^.K/)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('should encode CH to X,K generally', function () {
|
|
123
|
-
const encodings = doubleMetaphone.process('achievement')
|
|
124
|
-
expect(encodings[0]).toMatch(/^.X/)
|
|
125
|
-
expect(encodings[1]).toMatch(/^.K/)
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('shoud encode Polish WICZ to S,X', function () {
|
|
129
|
-
const encodings = doubleMetaphone.process('markiewicz')
|
|
130
|
-
expect(encodings[0]).toMatch(/S$/)
|
|
131
|
-
expect(encodings[1]).toMatch(/X$/)
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('should encode CIA to X', function () {
|
|
135
|
-
const encodings = doubleMetaphone.process('indicia')
|
|
136
|
-
expect(encodings[0]).toMatch(/X$/)
|
|
137
|
-
expect(encodings[1]).toMatch(/X$/)
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('should encode Italian CCI to X', function () {
|
|
141
|
-
const encodings = doubleMetaphone.process('bacci')
|
|
142
|
-
expect(encodings[0]).toContain('X')
|
|
143
|
-
expect(encodings[1]).toContain('X')
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('should encode some CCes to K', function () {
|
|
147
|
-
const encodings = doubleMetaphone.process('success')
|
|
148
|
-
expect(encodings[0]).toMatch(/^SKS/)
|
|
149
|
-
expect(encodings[1]).toMatch(/^SKS/)
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it('should encode some CC to K', function () {
|
|
153
|
-
const encodings = doubleMetaphone.process('yucca')
|
|
154
|
-
expect(encodings[0]).toMatch(/K$/)
|
|
155
|
-
expect(encodings[1]).toMatch(/K$/)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
it('should encode CQ to K', function () {
|
|
159
|
-
const encodings = doubleMetaphone.process('racquetball')
|
|
160
|
-
expect(encodings[0]).toMatch(/^.K/)
|
|
161
|
-
expect(encodings[1]).toMatch(/^.K/)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('should encode CIO to S,X', function () {
|
|
165
|
-
const encodings = doubleMetaphone.process('sociopath')
|
|
166
|
-
expect(encodings[0]).toMatch(/^.S/)
|
|
167
|
-
expect(encodings[1]).toMatch(/^.X/)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('should encode CI to S', function () {
|
|
171
|
-
const encodings = doubleMetaphone.process('city')
|
|
172
|
-
expect(encodings[0]).toMatch(/^S/)
|
|
173
|
-
expect(encodings[1]).toMatch(/^S/)
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
it('should encode Scotch maC to K', function () {
|
|
177
|
-
const encodings = doubleMetaphone.process('Mac Ghille dhuibh')
|
|
178
|
-
expect(encodings[0]).toMatch(/^MK/)
|
|
179
|
-
expect(encodings[1]).toMatch(/^MK/)
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
describe('Ç', function () {
|
|
184
|
-
it('should encode case Ç (French) to S', function () {
|
|
185
|
-
const encodings = doubleMetaphone.process('leçon')
|
|
186
|
-
expect(encodings[0]).toContain('S')
|
|
187
|
-
expect(encodings[1]).toContain('S')
|
|
188
|
-
})
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
describe('D', function () {
|
|
192
|
-
it('should encode D to T', function () {
|
|
193
|
-
const encodings = doubleMetaphone.process('double')
|
|
194
|
-
expect(encodings[0]).toMatch(/^T/)
|
|
195
|
-
expect(encodings[1]).toMatch(/^T/)
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
it('should encode DD to T', function () {
|
|
199
|
-
const encodings = doubleMetaphone.process('fiddle')
|
|
200
|
-
expect(encodings[0]).toContain('T')
|
|
201
|
-
expect(encodings[0]).not.toContain('TT')
|
|
202
|
-
expect(encodings[0]).not.toContain('D')
|
|
203
|
-
|
|
204
|
-
expect(encodings[1]).toContain('T')
|
|
205
|
-
expect(encodings[1]).not.toContain('TT')
|
|
206
|
-
expect(encodings[1]).not.toContain('D')
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
it('should encode DG to J', function () {
|
|
210
|
-
const encodings = doubleMetaphone.process('ledge')
|
|
211
|
-
expect(encodings[0]).toContain('J')
|
|
212
|
-
expect(encodings[0]).not.toContain('T')
|
|
213
|
-
expect(encodings[1]).toContain('J')
|
|
214
|
-
expect(encodings[1]).not.toContain('T')
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
it('should encode DT to T', function () {
|
|
218
|
-
const encodings = doubleMetaphone.process('bundt')
|
|
219
|
-
expect(encodings[0]).toMatch(/[^D]T$/)
|
|
220
|
-
expect(encodings[1]).toMatch(/[^D]T$/)
|
|
221
|
-
})
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
describe('F', function () {
|
|
225
|
-
it('should encode F', function () {
|
|
226
|
-
const encodings = doubleMetaphone.process('far')
|
|
227
|
-
expect(encodings[0]).toContain('F')
|
|
228
|
-
expect(encodings[1]).toContain('F')
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
it('should encode FF to F', function () {
|
|
232
|
-
const encodings = doubleMetaphone.process('effect')
|
|
233
|
-
expect(encodings[0]).toContain('F')
|
|
234
|
-
expect(encodings[0]).not.toContain('FF')
|
|
235
|
-
expect(encodings[1]).toContain('F')
|
|
236
|
-
expect(encodings[1]).not.toContain('FF')
|
|
237
|
-
})
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
describe('G', function () {
|
|
241
|
-
it('should encode G to F following U and 4 after certain cons', function () {
|
|
242
|
-
const encodings = doubleMetaphone.process('tough')
|
|
243
|
-
expect(encodings[0]).toMatch('F$')
|
|
244
|
-
expect(encodings[1]).toMatch('F$')
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
it('should encode G to K', function () {
|
|
248
|
-
const encodings = doubleMetaphone.process('gift')
|
|
249
|
-
expect(encodings[0]).toMatch('^K')
|
|
250
|
-
expect(encodings[1]).toMatch('^K')
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
it('should ignore G a few letters after D, H, B', function () {
|
|
254
|
-
const encodings = doubleMetaphone.process('fig')
|
|
255
|
-
expect(encodings[0]).toMatch('K$')
|
|
256
|
-
expect(encodings[1]).toMatch('K$')
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
it('should ignore G a few letters after D, H, B', function () {
|
|
260
|
-
const encodings = doubleMetaphone.process('hugh')
|
|
261
|
-
expect(encodings[0]).toBe('H')
|
|
262
|
-
expect(encodings[1]).toBe('H')
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
it('should encode G to J when staring a word whose 3rd legger is I', function () {
|
|
266
|
-
const encodings = doubleMetaphone.process('ghislaine')
|
|
267
|
-
expect(encodings[0]).toMatch(/^J/)
|
|
268
|
-
expect(encodings[1]).toMatch(/^J/)
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
it('should encode G to K when staring words whose 3rd letter is not I', function () {
|
|
272
|
-
const encodings = doubleMetaphone.process('consign')
|
|
273
|
-
expect(encodings[0]).toMatch(/N$/)
|
|
274
|
-
expect(encodings[1]).toMatch(/KN$/)
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
it('should encode GH to K if not succeeding a cons', function () {
|
|
278
|
-
const encodings = doubleMetaphone.process('Afghani')
|
|
279
|
-
expect(encodings[0]).toContain('K')
|
|
280
|
-
expect(encodings[1]).toContain('K')
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
it('should encode GN to N/KN generally', function () {
|
|
284
|
-
const encodings = doubleMetaphone.process('consign')
|
|
285
|
-
expect(encodings[0]).toMatch(/N$/)
|
|
286
|
-
expect(encodings[1]).toMatch(/KN$/)
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
it('should encode G to KN/N for the second letter following vowels', function () {
|
|
290
|
-
const encodings = doubleMetaphone.process('agnosia')
|
|
291
|
-
expect(encodings[0]).toMatch(/^.KN/)
|
|
292
|
-
expect(encodings[1]).toMatch(/^.N/)
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
it('should encode G to K,J when starting some words', function () {
|
|
296
|
-
const encodings = doubleMetaphone.process('germany')
|
|
297
|
-
expect(encodings[0]).toMatch(/^K/)
|
|
298
|
-
expect(encodings[1]).toMatch(/^J/)
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
it('should encode GL to KL, L', function () {
|
|
302
|
-
const encodings = doubleMetaphone.process('taglianetti')
|
|
303
|
-
expect(encodings[0]).toMatch(/KL/)
|
|
304
|
-
expect(encodings[1]).toMatch(/[^K]L/)
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
it('should encode GG to K', function () {
|
|
308
|
-
const encodings = doubleMetaphone.process('daggers')
|
|
309
|
-
expect(encodings[0]).toContain('K')
|
|
310
|
-
expect(encodings[0]).not.toContain('KK')
|
|
311
|
-
expect(encodings[1]).toContain('K')
|
|
312
|
-
expect(encodings[1]).not.toContain('KK')
|
|
313
|
-
})
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
describe('H', function () {
|
|
317
|
-
it('should keep initial Hs', function () {
|
|
318
|
-
const encodings = doubleMetaphone.process('hardly')
|
|
319
|
-
expect(encodings[0]).toMatch(/^H/)
|
|
320
|
-
expect(encodings[1]).toMatch(/^H/)
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
it('should keep Hs between vowels', function () {
|
|
324
|
-
const encodings = doubleMetaphone.process('ahoi')
|
|
325
|
-
expect(encodings[0]).toContain('H')
|
|
326
|
-
expect(encodings[1]).toContain('H')
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
it('should drop Hs in words if not surrounded by vowels or starting', function () {
|
|
330
|
-
const encodings = doubleMetaphone.process('charlie')
|
|
331
|
-
expect(encodings[0]).not.toContain('H')
|
|
332
|
-
expect(encodings[1]).not.toContain('H')
|
|
333
|
-
})
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
describe('J', function () {
|
|
337
|
-
it('should encode spainish Js to Hs in the middle of words', function () {
|
|
338
|
-
const encodings = doubleMetaphone.process('bajador')
|
|
339
|
-
expect(encodings[0]).toMatch(/^.J/)
|
|
340
|
-
expect(encodings[1]).toMatch(/^.H/)
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
it('should encode J to J,A', function () {
|
|
344
|
-
const encodings = doubleMetaphone.process('jumble')
|
|
345
|
-
expect(encodings[0]).toMatch(/^J/)
|
|
346
|
-
expect(encodings[1]).toMatch(/^A/)
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
it('should encode J to J," " at the end of words', function () {
|
|
350
|
-
const encodings = doubleMetaphone.process('hadj')
|
|
351
|
-
expect(encodings[0]).toMatch(/J$/)
|
|
352
|
-
expect(encodings[1]).toMatch(/\s$/)
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
it('should encode JJ to J', function () {
|
|
356
|
-
const encodings = doubleMetaphone.process('hajj')
|
|
357
|
-
expect(encodings[0]).toMatch(/J$/)
|
|
358
|
-
expect(encodings[1]).toMatch(/J$/)
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
it('should encode J to H in saint names (cities)', function () {
|
|
362
|
-
const encodings = doubleMetaphone.process('san juan')
|
|
363
|
-
expect(encodings[0]).toContain('H')
|
|
364
|
-
expect(encodings[1]).toContain('H')
|
|
365
|
-
})
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
describe('L', function () {
|
|
369
|
-
it('should encode L', function () {
|
|
370
|
-
const encodings = doubleMetaphone.process('last')
|
|
371
|
-
expect(encodings[0]).toMatch(/^L/)
|
|
372
|
-
expect(encodings[1]).toMatch(/^L/)
|
|
373
|
-
})
|
|
374
|
-
|
|
375
|
-
it('should encode L to LL', function () {
|
|
376
|
-
const encodings = doubleMetaphone.process('functionally')
|
|
377
|
-
expect(encodings[0]).toContain('L')
|
|
378
|
-
expect(encodings[0]).not.toContain('LL')
|
|
379
|
-
expect(encodings[1]).toContain('L')
|
|
380
|
-
expect(encodings[1]).not.toContain('LL')
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
it('should encode ignore spainish-style LL entirely in secondary', function () {
|
|
384
|
-
const encodings = doubleMetaphone.process('cabrillo')
|
|
385
|
-
expect(encodings[0]).toContain('L')
|
|
386
|
-
expect(encodings[1]).not.toContain('LL')
|
|
387
|
-
})
|
|
388
|
-
})
|
|
389
|
-
|
|
390
|
-
describe('M', function () {
|
|
391
|
-
it('should encode M', function () {
|
|
392
|
-
const encodings = doubleMetaphone.process('meter')
|
|
393
|
-
expect(encodings[0]).toMatch(/^M/)
|
|
394
|
-
// expect(encodings[1]).not.toContain(/^M/)
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
it('should skip B after M', function () {
|
|
398
|
-
const encodings = doubleMetaphone.process('thumb')
|
|
399
|
-
expect(encodings[0]).toMatch(/M$/)
|
|
400
|
-
// expect(encodings[1]).not.toContain(/M$/)
|
|
401
|
-
})
|
|
402
|
-
})
|
|
403
|
-
|
|
404
|
-
describe('N', function () {
|
|
405
|
-
it('should encode Ns', function () {
|
|
406
|
-
const encodings = doubleMetaphone.process('natural')
|
|
407
|
-
expect(encodings[0]).toContain('N')
|
|
408
|
-
expect(encodings[1]).toContain('N')
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
it('should encode NN to N', function () {
|
|
412
|
-
const encodings = doubleMetaphone.process('fanny')
|
|
413
|
-
expect(encodings[0]).toContain('N')
|
|
414
|
-
expect(encodings[1]).toContain('N')
|
|
415
|
-
|
|
416
|
-
expect(encodings[0]).not.toContain('NN')
|
|
417
|
-
expect(encodings[1]).not.toContain('NN')
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
it('should treat a spainish Ñ as a N', function () {
|
|
421
|
-
const encodings = doubleMetaphone.process('jalapeño')
|
|
422
|
-
expect(encodings[0]).toContain('N')
|
|
423
|
-
expect(encodings[1]).toContain('N')
|
|
424
|
-
})
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
describe('P', function () {
|
|
428
|
-
it('should encode PH to F', function () {
|
|
429
|
-
const encodings = doubleMetaphone.process('phone')
|
|
430
|
-
expect(encodings[0]).toMatch(/^F/)
|
|
431
|
-
expect(encodings[1]).toMatch(/^F/)
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
it('should encode P', function () {
|
|
435
|
-
const encodings = doubleMetaphone.process('party')
|
|
436
|
-
expect(encodings[0]).toContain('P')
|
|
437
|
-
expect(encodings[1]).toContain('P')
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
it('should encode PP to P', function () {
|
|
441
|
-
const encodings = doubleMetaphone.process('sappy')
|
|
442
|
-
expect(encodings[0]).toContain('P')
|
|
443
|
-
expect(encodings[0]).not.toContain('PP')
|
|
444
|
-
expect(encodings[1]).toContain('P')
|
|
445
|
-
expect(encodings[1]).not.toContain('PP')
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
/* jscpd:ignore-start */
|
|
449
|
-
it('should skip P before B i.e. raspberry', function () {
|
|
450
|
-
const encodings = doubleMetaphone.process('raspberry')
|
|
451
|
-
expect(encodings[0]).toContain('P')
|
|
452
|
-
expect(encodings[0]).not.toContain('PP')
|
|
453
|
-
expect(encodings[0]).not.toContain('PB')
|
|
454
|
-
expect(encodings[1]).toContain('P')
|
|
455
|
-
expect(encodings[1]).not.toContain('PP')
|
|
456
|
-
expect(encodings[1]).not.toContain('PB')
|
|
457
|
-
})
|
|
458
|
-
/* jscpd:ignore-end */
|
|
459
|
-
})
|
|
460
|
-
|
|
461
|
-
describe('Q', function () {
|
|
462
|
-
it('should encode Q to K', function () {
|
|
463
|
-
const encodings = doubleMetaphone.process('quarry')
|
|
464
|
-
expect(encodings[0]).toContain('K')
|
|
465
|
-
expect(encodings[1]).toContain('K')
|
|
466
|
-
})
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
describe('R', function () {
|
|
470
|
-
it('should encode R', function () {
|
|
471
|
-
const encodings = doubleMetaphone.process('raspberry')
|
|
472
|
-
expect(encodings[0]).toMatch(/^R/)
|
|
473
|
-
expect(encodings[1]).toMatch(/^R/)
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
it('should ignore trailing French Rs', function () {
|
|
477
|
-
const encodings = doubleMetaphone.process('papier')
|
|
478
|
-
expect(encodings[0]).toMatch(/[^R]$/)
|
|
479
|
-
expect(encodings[1]).toMatch(/R$/)
|
|
480
|
-
})
|
|
481
|
-
})
|
|
482
|
-
|
|
483
|
-
describe('S', function () {
|
|
484
|
-
it('should skip S between I and L', function () {
|
|
485
|
-
const encodings = doubleMetaphone.process('isle')
|
|
486
|
-
expect(encodings[0]).toMatch(/^AL/)
|
|
487
|
-
expect(encodings[1]).toMatch(/^AL/)
|
|
488
|
-
})
|
|
489
|
-
|
|
490
|
-
it("should encode sugar's S to X", function () {
|
|
491
|
-
const encodings = doubleMetaphone.process('sugar')
|
|
492
|
-
expect(encodings[0]).toMatch(/^X/)
|
|
493
|
-
expect(encodings[1]).toMatch(/^S/)
|
|
494
|
-
})
|
|
495
|
-
|
|
496
|
-
it('should encode general SH to X', function () {
|
|
497
|
-
const encodings = doubleMetaphone.process('share')
|
|
498
|
-
expect(encodings[0]).toMatch(/^X/)
|
|
499
|
-
expect(encodings[1]).toMatch(/^X/)
|
|
500
|
-
})
|
|
501
|
-
|
|
502
|
-
it('should encode certain germanic SHs to S', function () {
|
|
503
|
-
const encodings = doubleMetaphone.process('Sholmer')
|
|
504
|
-
expect(encodings[0]).toMatch(/^S/)
|
|
505
|
-
expect(encodings[1]).toMatch(/^S/)
|
|
506
|
-
})
|
|
507
|
-
|
|
508
|
-
it('should encode SION to S,X generally', function () {
|
|
509
|
-
const encodings = doubleMetaphone.process('tension')
|
|
510
|
-
expect(encodings[0]).toContain('S')
|
|
511
|
-
expect(encodings[1]).toContain('X')
|
|
512
|
-
})
|
|
513
|
-
|
|
514
|
-
it('should encode SCHool to SK', function () {
|
|
515
|
-
const encodings = doubleMetaphone.process('school')
|
|
516
|
-
expect(encodings[0]).toMatch(/^SK/)
|
|
517
|
-
expect(encodings[1]).toMatch(/^SK/)
|
|
518
|
-
})
|
|
519
|
-
|
|
520
|
-
it('should encode SCHER to X,SK', function () {
|
|
521
|
-
const encodings = doubleMetaphone.process('scherzando')
|
|
522
|
-
expect(encodings[0]).toMatch(/^X/)
|
|
523
|
-
expect(encodings[1]).toMatch(/^SK/)
|
|
524
|
-
})
|
|
525
|
-
|
|
526
|
-
it('should encode SCHL to X,S', function () {
|
|
527
|
-
const encodings = doubleMetaphone.process('schlump')
|
|
528
|
-
expect(encodings[0]).toMatch(/^X/)
|
|
529
|
-
expect(encodings[1]).toMatch(/^S/)
|
|
530
|
-
})
|
|
531
|
-
|
|
532
|
-
it('should encode SC to SK generally', function () {
|
|
533
|
-
const encodings = doubleMetaphone.process('scumbag')
|
|
534
|
-
expect(encodings[0]).toMatch(/^SK/)
|
|
535
|
-
expect(encodings[1]).toMatch(/^SK/)
|
|
536
|
-
})
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
describe('T', function () {
|
|
540
|
-
it('should encode TION to XN', function () {
|
|
541
|
-
const encodings = doubleMetaphone.process('nation')
|
|
542
|
-
expect(encodings[0]).toMatch(/XN$/)
|
|
543
|
-
expect(encodings[1]).toMatch(/XN$/)
|
|
544
|
-
})
|
|
545
|
-
|
|
546
|
-
it('should encode CH sounds to X', function () {
|
|
547
|
-
const encodings = doubleMetaphone.process('thatch')
|
|
548
|
-
expect(encodings[0]).toMatch(/X$/)
|
|
549
|
-
expect(encodings[1]).toMatch(/X$/)
|
|
550
|
-
})
|
|
551
|
-
|
|
552
|
-
it('should encode hard TH to T', function () {
|
|
553
|
-
const encodings = doubleMetaphone.process('thomas')
|
|
554
|
-
expect(encodings[0]).toMatch(/^T/)
|
|
555
|
-
expect(encodings[1]).toMatch(/^T/)
|
|
556
|
-
})
|
|
557
|
-
|
|
558
|
-
it('should encode soft TH to 0,T', function () {
|
|
559
|
-
const encodings = doubleMetaphone.process('this')
|
|
560
|
-
expect(encodings[0]).toMatch(/^0/)
|
|
561
|
-
expect(encodings[1]).toMatch(/^T/)
|
|
562
|
-
})
|
|
563
|
-
|
|
564
|
-
it('should encode TT to T', function () {
|
|
565
|
-
const encodings = doubleMetaphone.process('matta')
|
|
566
|
-
expect(encodings[0]).toMatch(/[^T]T/)
|
|
567
|
-
expect(encodings[1]).toMatch(/[^T]T/)
|
|
568
|
-
})
|
|
569
|
-
|
|
570
|
-
it('should encode TD to T', function () {
|
|
571
|
-
const encodings = doubleMetaphone.process('countdown')
|
|
572
|
-
expect(encodings[0]).toContain('T')
|
|
573
|
-
expect(encodings[0]).not.toContain('D')
|
|
574
|
-
expect(encodings[1]).toContain('T')
|
|
575
|
-
expect(encodings[1]).not.toContain('D')
|
|
576
|
-
})
|
|
577
|
-
})
|
|
578
|
-
|
|
579
|
-
describe('V', function () {
|
|
580
|
-
it('should encode V to F', function () {
|
|
581
|
-
const encodings = doubleMetaphone.process('very')
|
|
582
|
-
expect(encodings[0]).toContain('F')
|
|
583
|
-
expect(encodings[1]).toContain('F')
|
|
584
|
-
})
|
|
585
|
-
|
|
586
|
-
it('should encode VV to F', function () {
|
|
587
|
-
const encodings = doubleMetaphone.process('savvy')
|
|
588
|
-
expect(encodings[0]).toContain('F')
|
|
589
|
-
expect(encodings[0]).not.toContain('FF')
|
|
590
|
-
expect(encodings[0]).not.toContain('FV')
|
|
591
|
-
expect(encodings[1]).toContain('F')
|
|
592
|
-
expect(encodings[1]).not.toContain('FF')
|
|
593
|
-
expect(encodings[1]).not.toContain('FV')
|
|
594
|
-
})
|
|
595
|
-
})
|
|
596
|
-
|
|
597
|
-
describe('W', function () {
|
|
598
|
-
it('should encode WR to R', function () {
|
|
599
|
-
const encodings = doubleMetaphone.process('wrong')
|
|
600
|
-
expect(encodings[0]).toMatch('^R')
|
|
601
|
-
expect(encodings[1]).toMatch('^R')
|
|
602
|
-
})
|
|
603
|
-
|
|
604
|
-
it('should encode WH to A at the start of a word', function () {
|
|
605
|
-
const encodings = doubleMetaphone.process('wheat')
|
|
606
|
-
expect(encodings[0]).toMatch('^A')
|
|
607
|
-
expect(encodings[1]).toMatch('^A')
|
|
608
|
-
})
|
|
609
|
-
|
|
610
|
-
it('should encode WH to A,F if followed by a vowel at start', function () {
|
|
611
|
-
const encodings = doubleMetaphone.process('wolfgang')
|
|
612
|
-
expect(encodings[0]).toMatch('^A')
|
|
613
|
-
expect(encodings[1]).toMatch('^F')
|
|
614
|
-
})
|
|
615
|
-
|
|
616
|
-
it('should encode OWSKY alternately to F(V)', function () {
|
|
617
|
-
const encodings = doubleMetaphone.process('lebowski')
|
|
618
|
-
expect(encodings[0]).not.toContain('F')
|
|
619
|
-
expect(encodings[1]).toContain('F')
|
|
620
|
-
})
|
|
621
|
-
|
|
622
|
-
it('should encode WICZ', function () {
|
|
623
|
-
const encodings = doubleMetaphone.process('Lowicz')
|
|
624
|
-
expect(encodings[0]).toMatch('TS$')
|
|
625
|
-
expect(encodings[1]).toMatch('FX$')
|
|
626
|
-
})
|
|
627
|
-
})
|
|
628
|
-
|
|
629
|
-
describe('X', function () {
|
|
630
|
-
it('should encode X as S at start', function () {
|
|
631
|
-
const encodings = doubleMetaphone.process('xenophobia')
|
|
632
|
-
expect(encodings[0]).toMatch(/^S/)
|
|
633
|
-
expect(encodings[1]).toMatch(/^S/)
|
|
634
|
-
})
|
|
635
|
-
|
|
636
|
-
it('should encode X as KS at end for non-French words', function () {
|
|
637
|
-
const encodings = doubleMetaphone.process('box')
|
|
638
|
-
expect(encodings[0]).toMatch(/KS$/)
|
|
639
|
-
expect(encodings[1]).toMatch(/KS$/)
|
|
640
|
-
})
|
|
641
|
-
|
|
642
|
-
it('should skip X end for French words', function () {
|
|
643
|
-
const encodings = doubleMetaphone.process('lemieux')
|
|
644
|
-
expect(encodings[0]).not.toMatch(/KS$/)
|
|
645
|
-
expect(encodings[1]).not.toMatch(/KS$/)
|
|
646
|
-
})
|
|
647
|
-
})
|
|
648
|
-
|
|
649
|
-
describe('Z', function () {
|
|
650
|
-
it('should encode Z to S', function () {
|
|
651
|
-
const encodings = doubleMetaphone.process('zookeeper')
|
|
652
|
-
expect(encodings[0]).toMatch(/^S/)
|
|
653
|
-
expect(encodings[1]).toMatch(/^S/)
|
|
654
|
-
})
|
|
655
|
-
|
|
656
|
-
it('should encode Chinese ZH to J', function () {
|
|
657
|
-
const encodings = doubleMetaphone.process('zheng')
|
|
658
|
-
expect(encodings[0]).toMatch(/^J/)
|
|
659
|
-
expect(encodings[1]).toMatch(/^J/)
|
|
660
|
-
})
|
|
661
|
-
|
|
662
|
-
it('should encode ZZA to S, TS', function () {
|
|
663
|
-
const encodings = doubleMetaphone.process('pizza')
|
|
664
|
-
expect(encodings[0]).toContain('S')
|
|
665
|
-
expect(encodings[1]).toContain('TS')
|
|
666
|
-
})
|
|
667
|
-
})
|
|
668
|
-
|
|
669
|
-
describe('general', function () {
|
|
670
|
-
it('should detect vowels', function () {
|
|
671
|
-
expect(doubleMetaphone.isVowel('a')).toBeTruthy()
|
|
672
|
-
expect(doubleMetaphone.isVowel('e')).toBeTruthy()
|
|
673
|
-
expect(doubleMetaphone.isVowel('b')).toBeFalsy()
|
|
674
|
-
})
|
|
675
|
-
|
|
676
|
-
it('should encode general words', function () {
|
|
677
|
-
let encodings = doubleMetaphone.process('complete')
|
|
678
|
-
expect(encodings[0]).toMatch(/KMPLT/)
|
|
679
|
-
expect(encodings[1]).toMatch(/KMPLT/)
|
|
680
|
-
|
|
681
|
-
encodings = doubleMetaphone.process('Matrix')
|
|
682
|
-
expect(encodings[0]).toMatch(/MTRKS/)
|
|
683
|
-
expect(encodings[1]).toMatch(/MTRKS/)
|
|
684
|
-
|
|
685
|
-
encodings = doubleMetaphone.process('appropriate')
|
|
686
|
-
expect(encodings[0]).toMatch(/APRPRT/)
|
|
687
|
-
expect(encodings[1]).toMatch(/APRPRT/)
|
|
688
|
-
|
|
689
|
-
encodings = doubleMetaphone.process('intervention')
|
|
690
|
-
|
|
691
|
-
expect(encodings[0]).toBe('ANTRFNXN')
|
|
692
|
-
expect(encodings[1]).toBe('ANTRFNXN')
|
|
693
|
-
|
|
694
|
-
encodings = doubleMetaphone.process('Français')
|
|
695
|
-
expect(encodings[0]).toBe('FRNS')
|
|
696
|
-
expect(encodings[1]).toBe('FRNSS')
|
|
697
|
-
})
|
|
698
|
-
|
|
699
|
-
it('should truncate codes if specified', function () {
|
|
700
|
-
let encodings = doubleMetaphone.process('Matrix', 4)
|
|
701
|
-
expect(encodings[0]).toBe('MTRK')
|
|
702
|
-
expect(encodings[1]).toBe('MTRK')
|
|
703
|
-
|
|
704
|
-
encodings = doubleMetaphone.process('Français', 4)
|
|
705
|
-
expect(encodings[0]).toBe('FRNS')
|
|
706
|
-
expect(encodings[1]).toBe('FRNS')
|
|
707
|
-
})
|
|
708
|
-
|
|
709
|
-
it('should not truncate code is shorter than specification', function () {
|
|
710
|
-
let encodings = doubleMetaphone.process('Matrix', 32)
|
|
711
|
-
expect(encodings[0]).toBe('MTRKS')
|
|
712
|
-
expect(encodings[1]).toBe('MTRKS')
|
|
713
|
-
|
|
714
|
-
encodings = doubleMetaphone.process('Français', 5)
|
|
715
|
-
expect(encodings[0]).toBe('FRNS')
|
|
716
|
-
expect(encodings[1]).toBe('FRNSS')
|
|
717
|
-
})
|
|
718
|
-
|
|
719
|
-
it('should compare', function () {
|
|
720
|
-
expect(doubleMetaphone.compare('love', 'hate')).toBeFalsy()
|
|
721
|
-
expect(doubleMetaphone.compare('love', 'luv')).toBeTruthy()
|
|
722
|
-
})
|
|
723
|
-
})
|
|
724
|
-
|
|
725
|
-
describe('issue #34', function () {
|
|
726
|
-
it('terminate words ending in H', function () {
|
|
727
|
-
expect(doubleMetaphone.process('ptah')).toEqual(['PT', 'PT'])
|
|
728
|
-
})
|
|
729
|
-
})
|
|
730
|
-
|
|
731
|
-
describe('issue #173', function () {
|
|
732
|
-
it('handle initial cons correctly', function () {
|
|
733
|
-
expect(doubleMetaphone.process('ceasar')).toEqual(['SSR', 'SSR'])
|
|
734
|
-
expect(doubleMetaphone.process('ach')).toEqual(['AK', 'AK'])
|
|
735
|
-
expect(doubleMetaphone.process('chemical')).toEqual(['KMKL', 'KMKL'])
|
|
736
|
-
expect(doubleMetaphone.process('choral')).toEqual(['KRL', 'KRL'])
|
|
737
|
-
})
|
|
738
|
-
})
|
|
739
|
-
})
|