natural 6.0.1 → 6.1.1

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.
@@ -16,7 +16,7 @@ jobs:
16
16
 
17
17
  strategy:
18
18
  matrix:
19
- node-version: [10.x, 12.x, 14.x, 15.x]
19
+ node-version: [14.x, 16.x, 18.x]
20
20
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
21
 
22
22
  steps:
package/README.md CHANGED
@@ -11,9 +11,11 @@
11
11
  "Natural" is a general natural language facility for nodejs. It offers a broad range of functionalities for natural language processing. Documentation can be found [here on GitHub Pages](http://naturalnode.github.io/natural/).
12
12
 
13
13
 
14
- ## License
14
+ ## Open source licenses
15
15
 
16
- Copyright (c) 2011, 2012 Chris Umbel, Rob Ellis, Russell Mull
16
+ ### Natural: MIT License
17
+
18
+ Copyright (c) 2011, 2012 Chris Umbel, Rob Ellis, Russell Mull, Hugo W.L. ter Doest
17
19
 
18
20
  Permission is hereby granted, free of charge, to any person obtaining a copy
19
21
  of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +35,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
35
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34
36
  THE SOFTWARE.
35
37
 
36
- ## WordNet License
38
+ ### WordNet License
37
39
 
38
40
  This license is available as the file LICENSE in any downloaded version of WordNet.
39
41
  WordNet 3.0 license: (Download)
@@ -58,3 +60,7 @@ Princeton University or Princeton may not be used in advertising or publicity
58
60
  pertaining to distribution of the software and/or database. Title to copyright
59
61
  in this software, database and any associated documentation shall at all times
60
62
  remain with Princeton University and LICENSEE agrees to preserve same.
63
+
64
+ ### Porter stemmer German: BSD License
65
+
66
+ The Porter stemmer for German is licensed by a BSD license. It states Standard BSD License in the source code, interpreted as the original BSD license consisting of four clauses.
@@ -30,7 +30,7 @@ export * from './ngrams'
30
30
  export * from './normalizers'
31
31
  export * from './phonetics'
32
32
  export * from './sentiment'
33
- export * from './spelcheck'
33
+ export * from './spellcheck'
34
34
  export * from './stemmers'
35
35
  export * from './tfidf'
36
36
  export * from './tokenizers'
@@ -34,6 +34,7 @@ declare const PorterStemmer: Stemmer
34
34
  declare const PorterStemmerEs: Stemmer
35
35
  declare const PorterStemmerFa: Stemmer
36
36
  declare const PorterStemmerFr: Stemmer
37
+ declare const PorterStemmerDe: Stemmer
37
38
  declare const PorterStemmerIt: Stemmer
38
39
  declare const PorterStemmerNl: Stemmer
39
40
  declare const PorterStemmerNo: Stemmer
@@ -26,6 +26,7 @@ exports.PorterStemmer = require('./porter_stemmer')
26
26
  exports.PorterStemmerFa = require('./porter_stemmer_fa')
27
27
  exports.PorterStemmerFr = require('./porter_stemmer_fr')
28
28
  exports.CarryStemmerFr = require('./Carry')
29
+ exports.PorterStemmerDe = require('./porter_stemmer_de')
29
30
  exports.PorterStemmerRu = require('./porter_stemmer_ru')
30
31
  exports.PorterStemmerEs = require('./porter_stemmer_es')
31
32
  exports.PorterStemmerIt = require('./porter_stemmer_it')
@@ -0,0 +1,265 @@
1
+ /*
2
+ * Original author: Joder Illi
3
+ * Integration in Natural by Hugo W.L. ter Doest
4
+ *
5
+ * Copyright (c) 2010, FormBlitz AG
6
+ * All rights reserved.
7
+ * Implementation of the stemming algorithm from http://snowball.tartarus.org/algorithms/german/stemmer.html
8
+ * Copyright of the algorithm is: Copyright (c) 2001, Dr Martin Porter and can be found at http://snowball.tartarus.org/license.php
9
+ *
10
+ * Redistribution and use in source and binary forms, with or without
11
+ * modification, is covered by the standard BSD license.
12
+ *
13
+ */
14
+
15
+ 'use strict'
16
+
17
+ const Stemmer = require('./stemmer_de')
18
+
19
+ const PorterStemmer = new Stemmer()
20
+ PorterStemmer.stem = stemm
21
+ module.exports = PorterStemmer
22
+
23
+ /* by Joder Illi, Snowball mailing list */
24
+ function stemm (word) {
25
+ /*
26
+ Put u and y between vowels into upper case
27
+ */
28
+ word = word.replace(/([aeiouyäöü])u([aeiouyäöü])/g, '$1U$2')
29
+ word = word.replace(/([aeiouyäöü])y([aeiouyäöü])/g, '$1Y$2')
30
+
31
+ /*
32
+ and then do the following mappings,
33
+ (a) replace ß with ss,
34
+ (a) replace ae with ä, Not doing these,
35
+ have trouble with diphtongs
36
+ (a) replace oe with ö, Not doing these,
37
+ have trouble with diphtongs
38
+ (a) replace ue with ü unless preceded by q. Not doing these,
39
+ have trouble with diphtongs
40
+ So in quelle, ue is not mapped to ü because it follows q, and in
41
+ feuer it is not mapped because the first part of the rule changes it to
42
+ feUer, so the u is not found.
43
+ */
44
+ word = word.replace(/ß/g, 'ss')
45
+ // word = word.replace(/ae/g, 'ä');
46
+ // word = word.replace(/oe/g, 'ö');
47
+ // word = word.replace(/([^q])ue/g, '$1ü');
48
+
49
+ /*
50
+ R1 and R2 are first set up in the standard way (see the note on R1
51
+ and R2), but then R1 is adjusted so that the region before it contains at
52
+ least 3 letters.
53
+ R1 is the region after the first non-vowel following a vowel, or is
54
+ the null region at the end of the word if there is no such non-vowel.
55
+ R2 is the region after the first non-vowel following a vowel in R1,
56
+ or is the null region at the end of the word if there is no such non-vowel.
57
+ */
58
+
59
+ let r1Index = word.search(/[aeiouyäöü][^aeiouyäöü]/)
60
+ let r1 = ''
61
+ if (r1Index !== -1) {
62
+ r1Index += 2
63
+ r1 = word.substring(r1Index)
64
+ }
65
+
66
+ let r2Index = -1
67
+ // let r2 = ''
68
+
69
+ if (r1Index !== -1) {
70
+ r2Index = r1.search(/[aeiouyäöü][^aeiouyäöü]/)
71
+ if (r2Index !== -1) {
72
+ r2Index += 2
73
+ // r2 = r1.substring(r2Index)
74
+ r2Index += r1Index
75
+ } else {
76
+ // r2 = ''
77
+ }
78
+ }
79
+
80
+ if (r1Index !== -1 && r1Index < 3) {
81
+ r1Index = 3
82
+ r1 = word.substring(r1Index)
83
+ }
84
+
85
+ /*
86
+ Define a valid s-ending as one of b, d, f, g, h, k, l, m, n, r or t.
87
+ Define a valid st-ending as the same list, excluding letter r.
88
+ */
89
+
90
+ /*
91
+ Do each of steps 1, 2 and 3.
92
+ */
93
+
94
+ /*
95
+ Step 1:
96
+ Search for the longest among the following suffixes,
97
+ (a) em ern er
98
+ (b) e en es
99
+ (c) s (preceded by a valid s-ending)
100
+ */
101
+ const a1Index = word.search(/(em|ern|er)$/g)
102
+ const b1Index = word.search(/(e|en|es)$/g)
103
+ let c1Index = word.search(/([bdfghklmnrt]s)$/g)
104
+ if (c1Index !== -1) {
105
+ c1Index++
106
+ }
107
+ let index1 = 10000
108
+ let optionUsed1 = ''
109
+ if (a1Index !== -1 && a1Index < index1) {
110
+ optionUsed1 = 'a'
111
+ index1 = a1Index
112
+ }
113
+ if (b1Index !== -1 && b1Index < index1) {
114
+ optionUsed1 = 'b'
115
+ index1 = b1Index
116
+ }
117
+ if (c1Index !== -1 && c1Index < index1) {
118
+ optionUsed1 = 'c'
119
+ index1 = c1Index
120
+ }
121
+
122
+ /*
123
+ and delete if in R1. (Of course the letter of the valid s-ending is
124
+ not necessarily in R1.) If an ending of group (b) is deleted, and the ending
125
+ is preceded by niss, delete the final s.
126
+ (For example, äckern -> äck, ackers -> acker, armes -> arm,
127
+ bedürfnissen -> bedürfnis)
128
+ */
129
+
130
+ if (index1 !== 10000 && r1Index !== -1) {
131
+ if (index1 >= r1Index) {
132
+ word = word.substring(0, index1)
133
+ if (optionUsed1 === 'b') {
134
+ if (word.search(/niss$/) !== -1) {
135
+ word = word.substring(0, word.length - 1)
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ /*
142
+ Step 2:
143
+ Search for the longest among the following suffixes,
144
+ (a) en er est
145
+ (b) st (preceded by a valid st-ending, itself preceded by at least 3
146
+ letters)
147
+ */
148
+
149
+ const a2Index = word.search(/(en|er|est)$/g)
150
+ let b2Index = word.search(/(.{3}[bdfghklmnt]st)$/g)
151
+ if (b2Index !== -1) {
152
+ b2Index += 4
153
+ }
154
+
155
+ let index2 = 10000
156
+ // const optionUsed2 = ''
157
+ if (a2Index !== -1 && a2Index < index2) {
158
+ // optionUsed2 = 'a'
159
+ index2 = a2Index
160
+ }
161
+ if (b2Index !== -1 && b2Index < index2) {
162
+ // optionUsed2 = 'b'
163
+ index2 = b2Index
164
+ }
165
+
166
+ /*
167
+ and delete if in R1.
168
+ (For example, derbsten -> derbst by step 1, and derbst -> derb by
169
+ step 2, since b is a valid st-ending, and is preceded by just 3 letters)
170
+ */
171
+
172
+ if (index2 !== 10000 && r1Index !== -1) {
173
+ if (index2 >= r1Index) {
174
+ word = word.substring(0, index2)
175
+ }
176
+ }
177
+
178
+ /*
179
+ Step 3: d-suffixes (*)
180
+ Search for the longest among the following suffixes, and perform the
181
+ action indicated.
182
+ end ung
183
+ delete if in R2
184
+ if preceded by ig, delete if in R2 and not preceded by e
185
+ ig ik isch
186
+ delete if in R2 and not preceded by e
187
+ lich heit
188
+ delete if in R2
189
+ if preceded by er or en, delete if in R1
190
+ keit
191
+ delete if in R2
192
+ if preceded by lich or ig, delete if in R2
193
+ */
194
+
195
+ const a3Index = word.search(/(end|ung)$/g)
196
+ let b3Index = word.search(/[^e](ig|ik|isch)$/g)
197
+ const c3Index = word.search(/(lich|heit)$/g)
198
+ const d3Index = word.search(/(keit)$/g)
199
+ if (b3Index !== -1) {
200
+ b3Index++
201
+ }
202
+
203
+ let index3 = 10000
204
+ let optionUsed3 = ''
205
+ if (a3Index !== -1 && a3Index < index3) {
206
+ optionUsed3 = 'a'
207
+ index3 = a3Index
208
+ }
209
+ if (b3Index !== -1 && b3Index < index3) {
210
+ optionUsed3 = 'b'
211
+ index3 = b3Index
212
+ }
213
+ if (c3Index !== -1 && c3Index < index3) {
214
+ optionUsed3 = 'c'
215
+ index3 = c3Index
216
+ }
217
+ if (d3Index !== -1 && d3Index < index3) {
218
+ optionUsed3 = 'd'
219
+ index3 = d3Index
220
+ }
221
+
222
+ if (index3 !== 10000 && r2Index !== -1) {
223
+ if (index3 >= r2Index) {
224
+ word = word.substring(0, index3)
225
+ let optionIndex = -1
226
+ // const optionSubsrt = ''
227
+ if (optionUsed3 === 'a') {
228
+ optionIndex = word.search(/[^e](ig)$/)
229
+ if (optionIndex !== -1) {
230
+ optionIndex++
231
+ if (optionIndex >= r2Index) {
232
+ word = word.substring(0, optionIndex)
233
+ }
234
+ }
235
+ } else if (optionUsed3 === 'c') {
236
+ optionIndex = word.search(/(er|en)$/)
237
+ if (optionIndex !== -1) {
238
+ if (optionIndex >= r1Index) {
239
+ word = word.substring(0, optionIndex)
240
+ }
241
+ }
242
+ } else if (optionUsed3 === 'd') {
243
+ optionIndex = word.search(/(lich|ig)$/)
244
+ if (optionIndex !== -1) {
245
+ if (optionIndex >= r2Index) {
246
+ word = word.substring(0, optionIndex)
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ /*
254
+ Finally,
255
+ turn U and Y back into lower case, and remove the umlaut accent from
256
+ a, o and u.
257
+ */
258
+ word = word.replace(/U/g, 'u')
259
+ word = word.replace(/Y/g, 'y')
260
+ word = word.replace(/ä/g, 'a')
261
+ word = word.replace(/ö/g, 'o')
262
+ word = word.replace(/ü/g, 'u')
263
+
264
+ return word
265
+ }
@@ -0,0 +1,54 @@
1
+
2
+ /*
3
+ Copyright (c) 2023, Hugo W.L. ter Doest
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+ */
23
+
24
+ 'use strict'
25
+
26
+ const stopwords = require('stopwords-iso')
27
+ const englishStopWords = stopwords.de
28
+ const Tokenizer = require('../tokenizers/aggressive_tokenizer_de')
29
+
30
+ class Stemmer {
31
+ stem (token) {
32
+ return token
33
+ }
34
+
35
+ tokenizeAndStem (text, keepStops) {
36
+ const stemmedTokens = []
37
+
38
+ const that = this
39
+ new Tokenizer().tokenize(text).forEach(function (token) {
40
+ if (keepStops || englishStopWords.indexOf(token) === -1) {
41
+ let resultToken = token.toLowerCase()
42
+ // if (resultToken.match(new RegExp('[a-záéíóúüñ0-9]+', 'gi'))) {
43
+ if (resultToken.match(/[a-záéíóúüñ0-9]+/gi)) {
44
+ resultToken = that.stem(resultToken)
45
+ }
46
+ stemmedTokens.push(resultToken)
47
+ }
48
+ })
49
+
50
+ return stemmedTokens
51
+ }
52
+ }
53
+
54
+ module.exports = Stemmer
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright (c) 2011, Chris Umbel, Martijn de Boer
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
+ const Tokenizer = require('./tokenizer')
26
+ const util = require('util')
27
+
28
+ const AggressiveTokenizer = function () {
29
+ Tokenizer.call(this)
30
+ }
31
+ util.inherits(AggressiveTokenizer, Tokenizer)
32
+
33
+ module.exports = AggressiveTokenizer
34
+
35
+ AggressiveTokenizer.prototype.tokenize = function (text) {
36
+ // break a string up into an array of tokens by anything non-word
37
+ return this.trim(text.split(/[^a-zA-Z0-9_'-]+/))
38
+ }
@@ -67,6 +67,9 @@ export declare class AggressiveTokenizerFa implements Tokenizer {
67
67
  export declare class AggressiveTokenizerFr implements Tokenizer {
68
68
  tokenize (text: string): string[]
69
69
  }
70
+ export declare class AggressiveTokenizerDe implements Tokenizer {
71
+ tokenize (text: string): string[]
72
+ }
70
73
  export declare class AggressiveTokenizerId implements Tokenizer {
71
74
  tokenize (text: string): string[]
72
75
  }
@@ -25,6 +25,7 @@ THE SOFTWARE.
25
25
  exports.AggressiveTokenizerNl = require('./aggressive_tokenizer_nl')
26
26
  exports.AggressiveTokenizerFa = require('./aggressive_tokenizer_fa')
27
27
  exports.AggressiveTokenizerFr = require('./aggressive_tokenizer_fr')
28
+ exports.AggressiveTokenizerDe = require('./aggressive_tokenizer_de')
28
29
  exports.AggressiveTokenizerRu = require('./aggressive_tokenizer_ru')
29
30
  exports.AggressiveTokenizerEs = require('./aggressive_tokenizer_es')
30
31
  exports.AggressiveTokenizerIt = require('./aggressive_tokenizer_it')
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "natural",
3
3
  "description": "General natural language (tokenizing, stemming (English, Russian, Spanish), part-of-speech tagging, sentiment analysis, classification, inflection, phonetics, tfidf, WordNet, jaro-winkler, Levenshtein distance, Dice's Coefficient) facilities for node.",
4
- "version": "6.0.1",
4
+ "version": "6.1.1",
5
5
  "homepage": "https://github.com/NaturalNode/natural",
6
6
  "repository": {
7
7
  "type": "git",
@@ -14,12 +14,14 @@
14
14
  "afinn-165": "^1.0.2",
15
15
  "apparatus": "^0.0.10",
16
16
  "safe-stable-stringify": "^2.2.0",
17
+ "stopwords-iso": "^1.1.0",
17
18
  "sylvester": "^0.0.12",
18
19
  "tsc": "^2.0.4",
19
20
  "underscore": "^1.9.1",
20
21
  "wordnet-db": "^3.1.11"
21
22
  },
22
23
  "devDependencies": {
24
+ "@types/node": "^18.11.18",
23
25
  "browserfs": "^1.4.3",
24
26
  "gulp": "^4.0.2",
25
27
  "gulp-jasmine": "^4.0.0",