natural 0.1.27 → 0.2.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.
- package/.editorconfig +7 -0
- package/LICENSE.txt +0 -0
- package/Makefile +0 -0
- package/README.md +237 -24
- package/benchmarks/index.js +1 -1
- package/benchmarks/metaphone.js +0 -0
- package/benchmarks/soundex.js +0 -0
- package/examples/classification/basic.js +0 -0
- package/examples/classification/recall.js +0 -0
- package/examples/classification/store.js +0 -0
- package/examples/inflection/count.js +0 -0
- package/examples/inflection/noun.js +0 -0
- package/examples/inflection/noun_attach.js +0 -0
- package/examples/phonetics/compare.js +0 -0
- package/examples/phonetics/sounds_like.js +0 -0
- package/examples/phonetics/tokenize_and_phoneticize.js +0 -0
- package/examples/stemming/stem_corpus.js +0 -0
- package/examples/stemming/stem_word.js +0 -0
- package/examples/tfidf/array_example.js +0 -0
- package/examples/tfidf/multiple_terms.js +0 -0
- package/examples/tfidf/tfidf_example.js +0 -0
- package/index.js +0 -0
- package/io_spec/test_data/tfidf/one +0 -0
- package/io_spec/test_data/tfidf/two +0 -0
- package/io_spec/tfidf_spec.js +0 -0
- package/io_spec/wordnet_spec.js +0 -0
- package/lib/natural/analyzers/sentence_analyzer.js +16 -13
- package/lib/natural/classifiers/bayes_classifier.js +6 -2
- package/lib/natural/classifiers/classifier.js +0 -0
- package/lib/natural/classifiers/logistic_regression_classifier.js +0 -0
- package/lib/natural/distance/dice_coefficient.js +0 -0
- package/lib/natural/distance/jaro-winkler_distance.js +13 -8
- package/lib/natural/distance/levenshtein_distance.js +0 -0
- package/lib/natural/index.js +8 -0
- package/lib/natural/inflectors/count_inflector.js +0 -0
- package/lib/natural/inflectors/form_set.js +0 -0
- package/lib/natural/inflectors/fr/count_inflector.js +0 -0
- package/lib/natural/inflectors/fr/noun_inflector.js +0 -0
- package/lib/natural/inflectors/ja/noun_inflector.js +0 -0
- package/lib/natural/inflectors/noun_inflector.js +0 -0
- package/lib/natural/inflectors/present_verb_inflector.js +1 -0
- package/lib/natural/inflectors/singular_plural_inflector.js +1 -2
- package/lib/natural/ngrams/ngrams.js +45 -8
- package/lib/natural/ngrams/ngrams_zh.js +83 -0
- package/lib/natural/normalizers/normalizer.js +30 -38
- package/lib/natural/normalizers/normalizer_ja.js +26 -8
- package/lib/natural/normalizers/normalizer_no.js +59 -0
- package/lib/natural/phonetics/double_metaphone.js +9 -4
- package/lib/natural/phonetics/metaphone.js +6 -1
- package/lib/natural/phonetics/phonetic.js +0 -0
- package/lib/natural/phonetics/soundex.js +11 -7
- package/lib/natural/spellcheck/spellcheck.js +80 -0
- package/lib/natural/stemmers/lancaster_rules.js +4 -4
- package/lib/natural/stemmers/lancaster_stemmer.js +0 -0
- package/lib/natural/stemmers/porter_stemmer.js +90 -63
- package/lib/natural/stemmers/porter_stemmer_es.js +22 -23
- package/lib/natural/stemmers/porter_stemmer_fr.js +377 -0
- package/lib/natural/stemmers/porter_stemmer_no.js +155 -0
- package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
- package/lib/natural/stemmers/stemmer.js +0 -0
- package/lib/natural/stemmers/stemmer_fr.js +58 -0
- package/lib/natural/stemmers/stemmer_no.js +61 -0
- package/lib/natural/stemmers/stemmer_pt.js +65 -0
- package/lib/natural/stemmers/token.js +163 -0
- package/lib/natural/tfidf/tfidf.js +50 -19
- package/lib/natural/tokenizers/aggressive_tokenizer.js +0 -0
- package/lib/natural/tokenizers/aggressive_tokenizer_es.js +0 -0
- package/lib/natural/tokenizers/aggressive_tokenizer_fr.js +36 -0
- package/lib/natural/tokenizers/aggressive_tokenizer_nl.js +0 -0
- package/lib/natural/tokenizers/aggressive_tokenizer_no.js +39 -0
- package/lib/natural/tokenizers/aggressive_tokenizer_pt.js +0 -0
- package/lib/natural/tokenizers/regexp_tokenizer.js +0 -0
- package/lib/natural/tokenizers/tokenizer.js +2 -2
- package/lib/natural/tokenizers/treebank_word_tokenizer.js +0 -0
- package/lib/natural/trie/trie.js +47 -0
- package/lib/natural/util/bag.js +50 -0
- package/lib/natural/util/edge_weighted_digraph.js +112 -0
- package/lib/natural/util/longest_path_tree.js +99 -0
- package/lib/natural/util/shortest_path_tree.js +100 -0
- package/lib/natural/util/stopwords.js +0 -0
- package/lib/natural/util/stopwords_fr.js +194 -0
- package/lib/natural/util/stopwords_nl.js +43 -0
- package/lib/natural/util/stopwords_no.js +42 -0
- package/lib/natural/util/stopwords_pt.js +136 -0
- package/lib/natural/util/topological.js +98 -0
- package/lib/natural/wordnet/data_file.js +0 -0
- package/lib/natural/wordnet/index_file.js +0 -0
- package/lib/natural/wordnet/wordnet.js +0 -0
- package/lib/natural/wordnet/wordnet_file.js +0 -0
- package/package.json +2 -2
- package/spec/aggressive_tokenizer_fr_spec.js +101 -0
- package/spec/aggressive_tokenizer_pt_spec.js +0 -0
- package/spec/aggressive_tokenizer_spec.js +0 -0
- package/spec/bayes_classifier_spec.js +12 -0
- package/spec/classifier_spec.js +84 -0
- package/spec/count_inflector_fr_spec.js +0 -0
- package/spec/count_inflector_spec.js +0 -0
- package/spec/dice_coefficient_spec.js +0 -0
- package/spec/double_metaphone_spec.js +10 -1
- package/spec/jaro-winkler_spec.js +0 -0
- package/spec/lancaster_stemmer_spec.js +10 -1
- package/spec/levenshtein_spec.js +0 -0
- package/spec/logistic_regression_classifier_spec.js +0 -0
- package/spec/longest_path_tree_spec.js +102 -0
- package/spec/metaphone_spec.js +10 -0
- package/spec/ngram_spec.js +61 -0
- package/spec/ngram_zh_spec.js +122 -0
- package/spec/normalizer_ja_spec.js +9 -3
- package/spec/normalizer_no_spec.js +111 -0
- package/spec/normalizer_spec.js +26 -5
- package/spec/noun_inflector_fr_spec.js +0 -0
- package/spec/noun_inflector_ja_spec.js +0 -0
- package/spec/noun_inflector_spec.js +0 -0
- package/spec/porter_stemmer_fr_spec.js +101 -0
- package/spec/porter_stemmer_no_spec.js +143 -0
- package/spec/porter_stemmer_pt_spec.js +50 -0
- package/spec/porter_stemmer_spec.js +49 -0
- package/spec/present_verb_inflector_spec.js +3 -0
- package/spec/remove_diacritics_spec.js +31 -0
- package/spec/sentence_analyzer_spec.js +248 -0
- package/spec/shortest_path_tree_spec.js +132 -0
- package/spec/soundex_spec.js +13 -9
- package/spec/spellcheck_spec.js +92 -0
- package/spec/stemmer_token_spec.js +161 -0
- package/spec/test_data/snowball_fr.txt +20402 -0
- package/spec/test_data/snowball_no.txt +20628 -0
- package/spec/test_data/snowball_pt.txt +32016 -0
- package/spec/test_data/tfdif_testcorpus.txt +0 -0
- package/spec/test_data/tfidf_teststopwords.txt +0 -0
- package/spec/test_data/wordnet_mini.sql +0 -0
- package/spec/tfidf_spec.js +153 -28
- package/spec/tokenizer_ja_spec.js +0 -0
- package/spec/treebank_word_tokenizer_spec.js +0 -0
- package/spec/trie_spec.js +27 -3
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2014, Ismaël Héry
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// A list of commonly used french words that have little meaning and can be excluded
|
|
24
|
+
// from analysis.
|
|
25
|
+
|
|
26
|
+
var words = ['être', 'avoir', 'faire',
|
|
27
|
+
'a',
|
|
28
|
+
'au',
|
|
29
|
+
'aux',
|
|
30
|
+
'avec',
|
|
31
|
+
'ce',
|
|
32
|
+
'ces',
|
|
33
|
+
'dans',
|
|
34
|
+
'de',
|
|
35
|
+
'des',
|
|
36
|
+
'du',
|
|
37
|
+
'elle',
|
|
38
|
+
'en',
|
|
39
|
+
'et',
|
|
40
|
+
'eux',
|
|
41
|
+
'il',
|
|
42
|
+
'je',
|
|
43
|
+
'la',
|
|
44
|
+
'le',
|
|
45
|
+
'leur',
|
|
46
|
+
'lui',
|
|
47
|
+
'ma',
|
|
48
|
+
'mais',
|
|
49
|
+
'me',
|
|
50
|
+
'même',
|
|
51
|
+
'mes',
|
|
52
|
+
'moi',
|
|
53
|
+
'mon',
|
|
54
|
+
'ne',
|
|
55
|
+
'nos',
|
|
56
|
+
'notre',
|
|
57
|
+
'nous',
|
|
58
|
+
'on',
|
|
59
|
+
'ou',
|
|
60
|
+
'où',
|
|
61
|
+
'par',
|
|
62
|
+
'pas',
|
|
63
|
+
'pour',
|
|
64
|
+
'qu',
|
|
65
|
+
'que',
|
|
66
|
+
'qui',
|
|
67
|
+
'sa',
|
|
68
|
+
'se',
|
|
69
|
+
'ses',
|
|
70
|
+
'son',
|
|
71
|
+
'sur',
|
|
72
|
+
'ta',
|
|
73
|
+
'te',
|
|
74
|
+
'tes',
|
|
75
|
+
'toi',
|
|
76
|
+
'ton',
|
|
77
|
+
'tu',
|
|
78
|
+
'un',
|
|
79
|
+
'une',
|
|
80
|
+
'vos',
|
|
81
|
+
'votre',
|
|
82
|
+
'vous',
|
|
83
|
+
'c',
|
|
84
|
+
'd',
|
|
85
|
+
'j',
|
|
86
|
+
'l',
|
|
87
|
+
'à',
|
|
88
|
+
'm',
|
|
89
|
+
'n',
|
|
90
|
+
's',
|
|
91
|
+
't',
|
|
92
|
+
'y',
|
|
93
|
+
'été',
|
|
94
|
+
'étée',
|
|
95
|
+
'étées',
|
|
96
|
+
'étés',
|
|
97
|
+
'étant',
|
|
98
|
+
'suis',
|
|
99
|
+
'es',
|
|
100
|
+
'est',
|
|
101
|
+
'sommes',
|
|
102
|
+
'êtes',
|
|
103
|
+
'sont',
|
|
104
|
+
'serai',
|
|
105
|
+
'seras',
|
|
106
|
+
'sera',
|
|
107
|
+
'serons',
|
|
108
|
+
'serez',
|
|
109
|
+
'seront',
|
|
110
|
+
'serais',
|
|
111
|
+
'serait',
|
|
112
|
+
'serions',
|
|
113
|
+
'seriez',
|
|
114
|
+
'seraient',
|
|
115
|
+
'étais',
|
|
116
|
+
'était',
|
|
117
|
+
'étions',
|
|
118
|
+
'étiez',
|
|
119
|
+
'étaient',
|
|
120
|
+
'fus',
|
|
121
|
+
'fut',
|
|
122
|
+
'fûmes',
|
|
123
|
+
'fûtes',
|
|
124
|
+
'furent',
|
|
125
|
+
'sois',
|
|
126
|
+
'soit',
|
|
127
|
+
'soyons',
|
|
128
|
+
'soyez',
|
|
129
|
+
'soient',
|
|
130
|
+
'fusse',
|
|
131
|
+
'fusses',
|
|
132
|
+
'fût',
|
|
133
|
+
'fussions',
|
|
134
|
+
'fussiez',
|
|
135
|
+
'fussent',
|
|
136
|
+
'ayant',
|
|
137
|
+
'eu',
|
|
138
|
+
'eue',
|
|
139
|
+
'eues',
|
|
140
|
+
'eus',
|
|
141
|
+
'ai',
|
|
142
|
+
'as',
|
|
143
|
+
'avons',
|
|
144
|
+
'avez',
|
|
145
|
+
'ont',
|
|
146
|
+
'aurai',
|
|
147
|
+
'auras',
|
|
148
|
+
'aura',
|
|
149
|
+
'aurons',
|
|
150
|
+
'aurez',
|
|
151
|
+
'auront',
|
|
152
|
+
'aurais',
|
|
153
|
+
'aurait',
|
|
154
|
+
'aurions',
|
|
155
|
+
'auriez',
|
|
156
|
+
'auraient',
|
|
157
|
+
'avais',
|
|
158
|
+
'avait',
|
|
159
|
+
'avions',
|
|
160
|
+
'aviez',
|
|
161
|
+
'avaient',
|
|
162
|
+
'eut',
|
|
163
|
+
'eûmes',
|
|
164
|
+
'eûtes',
|
|
165
|
+
'eurent',
|
|
166
|
+
'aie',
|
|
167
|
+
'aies',
|
|
168
|
+
'ait',
|
|
169
|
+
'ayons',
|
|
170
|
+
'ayez',
|
|
171
|
+
'aient',
|
|
172
|
+
'eusse',
|
|
173
|
+
'eusses',
|
|
174
|
+
'eût',
|
|
175
|
+
'eussions',
|
|
176
|
+
'eussiez',
|
|
177
|
+
'eussent',
|
|
178
|
+
'ceci',
|
|
179
|
+
'cela',
|
|
180
|
+
'cet',
|
|
181
|
+
'cette',
|
|
182
|
+
'ici',
|
|
183
|
+
'ils',
|
|
184
|
+
'les',
|
|
185
|
+
'leurs',
|
|
186
|
+
'quel',
|
|
187
|
+
'quels',
|
|
188
|
+
'quelle',
|
|
189
|
+
'quelles',
|
|
190
|
+
'sans',
|
|
191
|
+
'soi'
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
exports.words = words;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2011, Chris Umbel, Martijn de Boer, Damien van Holten
|
|
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
|
+
// a list of commonly used words that have little meaning and can be excluded
|
|
24
|
+
// from analysis.
|
|
25
|
+
// This dutch wordlist has been parsed from a list created by Damien van Holten
|
|
26
|
+
// source: http://www.damienvanholten.com/blog/dutch-stop-words/
|
|
27
|
+
var words = [
|
|
28
|
+
'aan', 'af', 'al', 'alles', 'als', 'altijd', 'andere', 'ben', 'bij', 'daar',
|
|
29
|
+
'dan', 'dat', 'de', 'der', 'deze', 'die', 'dit', 'doch', 'doen', 'door', 'dus',
|
|
30
|
+
'een', 'eens', 'en', 'er', 'ge', 'geen', 'geweest', 'haar', 'had', 'heb',
|
|
31
|
+
'hebben', 'heeft', 'hem', 'het', 'hier', 'hij', 'hoe', 'hun', 'iemand', 'iets',
|
|
32
|
+
'ik', 'in', 'is', 'ja', 'je ', 'kan', 'kon', 'kunnen', 'maar', 'me', 'meer',
|
|
33
|
+
'men', 'met', 'mij', 'mijn', 'moet', 'na', 'naar', 'niet', 'niets', 'nog', 'nu',
|
|
34
|
+
'of', 'om', 'omdat', 'ons', 'ook', 'op', 'over', 'reeds', 'te', 'tegen', 'toch',
|
|
35
|
+
'toen', 'tot', 'u', 'uit', 'uw', 'van', 'veel', 'voor', 'want', 'waren', 'was',
|
|
36
|
+
'wat', 'we', 'wel', 'werd', 'wezen', 'wie', 'wij', 'wil', 'worden', 'zal', 'ze',
|
|
37
|
+
'zei', 'zelf', 'zich', 'zij', 'zijn', 'zo', 'zonder', 'zou',
|
|
38
|
+
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
|
39
|
+
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '$', '1',
|
|
40
|
+
'2', '3', '4', '5', '6', '7', '8', '9', '0', '_', '-'];
|
|
41
|
+
|
|
42
|
+
// tell the world about the noise words.
|
|
43
|
+
exports.words = words;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2014, Kristoffer Brabrand
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// a list of commonly used words that have little meaning and can be excluded
|
|
24
|
+
// from analysis.
|
|
25
|
+
var words = [
|
|
26
|
+
'og','i','jeg','det','at','en','et','den','til','er','som',
|
|
27
|
+
'på','de','med','han','av','ikke','der','så','var','meg',
|
|
28
|
+
'seg','men','ett','har','om','vi','min','mitt','ha','hadde',
|
|
29
|
+
'hun','nå','over','da','ved','fra','du','ut','sin','dem',
|
|
30
|
+
'oss','opp','man','kan','hans','hvor','eller','hva','skal',
|
|
31
|
+
'selv','sjøl','her','alle','vil','bli','ble','blitt','kunne',
|
|
32
|
+
'inn','når','være','kom','noen','noe','ville','dere','som',
|
|
33
|
+
'deres','kun','ja','etter','ned','skulle','denne','for','deg',
|
|
34
|
+
'si','sine','sitt','mot','å','meget','hvorfor','dette','disse',
|
|
35
|
+
'uten','hvordan','ingen','din','ditt','blir','samme','hvilken',
|
|
36
|
+
'hvilke','sånn','inni','mellom','vår','hver','hvem','vors',
|
|
37
|
+
'hvis','både','bare','enn','fordi','før','mange','også','slik',
|
|
38
|
+
'vært','være','begge','siden','henne','hennar','hennes',
|
|
39
|
+
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '_'];
|
|
40
|
+
|
|
41
|
+
// tell the world about the noise words.
|
|
42
|
+
exports.words = words;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2011, Luís Rodrigues
|
|
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
|
+
// a list of commonly used words that have little meaning and can be excluded
|
|
24
|
+
// from analysis.
|
|
25
|
+
var words = [
|
|
26
|
+
'a',
|
|
27
|
+
'à',
|
|
28
|
+
'ao',
|
|
29
|
+
'aos',
|
|
30
|
+
'aquela',
|
|
31
|
+
'aquelas',
|
|
32
|
+
'aquele',
|
|
33
|
+
'aqueles',
|
|
34
|
+
'aquilo',
|
|
35
|
+
'as',
|
|
36
|
+
'às',
|
|
37
|
+
'até',
|
|
38
|
+
'com',
|
|
39
|
+
'como',
|
|
40
|
+
'da',
|
|
41
|
+
'das',
|
|
42
|
+
'de',
|
|
43
|
+
'dela',
|
|
44
|
+
'delas',
|
|
45
|
+
'dele',
|
|
46
|
+
'deles',
|
|
47
|
+
'depois',
|
|
48
|
+
'do',
|
|
49
|
+
'dos',
|
|
50
|
+
'e',
|
|
51
|
+
'ela',
|
|
52
|
+
'elas',
|
|
53
|
+
'ele',
|
|
54
|
+
'eles',
|
|
55
|
+
'em',
|
|
56
|
+
'entre',
|
|
57
|
+
'essa',
|
|
58
|
+
'essas',
|
|
59
|
+
'esse',
|
|
60
|
+
'esses',
|
|
61
|
+
'esta',
|
|
62
|
+
'estas',
|
|
63
|
+
'este',
|
|
64
|
+
'estes',
|
|
65
|
+
'eu',
|
|
66
|
+
'isso',
|
|
67
|
+
'isto',
|
|
68
|
+
'já',
|
|
69
|
+
'lhe',
|
|
70
|
+
'lhes',
|
|
71
|
+
'mais',
|
|
72
|
+
'mas',
|
|
73
|
+
'me',
|
|
74
|
+
'mesmo',
|
|
75
|
+
'meu',
|
|
76
|
+
'meus',
|
|
77
|
+
'minha',
|
|
78
|
+
'minhas',
|
|
79
|
+
'muito',
|
|
80
|
+
'muitos',
|
|
81
|
+
'na',
|
|
82
|
+
'não',
|
|
83
|
+
'nas',
|
|
84
|
+
'nem',
|
|
85
|
+
'no',
|
|
86
|
+
'nos',
|
|
87
|
+
'nós',
|
|
88
|
+
'nossa',
|
|
89
|
+
'nossas',
|
|
90
|
+
'nosso',
|
|
91
|
+
'nossos',
|
|
92
|
+
'num',
|
|
93
|
+
'nuns',
|
|
94
|
+
'numa',
|
|
95
|
+
'numas',
|
|
96
|
+
'o',
|
|
97
|
+
'os',
|
|
98
|
+
'ou',
|
|
99
|
+
'para',
|
|
100
|
+
'pela',
|
|
101
|
+
'pelas',
|
|
102
|
+
'pelo',
|
|
103
|
+
'pelos',
|
|
104
|
+
'por',
|
|
105
|
+
'quais',
|
|
106
|
+
'qual',
|
|
107
|
+
'quando',
|
|
108
|
+
'que',
|
|
109
|
+
'quem',
|
|
110
|
+
'se',
|
|
111
|
+
'sem',
|
|
112
|
+
'seu',
|
|
113
|
+
'seus',
|
|
114
|
+
'só',
|
|
115
|
+
'sua',
|
|
116
|
+
'suas',
|
|
117
|
+
'também',
|
|
118
|
+
'te',
|
|
119
|
+
'teu',
|
|
120
|
+
'teus',
|
|
121
|
+
'tu',
|
|
122
|
+
'tua',
|
|
123
|
+
'tuas',
|
|
124
|
+
'um',
|
|
125
|
+
'uma',
|
|
126
|
+
'umas',
|
|
127
|
+
'você',
|
|
128
|
+
'vocês',
|
|
129
|
+
'vos',
|
|
130
|
+
'vosso',
|
|
131
|
+
'vossos',
|
|
132
|
+
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '_'
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
// tell the world about the noise words.
|
|
136
|
+
exports.words = words;
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
'use strict';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* a topo sort for a digraph
|
|
26
|
+
* @param {Digraph}
|
|
27
|
+
*/
|
|
28
|
+
var Topological = function(g) {
|
|
29
|
+
this.isDag = true;
|
|
30
|
+
this.sorted = topoSort(uniqueVertexs(g.edges()), g.edges());
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Topological.prototype.isDAG = function() {
|
|
34
|
+
return this.isDag;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* get ordered vertexs of digraph
|
|
39
|
+
*/
|
|
40
|
+
Topological.prototype.order = function() {
|
|
41
|
+
return this.sorted.slice();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {Array} all vertex in digraph
|
|
46
|
+
* @param {Object} all edges in the digraph
|
|
47
|
+
*/
|
|
48
|
+
function topoSort(vertexs, edges) {
|
|
49
|
+
var sorted = [];
|
|
50
|
+
var cursor = vertexs.length,
|
|
51
|
+
visited = {},
|
|
52
|
+
i = cursor;
|
|
53
|
+
while (i--) {
|
|
54
|
+
if (!visited[i]) visit(vertexs[i], i, []);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return sorted.reverse();
|
|
58
|
+
|
|
59
|
+
function visit(vertex, i, predecessors) {
|
|
60
|
+
if(predecessors.indexOf(vertex) >= 0) {
|
|
61
|
+
throw new Error('Cyclic dependency:' + JSON.stringify(vertex));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if(visited[i]) return;
|
|
65
|
+
visited[i] = true;
|
|
66
|
+
|
|
67
|
+
var outgoing = edges.filter(function(edge) {
|
|
68
|
+
return edge.to() === vertex;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
var preds = [];
|
|
72
|
+
if(outgoing.length > 0) {
|
|
73
|
+
preds = predecessors.concat(vertex);
|
|
74
|
+
}
|
|
75
|
+
var from;
|
|
76
|
+
outgoing.forEach(function(edge) {
|
|
77
|
+
from = edge.from();
|
|
78
|
+
visit(from, vertexs.indexOf(from), preds);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
sorted[--cursor] = vertex;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
function uniqueVertexs(edges) {
|
|
87
|
+
var vertexs = [];
|
|
88
|
+
var from, to;
|
|
89
|
+
edges.forEach(function(edge) {
|
|
90
|
+
from = edge.from();
|
|
91
|
+
to = edge.to();
|
|
92
|
+
if (vertexs.indexOf(from) < 0) vertexs.push(from);
|
|
93
|
+
if (vertexs.indexOf(to) < 0) vertexs.push(to);
|
|
94
|
+
});
|
|
95
|
+
return vertexs;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
module.exports = Topological;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
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), classification, inflection, phonetics, tfidf, WordNet, jaro-winkler, Levenshtein distance, Dice's Coefficient) facilities for node.",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"homepage": "https://github.com/NaturalNode/natural",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"sylvester": ">= 0.0.12",
|
|
15
|
-
"apparatus": ">= 0.0.
|
|
15
|
+
"apparatus": ">= 0.0.9",
|
|
16
16
|
"underscore": ">=1.3.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
@@ -0,0 +1,101 @@
|
|
|
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 softwé and associated documentation files (the "Softwé"), to deal
|
|
6
|
+
in the Softwé without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Softwé, and to permit persons to whom the Softwé 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 Softwé.
|
|
13
|
+
|
|
14
|
+
THE SOFTWé 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 SOFTWé OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWé.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
var Tokenizer = require('../lib/natural/tokenizers/aggressive_tokenizer_fr'),
|
|
24
|
+
tokenizer = new Tokenizer();
|
|
25
|
+
|
|
26
|
+
var text = "Affectueusement surnommé « Gabo » dans toute l'Amérique latine, le Colombien Gabriel Garcia Marquez, prix Nobel de littérature 1982, l'un des plus grands écrivains du XXe siècle, est mort À son domicile de Mexico jeudi 17 avril. Il était âgé de 87 ans. Son Œuvre a été traduite dans toutes les langues ou presque, et vendue à quelque 50 millions d'exemplaires.";
|
|
27
|
+
|
|
28
|
+
var tokenized = [ 'Affectueusement',
|
|
29
|
+
'surnommé',
|
|
30
|
+
'Gabo',
|
|
31
|
+
'dans',
|
|
32
|
+
'toute',
|
|
33
|
+
'l',
|
|
34
|
+
'Amérique',
|
|
35
|
+
'latine',
|
|
36
|
+
'le',
|
|
37
|
+
'Colombien',
|
|
38
|
+
'Gabriel',
|
|
39
|
+
'Garcia',
|
|
40
|
+
'Marquez',
|
|
41
|
+
'prix',
|
|
42
|
+
'Nobel',
|
|
43
|
+
'de',
|
|
44
|
+
'littérature',
|
|
45
|
+
'1982',
|
|
46
|
+
'l',
|
|
47
|
+
'un',
|
|
48
|
+
'des',
|
|
49
|
+
'plus',
|
|
50
|
+
'grands',
|
|
51
|
+
'écrivains',
|
|
52
|
+
'du',
|
|
53
|
+
'XXe',
|
|
54
|
+
'siècle',
|
|
55
|
+
'est',
|
|
56
|
+
'mort',
|
|
57
|
+
'À',
|
|
58
|
+
'son',
|
|
59
|
+
'domicile',
|
|
60
|
+
'de',
|
|
61
|
+
'Mexico',
|
|
62
|
+
'jeudi',
|
|
63
|
+
'17',
|
|
64
|
+
'avril',
|
|
65
|
+
'Il',
|
|
66
|
+
'était',
|
|
67
|
+
'âgé',
|
|
68
|
+
'de',
|
|
69
|
+
'87',
|
|
70
|
+
'ans',
|
|
71
|
+
'Son',
|
|
72
|
+
'Œuvre',
|
|
73
|
+
'a',
|
|
74
|
+
'été',
|
|
75
|
+
'traduite',
|
|
76
|
+
'dans',
|
|
77
|
+
'toutes',
|
|
78
|
+
'les',
|
|
79
|
+
'langues',
|
|
80
|
+
'ou',
|
|
81
|
+
'presque',
|
|
82
|
+
'et',
|
|
83
|
+
'vendue',
|
|
84
|
+
'à',
|
|
85
|
+
'quelque',
|
|
86
|
+
'50',
|
|
87
|
+
'millions',
|
|
88
|
+
'd',
|
|
89
|
+
'exemplaires' ];
|
|
90
|
+
|
|
91
|
+
describe('aggressive_tokenizer_fr', function() {
|
|
92
|
+
it('should tokenize strings', function() {
|
|
93
|
+
expect(tokenizer.tokenize(text)).toEqual(tokenized);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should tokenize strings via attached string method', function() {
|
|
97
|
+
tokenizer.attach();
|
|
98
|
+
expect(text.tokenize()).toEqual(tokenized);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
});
|
|
File without changes
|
|
File without changes
|
|
@@ -157,5 +157,17 @@ describe('bayes classifier', function() {
|
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
159
|
});
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
it('should accept an optional smoothing parameter for the Bayesian estimates', function() {
|
|
163
|
+
var defaultClassifier = new natural.BayesClassifier();
|
|
164
|
+
var PorterStemmer = require('../lib/natural/stemmers/porter_stemmer');
|
|
165
|
+
var newClassifier1 = new natural.BayesClassifier(PorterStemmer);
|
|
166
|
+
var newClassifier2 = new natural.BayesClassifier(PorterStemmer, 0.1);
|
|
167
|
+
|
|
168
|
+
expect(defaultClassifier.classifier.smoothing).toBe(1.0);
|
|
169
|
+
expect(newClassifier1.classifier.smoothing).toBe(1.0);
|
|
170
|
+
expect(newClassifier2.classifier.smoothing).toBe(0.1);
|
|
171
|
+
});
|
|
160
172
|
});
|
|
161
173
|
});
|