natural 0.2.1 → 0.4.0

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 (106) hide show
  1. package/.npmignore +4 -11
  2. package/README.md +156 -41
  3. package/bayes_classifier.json +1 -0
  4. package/lib/natural/brill_pos_tagger/data/Dutch/README.txt +2 -0
  5. package/lib/natural/brill_pos_tagger/data/Dutch/brill_CONTEXTRULES.jg +285 -0
  6. package/lib/natural/brill_pos_tagger/data/Dutch/brill_LEXICON.jg +11699 -0
  7. package/lib/natural/brill_pos_tagger/data/English/README.txt +8 -0
  8. package/lib/natural/brill_pos_tagger/data/English/lexicon_from_posjs.json +297827 -0
  9. package/lib/natural/brill_pos_tagger/data/English/tr_from_brill_paper.txt +10 -0
  10. package/lib/natural/brill_pos_tagger/data/English/tr_from_posjs.txt +18 -0
  11. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +136 -0
  12. package/lib/natural/brill_pos_tagger/lib/Predicate.js +410 -0
  13. package/lib/natural/brill_pos_tagger/lib/TF_Parser.js +717 -0
  14. package/lib/natural/brill_pos_tagger/lib/TF_Parser.pegjs +55 -0
  15. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +49 -0
  16. package/lib/natural/classifiers/bayes_classifier.js +6 -5
  17. package/lib/natural/classifiers/classifier.js +3 -2
  18. package/lib/natural/classifiers/logistic_regression_classifier.js +9 -5
  19. package/lib/natural/distance/dice_coefficient.js +22 -12
  20. package/lib/natural/index.js +6 -0
  21. package/lib/natural/ngrams/ngrams.js +4 -0
  22. package/lib/natural/stemmers/stemmer.js +31 -6
  23. package/lib/natural/tokenizers/regexp_tokenizer.js +3 -3
  24. package/{examples/inflection/noun.js → lib/natural/tokenizers/sentence_tokenizer.js} +14 -10
  25. package/lib/natural/tokenizers/tokenizer_case.js +58 -0
  26. package/lib/natural/util/bag.js +1 -0
  27. package/lib/natural/wordnet/wordnet.js +2 -2
  28. package/lib/natural/wordnet/wordnet_file.js +1 -1
  29. package/lr_classifier.json +1 -0
  30. package/package.json +6 -3
  31. package/package.json~ +66 -0
  32. package/benchmarks/index.js +0 -32
  33. package/benchmarks/metaphone.js +0 -27
  34. package/benchmarks/soundex.js +0 -27
  35. package/examples/classification/basic.js +0 -35
  36. package/examples/classification/recall.js +0 -28
  37. package/examples/classification/store.js +0 -37
  38. package/examples/inflection/count.js +0 -35
  39. package/examples/inflection/noun_attach.js +0 -33
  40. package/examples/phonetics/compare.js +0 -39
  41. package/examples/phonetics/sounds_like.js +0 -40
  42. package/examples/phonetics/tokenize_and_phoneticize.js +0 -54
  43. package/examples/stemming/stem_corpus.js +0 -29
  44. package/examples/stemming/stem_word.js +0 -26
  45. package/examples/tfidf/array_example.js +0 -34
  46. package/examples/tfidf/multiple_terms.js +0 -33
  47. package/examples/tfidf/tfidf_example.js +0 -44
  48. package/io_spec/test_data/tfidf/one +0 -1
  49. package/io_spec/test_data/tfidf/two +0 -1
  50. package/io_spec/tfidf_spec.js +0 -50
  51. package/io_spec/wordnet_spec.js +0 -81
  52. package/spec/aggressive_tokenizer_es_spec.js +0 -36
  53. package/spec/aggressive_tokenizer_fr_spec.js +0 -101
  54. package/spec/aggressive_tokenizer_nl_spec.js +0 -36
  55. package/spec/aggressive_tokenizer_pt_spec.js +0 -56
  56. package/spec/aggressive_tokenizer_spec.js +0 -56
  57. package/spec/bayes_classifier_spec.js +0 -173
  58. package/spec/classifier_spec.js +0 -175
  59. package/spec/count_inflector_fr_spec.js +0 -44
  60. package/spec/count_inflector_spec.js +0 -73
  61. package/spec/dice_coefficient_spec.js +0 -26
  62. package/spec/double_metaphone_spec.js +0 -752
  63. package/spec/jaro-winkler_spec.js +0 -53
  64. package/spec/lancaster_stemmer_spec.js +0 -73
  65. package/spec/levenshtein_spec.js +0 -66
  66. package/spec/logistic_regression_classifier_spec.js +0 -122
  67. package/spec/longest_path_tree_spec.js +0 -102
  68. package/spec/metaphone_spec.js +0 -252
  69. package/spec/ngram_spec.js +0 -130
  70. package/spec/ngram_zh_spec.js +0 -122
  71. package/spec/normalizer_ja_spec.js +0 -160
  72. package/spec/normalizer_no_spec.js +0 -111
  73. package/spec/normalizer_spec.js +0 -140
  74. package/spec/noun_inflector_fr_spec.js +0 -476
  75. package/spec/noun_inflector_ja_spec.js +0 -112
  76. package/spec/noun_inflector_spec.js +0 -270
  77. package/spec/porter_stemmer_fr_spec.js +0 -101
  78. package/spec/porter_stemmer_it_spec.js +0 -44
  79. package/spec/porter_stemmer_no_spec.js +0 -143
  80. package/spec/porter_stemmer_pt_spec.js +0 -50
  81. package/spec/porter_stemmer_ru_spec.js +0 -63
  82. package/spec/porter_stemmer_spec.js +0 -182
  83. package/spec/present_verb_inflector_spec.js +0 -128
  84. package/spec/remove_diacritics_spec.js +0 -31
  85. package/spec/sentence_analyzer_spec.js +0 -277
  86. package/spec/shortest_path_tree_spec.js +0 -132
  87. package/spec/soundex_spec.js +0 -158
  88. package/spec/spellcheck_spec.js +0 -92
  89. package/spec/stemmer_ja_spec.js +0 -66
  90. package/spec/stemmer_token_spec.js +0 -161
  91. package/spec/test_data/snowball_fr.txt +0 -20402
  92. package/spec/test_data/snowball_it.txt +0 -35482
  93. package/spec/test_data/snowball_no.txt +0 -20628
  94. package/spec/test_data/snowball_pt.txt +0 -32016
  95. package/spec/test_data/tfdif_testcorpus.txt +0 -7
  96. package/spec/test_data/tfidf_document1.txt +0 -1
  97. package/spec/test_data/tfidf_document2.txt +0 -1
  98. package/spec/test_data/tfidf_document3.txt +0 -1
  99. package/spec/test_data/tfidf_document4.txt +0 -1
  100. package/spec/test_data/tfidf_teststopwords.txt +0 -1
  101. package/spec/test_data/wordnet_mini.sql +0 -95
  102. package/spec/tfidf_spec.js +0 -323
  103. package/spec/tokenizer_ja_spec.js +0 -58
  104. package/spec/transliterator_ja_spec.js +0 -103
  105. package/spec/treebank_word_tokenizer_spec.js +0 -36
  106. package/spec/trie_spec.js +0 -206
@@ -1,66 +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
- var StemmerJa = require('../lib/natural/stemmers/stemmer_ja');
24
- var stemmer = new StemmerJa();
25
-
26
- var test = ['コピー', 'コーヒー', 'タクシー', 'パーティー', 'パーティ', 'ヘルプ・センター'];
27
- var testResult = ['コピー', 'コーヒ', 'タクシ', 'パーティ', 'パーティ', 'ヘルプ・センタ'];
28
- var text = '明後日パーティーに行く予定がある。図書館で資料をコピーしました。';
29
-
30
- describe('StemmerJa', function() {
31
- it('should stem words', function() {
32
- for (var i = 0; i < test.length; i++) {
33
- expect(stemmer.stem(test[i])).toBe(testResult[i]);
34
- }
35
- });
36
-
37
- it('should not tokenize halfwidth katakana', function() {
38
- expect(stemmer.stem('タクシー')).toEqual('タクシー');
39
- });
40
-
41
- it('should tokenize, stem and exclude stop words (default behavior)', function() {
42
- var tokens = [
43
- '明後日', 'パーティ', '行く', '予定', // パーティー should be stemmed
44
- '図書館', '資料', 'コピー', 'まし'];
45
- expect(stemmer.tokenizeAndStem(text)).toEqual(tokens);
46
- expect(stemmer.tokenizeAndStem(text, false)).toEqual(tokens);
47
- });
48
-
49
- it('should tokenize, stem and keep stop words', function() {
50
- expect(stemmer.tokenizeAndStem(text, true)).toEqual([
51
- '明後日', 'パーティ', 'に', '行く', '予定', 'が', 'ある',
52
- '図書館', 'で', '資料', 'を', 'コピー', 'し', 'まし', 'た']);
53
- });
54
-
55
- it('should attach new methods to String', function() {
56
- stemmer.attach();
57
- expect('コーヒー'.stem()).toEqual('コーヒ');
58
- expect('コピー'.stem()).toEqual('コピー');
59
- expect('図書館で資料をコピーしました。'.tokenizeAndStem()).toEqual([
60
- '図書館', '資料', 'コピー', 'まし']);
61
- expect('図書館で資料をコピーしました。'.tokenizeAndStem(false)).toEqual([
62
- '図書館', '資料', 'コピー', 'まし']);
63
- expect('図書館で資料をコピーしました。'.tokenizeAndStem(true)).toEqual([
64
- '図書館', 'で', '資料', 'を', 'コピー', 'し', 'まし', 'た']);
65
- });
66
- });
@@ -1,161 +0,0 @@
1
- /*
2
- Copyright (c) 2014, 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
- var StemmerToken = require('../lib/natural/stemmers/token');
24
-
25
- describe('stemmer token', function () {
26
-
27
- it('should receive a string', function () {
28
- var string = 'test',
29
- token = new StemmerToken(string);
30
-
31
- expect(token.string).toBe(string);
32
- });
33
-
34
- it('should hold the original token string', function () {
35
- var string = 'test',
36
- token = new StemmerToken(string);
37
-
38
- expect(token.original).toBe(string);
39
- });
40
-
41
- it('should replace all instances of a string', function () {
42
- var string = 'tester',
43
- token = new StemmerToken(string);
44
-
45
- token.replaceAll('e', 'a');
46
- expect(token.string).toBe('tastar');
47
-
48
- token.replaceAll('ar', 'er');
49
- expect(token.string).toBe('taster');
50
-
51
- token.replaceAll('r', '');
52
- expect(token.string).toBe('taste');
53
- });
54
-
55
- it('should allow vowels to be set', function () {
56
- var vowels = 'aeiou',
57
- vowelsArray = vowels.split(''),
58
- token = new StemmerToken('');
59
-
60
- token.usingVowels(vowels);
61
- expect(token.vowels).toBe(vowels);
62
-
63
- token.usingVowels(vowelsArray);
64
- expect(token.vowels).toBe(vowelsArray);
65
- });
66
-
67
- it('should check for vowels', function () {
68
- var vowels = 'aeiou',
69
- token = new StemmerToken('test');
70
-
71
- token.usingVowels(vowels);
72
-
73
- expect(token.hasVowelAtIndex(0)).toBe(false);
74
- expect(token.hasVowelAtIndex(1)).toBe(true);
75
- expect(token.hasVowelAtIndex(99)).toBe(false);
76
-
77
- token.usingVowels(vowels.split(''));
78
-
79
- expect(token.hasVowelAtIndex(0)).toBe(false);
80
- expect(token.hasVowelAtIndex(1)).toBe(true);
81
- expect(token.hasVowelAtIndex(99)).toBe(false);
82
- });
83
-
84
- it('should find the next vowel', function () {
85
- var token = new StemmerToken('tester').usingVowels('aeiou');
86
-
87
- expect(token.nextVowelIndex(0)).toBe(1);
88
- expect(token.nextVowelIndex(1)).toBe(1);
89
- expect(token.nextVowelIndex(2)).toBe(4);
90
- expect(token.nextVowelIndex(5)).toBe(6);
91
- expect(token.nextVowelIndex(99)).toBe(6);
92
- expect(token.nextVowelIndex(-1)).toBe(6);
93
- });
94
-
95
- it('should find the next consonant', function () {
96
- var token = new StemmerToken('testee').usingVowels('aeiou');
97
-
98
- expect(token.nextConsonantIndex(0)).toBe(0);
99
- expect(token.nextConsonantIndex(1)).toBe(2);
100
- expect(token.nextConsonantIndex(5)).toBe(6);
101
- expect(token.nextConsonantIndex(99)).toBe(6);
102
- expect(token.nextConsonantIndex(-1)).toBe(6);
103
- });
104
-
105
- it('should mark regions', function() {
106
- var token = new StemmerToken('tester');
107
-
108
- token.markRegion('test', 1);
109
- expect(token.regions.test).toBe(1);
110
- });
111
-
112
- it('should mark regions with a callback', function() {
113
- var token = new StemmerToken('tester'),
114
- context = { value: 99 };
115
-
116
- token.markRegion('test', 1, function (arg) { return arg; });
117
- expect(token.regions.test).toBe(1);
118
-
119
- token.markRegion('test', [1], function (arg) { return arg; });
120
- expect(token.regions.test).toBe(1);
121
-
122
- token.markRegion('test', [1, 1], function (a1, a2) { return a1 + a2; });
123
- expect(token.regions.test).toBe(2);
124
-
125
- token.markRegion('test', null, function () { return this.string.length; });
126
- expect(token.regions.test).toBe(6);
127
-
128
- token.markRegion('test', null, function () { return this.value; }, context);
129
- expect(token.regions.test).toBe(99);
130
- });
131
-
132
- it('should check for suffixes', function() {
133
- var token = new StemmerToken('tester');
134
-
135
- expect(token.hasSuffix('er')).toBe(true);
136
- expect(token.hasSuffix('st')).toBe(false);
137
- });
138
-
139
- it('should check for suffixes within a region', function() {
140
- var token = new StemmerToken('tester').markRegion('region', 2);
141
-
142
- expect(token.hasSuffixInRegion('st', 'region')).toBe(false);
143
- expect(token.hasSuffixInRegion('ster', 'region')).toBe(true);
144
- expect(token.hasSuffixInRegion('ester', 'region')).toBe(false);
145
- });
146
-
147
- it('should replace the suffix within a region', function() {
148
- var t1 = new StemmerToken('tester').markRegion('region', 4),
149
- t2 = new StemmerToken('tester').markRegion('region', 0);
150
-
151
- t1.replaceSuffixInRegion('ter', '<s>', 'region');
152
- expect(t1.string).toBe('tester');
153
-
154
- t1.replaceSuffixInRegion('er', '<s>', 'region');
155
- expect(t1.string).toBe('test<s>');
156
-
157
- t2.replaceSuffixInRegion('protester', '<s>', 'region');
158
- expect(t2.string).toBe('tester');
159
- });
160
-
161
- });