natural 7.0.2 → 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 (72) hide show
  1. package/.github/workflows/npm-publish.yml +2 -0
  2. package/.nycrc +9 -0
  3. package/lib/natural/analyzers/sentence_analyzer.js +115 -113
  4. package/lib/natural/spellcheck/spellcheck.js +63 -61
  5. package/lib/natural/util/bag.js +27 -25
  6. package/package.json +3 -4
  7. package/tsconfig.json +1 -1
  8. package/ts_spec/MaxEntClassifier_spec.ts +0 -130
  9. package/ts_spec/SentimentAnalyzer_spec.ts +0 -232
  10. package/ts_spec/WordPunctTokenizer_spec.ts +0 -57
  11. package/ts_spec/aggressive_tokenizer_de_spec.ts +0 -36
  12. package/ts_spec/aggressive_tokenizer_es_spec.ts +0 -39
  13. package/ts_spec/aggressive_tokenizer_fr_spec.ts +0 -111
  14. package/ts_spec/aggressive_tokenizer_hi_spec.ts +0 -70
  15. package/ts_spec/aggressive_tokenizer_nl_spec.ts +0 -39
  16. package/ts_spec/aggressive_tokenizer_pt_spec.ts +0 -48
  17. package/ts_spec/aggressive_tokenizer_spec.ts +0 -57
  18. package/ts_spec/aggressive_tokenizer_sv_spec.ts +0 -52
  19. package/ts_spec/aggressive_tokenizer_vi_spec.ts +0 -48
  20. package/ts_spec/bayes_classifier_spec.ts +0 -165
  21. package/ts_spec/brill_pos_tagger_spec.ts +0 -79
  22. package/ts_spec/brill_pos_trainer_spec.ts +0 -107
  23. package/ts_spec/carry_stemmer_fr_spec.ts +0 -97
  24. package/ts_spec/classifier_spec.ts +0 -104
  25. package/ts_spec/count_inflector_fr_spec.ts +0 -47
  26. package/ts_spec/count_inflector_spec.ts +0 -76
  27. package/ts_spec/damerau_levenshtein_spec.ts +0 -53
  28. package/ts_spec/dice_coefficient_spec.ts +0 -37
  29. package/ts_spec/double_metaphone_spec.ts +0 -739
  30. package/ts_spec/hamming_distance_spec.ts +0 -66
  31. package/ts_spec/jaro-winkler_spec.ts +0 -79
  32. package/ts_spec/lancaster_stemmer_spec.ts +0 -63
  33. package/ts_spec/levenshtein_spec.ts +0 -107
  34. package/ts_spec/logistic_regression_classifier_spec.ts +0 -93
  35. package/ts_spec/longest_path_tree_spec.ts +0 -111
  36. package/ts_spec/metaphone_spec.ts +0 -258
  37. package/ts_spec/ngram_spec.ts +0 -145
  38. package/ts_spec/ngram_zh_spec.ts +0 -124
  39. package/ts_spec/normalizer_ja_spec.ts +0 -165
  40. package/ts_spec/normalizer_no_spec.ts +0 -112
  41. package/ts_spec/normalizer_spec.ts +0 -141
  42. package/ts_spec/noun_inflector_fr_spec.ts +0 -472
  43. package/ts_spec/noun_inflector_ja_spec.ts +0 -116
  44. package/ts_spec/noun_inflector_spec.ts +0 -369
  45. package/ts_spec/orthography_tokenizer_spec.ts +0 -47
  46. package/ts_spec/porter_stemmer_de_spec.ts +0 -53
  47. package/ts_spec/porter_stemmer_es_spec.ts +0 -63
  48. package/ts_spec/porter_stemmer_fr_spec.ts +0 -103
  49. package/ts_spec/porter_stemmer_it_spec.ts +0 -56
  50. package/ts_spec/porter_stemmer_nl_spec.ts +0 -73
  51. package/ts_spec/porter_stemmer_no_spec.ts +0 -148
  52. package/ts_spec/porter_stemmer_pt_spec.ts +0 -50
  53. package/ts_spec/porter_stemmer_ru_spec.ts +0 -67
  54. package/ts_spec/porter_stemmer_spec.ts +0 -202
  55. package/ts_spec/porter_stemmer_sv_spec.ts +0 -41
  56. package/ts_spec/present_verb_inflector_spec.ts +0 -127
  57. package/ts_spec/remove_diacritics_spec.ts +0 -30
  58. package/ts_spec/sentence_analyzer_spec.ts +0 -293
  59. package/ts_spec/sentence_tokenizer_parser_spec.ts +0 -200
  60. package/ts_spec/sentence_tokenizer_spec.ts +0 -189
  61. package/ts_spec/shortest_path_tree_spec.ts +0 -141
  62. package/ts_spec/soundex_spec.ts +0 -162
  63. package/ts_spec/spellcheck_spec.ts +0 -112
  64. package/ts_spec/stemmer_id_spec.ts +0 -374
  65. package/ts_spec/stemmer_ja_spec.ts +0 -69
  66. package/ts_spec/stemmer_token_spec.ts +0 -163
  67. package/ts_spec/tfidf_spec.ts +0 -275
  68. package/ts_spec/tokenizer_case_spec.ts +0 -242
  69. package/ts_spec/tokenizer_ja_spec.ts +0 -63
  70. package/ts_spec/transliterator_ja_spec.ts +0 -105
  71. package/ts_spec/treebank_word_tokenizer_spec.ts +0 -38
  72. package/ts_spec/trie_spec.ts +0 -197
@@ -1,104 +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 { BayesClassifier } from 'lib/natural'
26
-
27
- describe('classifier', function () {
28
- describe('addDocument', function () {
29
- it('should ignore an empty document', function () {
30
- const classifier = new BayesClassifier()
31
- classifier.addDocument('', 'philosophy')
32
- expect(classifier.docs.length).toBe(0)
33
- })
34
-
35
- it('should increment features', function () {
36
- const classifier = new BayesClassifier()
37
- classifier.addDocument('foo', '')
38
- classifier.addDocument('foo', '')
39
- classifier.addDocument('bar', '')
40
- classifier.addDocument('bar', '')
41
- classifier.addDocument('bar', '')
42
- classifier.addDocument('baz', '')
43
- expect(classifier.docs.length).toBe(6)
44
- expect(classifier.features.foo).toBe(2)
45
- expect(classifier.features.bar).toBe(3)
46
- expect(classifier.features.baz).toBe(1)
47
- })
48
- })
49
-
50
- describe('Classifier', function () {
51
- const pushedEvents: any[] = []
52
- function eventRegister (obj: any): void {
53
- pushedEvents.push(obj)
54
- }
55
-
56
- function assertEventResults (): void {
57
- expect(pushedEvents[0].index).toBe(0)
58
- expect(pushedEvents[0].total).toBe(6)
59
- expect(pushedEvents.length).toBe(6)
60
- }
61
-
62
- it('should emit events when documents are added or training is finished', function () {
63
- const classifier = new BayesClassifier()
64
- classifier.on('trainedWithDocument', eventRegister)
65
- classifier.on('doneTraining', assertEventResults)
66
-
67
- classifier.addDocument('i fixed the box', 'computing')
68
- classifier.addDocument('i write code', 'computing')
69
- classifier.addDocument('nasty script code', 'computing')
70
- classifier.addDocument('write a book', 'literature')
71
- classifier.addDocument('read a book', 'literature')
72
- classifier.addDocument('study the books', 'literature')
73
-
74
- classifier.train()
75
- classifier.removeListener('trainedWithDocument', eventRegister)
76
- classifier.removeListener('doneTraining', assertEventResults)
77
- })
78
- })
79
-
80
- describe('Classifier', function () {
81
- let classifier: BayesClassifier
82
- beforeEach(function () {
83
- classifier = new BayesClassifier()
84
- classifier.addDocument('i fixed the box', 'computing')
85
- classifier.addDocument('i write code', 'computing')
86
- classifier.addDocument('write a book', 'literature')
87
- classifier.addDocument('study the books', 'literature')
88
- })
89
-
90
- it('should do nothing if text is not a string', function () {
91
- expect(classifier.docs.length).toBe(4)
92
- classifier.removeDocument(['write a book'], 'literature')
93
- classifier.removeDocument(['study the books'], 'literature')
94
- expect(classifier.docs.length).toBe(4)
95
- })
96
-
97
- it('should do nothing if text is not a match', function () {
98
- expect(classifier.docs.length).toBe(4)
99
- classifier.removeDocument('something else', 'literature')
100
- classifier.removeDocument('another thing', 'literature')
101
- expect(classifier.docs.length).toBe(4)
102
- })
103
- })
104
- })
@@ -1,47 +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
- 'use strict'
24
-
25
- import { CountInflectorFr } from 'lib/natural'
26
- const inflector = new CountInflectorFr()
27
-
28
- describe('count_inflector', function () {
29
- it('should handle 1er cases', function () {
30
- expect(inflector.nth(1)).toBe('1er')
31
- })
32
-
33
- it('should handle the 2e cases', function () {
34
- expect(inflector.nth(0)).toBe('0e')
35
- expect(inflector.nth(2)).toBe('2e')
36
- expect(inflector.nth(3)).toBe('3e')
37
- expect(inflector.nth(5)).toBe('5e')
38
- expect(inflector.nth(11)).toBe('11e')
39
- expect(inflector.nth(100)).toBe('100e')
40
- expect(inflector.nth(999)).toBe('999e')
41
- })
42
-
43
- it('should handle roman numerals', function () {
44
- expect(inflector.nth('I')).toBe('Ier')
45
- expect(inflector.nth('XX')).toBe('XXe')
46
- })
47
- })
@@ -1,76 +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 { CountInflector } from 'lib/natural'
26
- const inflector = new CountInflector()
27
-
28
- describe('count_inflector', function () {
29
- it('should handle 1st cases', function () {
30
- expect(inflector.nth(1)).toBe('1st')
31
- expect(inflector.nth(101)).toBe('101st')
32
- expect(inflector.nth(11)).not.toBe('11st')
33
- expect(inflector.nth(111)).not.toBe('111st')
34
- })
35
-
36
- it('should handle the 12th cases', function () {
37
- expect(inflector.nth(12)).toBe('12th')
38
- expect(inflector.nth(112)).toBe('112th')
39
- expect(inflector.nth(1112)).toBe('1112th')
40
- })
41
-
42
- it('should handle the 11th cases', function () {
43
- expect(inflector.nth(11)).toBe('11th')
44
- expect(inflector.nth(111)).toBe('111th')
45
- expect(inflector.nth(1111)).toBe('1111th')
46
- })
47
-
48
- it('should handle the 13th cases', function () {
49
- expect(inflector.nth(13)).toBe('13th')
50
- expect(inflector.nth(113)).toBe('113th')
51
- expect(inflector.nth(1113)).toBe('1113th')
52
- })
53
-
54
- it('should handle the th cases', function () {
55
- expect(inflector.nth(10)).toBe('10th')
56
- expect(inflector.nth(4)).toBe('4th')
57
- expect(inflector.nth(400)).toBe('400th')
58
- expect(inflector.nth(404)).toBe('404th')
59
- expect(inflector.nth(5)).toBe('5th')
60
- expect(inflector.nth(5000)).toBe('5000th')
61
- expect(inflector.nth(5005)).toBe('5005th')
62
- expect(inflector.nth(9)).toBe('9th')
63
- expect(inflector.nth(90009)).toBe('90009th')
64
- expect(inflector.nth(90000)).toBe('90000th')
65
- })
66
-
67
- it('should handle 2nd cases', function () {
68
- expect(inflector.nth(2)).toBe('2nd')
69
- expect(inflector.nth(12)).not.toBe('12nd')
70
- })
71
-
72
- it('should handle 3rd cases', function () {
73
- expect(inflector.nth(3)).toBe('3rd')
74
- expect(inflector.nth(13)).not.toBe('13rd')
75
- })
76
- })
@@ -1,53 +0,0 @@
1
- 'use strict'
2
-
3
- import { DamerauLevenshteinDistance, DamerauLevenshteinDistanceSearch } from 'lib/natural'
4
-
5
- describe('DamerauLevenshtein', function () {
6
- describe('default', function () {
7
- it('should be 0 when given equal strings', function () {
8
- expect(DamerauLevenshteinDistance('test', 'test')).toBe(0)
9
- })
10
-
11
- it('should calculate 1 for adjacent transposition', function () {
12
- expect(DamerauLevenshteinDistance('za', 'az')).toBe(1)
13
- expect(DamerauLevenshteinDistance('Tomato', 'oTmato')).toBe(1)
14
- })
15
-
16
- it('should handle custom transposition_cost', function () {
17
- expect(DamerauLevenshteinDistance('za', 'az', { transposition_cost: 0 })).toBe(0)
18
- })
19
-
20
- it('should calculate 2 when there are 2 transpositions', function () {
21
- expect(DamerauLevenshteinDistance('tomato', 'otmaot')).toBe(2)
22
- })
23
-
24
- it('should calculate 2 for 1 transposition and 1 insertion', function () {
25
- expect(DamerauLevenshteinDistance('CA', 'ABC')).toBe(2)
26
- expect(DamerauLevenshteinDistance('a cat', 'a abct')).toBe(2)
27
- })
28
- })
29
-
30
- describe('options.restricted = true', function () {
31
- const restricted = { restricted: true }
32
- it('should calculate 0 for equal strings', function () {
33
- expect(DamerauLevenshteinDistance('identity', 'identity', restricted)).toBe(0)
34
- })
35
- it('should calculate 1 for an adjacent transposition', function () {
36
- expect(DamerauLevenshteinDistance('za', 'az', restricted)).toBe(1)
37
- })
38
- it('should not count transposition more than 1 char away', function () {
39
- expect(DamerauLevenshteinDistance('CA', 'ABC', restricted)).toBe(3)
40
- })
41
- })
42
-
43
- it('should combine search with Damerau', function () {
44
- const source = 'The RainCoat BookStore'
45
- const target = 'All the best books are here at the Rain Coats Book Store'
46
- const result = DamerauLevenshteinDistanceSearch(source, target)
47
- expect(result).toEqual({
48
- substring: 'the Rain Coats Book Store',
49
- distance: 4,
50
- offset: 31
51
- })
52
- })
53
- })
@@ -1,37 +0,0 @@
1
- 'use strict'
2
-
3
- import { DiceCoefficient as dice } from 'lib/natural'
4
- import text1 from '../spec/test_data/Wikipedia_EN_FrenchRevolution.json'
5
- import text2 from '../spec/test_data/Wikipedia_EN_InfluenceOfTheFrenchRevolution.json'
6
-
7
- describe('dice', function () {
8
- it('should handle exact matches', function () {
9
- expect(dice('john', 'john')).toBe(1)
10
- })
11
-
12
- it('should match single character words', function () {
13
- expect(dice('a', 'a')).toBe(1)
14
- expect(dice('a', 'b')).toBe(0)
15
- })
16
-
17
- it('should handle total mis-matches', function () {
18
- expect(dice('john', 'matt')).toBe(0)
19
- })
20
-
21
- // Example from http://en.wikipedia.org/wiki/Dice's_coefficient
22
- it('should handle a typical case', function () {
23
- expect(dice('night', 'nacht')).toBe(0.25)
24
- })
25
-
26
- it('should sanitize case', function () {
27
- expect(dice('night', 'NIGHT')).toBe(1)
28
- })
29
-
30
- it('should sanitize spacing', function () {
31
- expect(dice('the space', 'the space')).toBe(1)
32
- })
33
-
34
- it('should compare complete texts', function () {
35
- expect(dice(text1.text, text2.text)).toBe(0.7939374395356337)
36
- })
37
- })