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
package/spec/trie_spec.js DELETED
@@ -1,206 +0,0 @@
1
- /*
2
- Copyright (c) 2014 Ken Koch
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 Trie = require('../lib/natural/trie/trie');
24
-
25
- describe('trie', function() {
26
-
27
- describe("adding strings", function(){
28
-
29
- it("should add words one at a time", function(){
30
- var trie = new Trie();
31
- trie.addString("test");
32
- expect(trie.contains("test")).toBe(true);
33
-
34
- trie.addString("abcd");
35
- expect(trie.contains("abcd")).toBe(true);
36
- });
37
-
38
- it("should return true if a string is added that already existed", function(){
39
- var trie = new Trie();
40
- expect(trie.addString("test")).toBe(false);
41
- expect(trie.addString("test")).toBe(true);
42
- });
43
-
44
- it("Should add an array of strings", function(){
45
- var trie = new Trie();
46
- var testWords = ["test", "abcd", "ffff"];
47
- trie.addStrings(testWords);
48
-
49
- for (var i = testWords.length - 1; i >= 0; i--) {
50
- expect(trie.contains(testWords[i])).toBe(true);
51
- };
52
- });
53
- });
54
-
55
- describe("getSize", function(){
56
-
57
- it("should return 1 for an empty trie", function(){
58
- var trie = new Trie();
59
- expect(trie.getSize()).toBe(1);
60
- });
61
-
62
- it("should return the correct size", function(){
63
- var trie = new Trie();
64
- trie.addString("a");
65
- expect(trie.getSize()).toBe(2);
66
-
67
- trie.addString("ab");
68
- expect(trie.getSize()).toBe(3);
69
- });
70
-
71
- it("should count all branches", function(){
72
- var trie = new Trie();
73
- trie.addString("a");
74
- expect(trie.getSize()).toBe(2);
75
-
76
- trie.addString("ba");
77
- expect(trie.getSize()).toBe(4);
78
- });
79
-
80
- });
81
-
82
- describe("searching", function(){
83
-
84
- it("should not find words that haven't been added", function(){
85
- var trie = new Trie();
86
- expect(trie.contains("aaaaa")).toBe(false);
87
- });
88
-
89
- it("should not return prefixes of words that have been added as words", function(){
90
- var trie = new Trie();
91
- trie.addString("test");
92
- expect(trie.contains("test")).toBe(true);
93
- expect(trie.contains("tes")).toBe(false);
94
- });
95
-
96
- it("should not return suffixes of words that have been added as words", function(){
97
- var trie = new Trie();
98
- trie.addString("test");
99
- expect(trie.contains("test")).toBe(true);
100
- expect(trie.contains("est")).toBe(false);
101
- });
102
-
103
- it("should not find a word that falls in between two other words but has not been added", function(){
104
- var trie = new Trie();
105
- trie.addString("test");
106
- trie.addString("tested");
107
- expect(trie.contains("test")).toBe(true);
108
- expect(trie.contains("tested")).toBe(true);
109
- expect(trie.contains("teste")).toBe(false);
110
- });
111
- });
112
-
113
- describe("prefix searching", function(){
114
-
115
- it("should be able to find all full prefix matched words along a path.", function(){
116
- var trie = new Trie();
117
- trie.addStrings(["a","ab","bc","cd","abc"]);
118
- var results = trie.findMatchesOnPath("abcd");
119
- expect(results).toContain("a");
120
- expect(results).toContain("ab");
121
- expect(results).toContain("abc");
122
- expect(results).not.toContain("bc");
123
- expect(results).not.toContain("cd");
124
- });
125
-
126
- it("should be able to guess all full prefix matched words.", function(){
127
- var trie = new Trie();
128
- trie.addStrings(["a","ab","bc","cd","abc"]);
129
- var results = trie.keysWithPrefix("a");
130
- expect(results).toContain("a");
131
- expect(results).toContain("ab");
132
- expect(results).toContain("abc");
133
- expect(results).not.toContain("bc");
134
- expect(results).not.toContain("cd");
135
- results = trie.keysWithPrefix("ab");
136
- expect(results).toContain("ab");
137
- expect(results).toContain("abc");
138
- expect(results).not.toContain("a");
139
- expect(results).not.toContain("bc");
140
- expect(results).not.toContain("cd");
141
- });
142
-
143
- it("should be able to execute the find_prefix search with a match", function(){
144
- var trie = new Trie();
145
- trie.addStrings(["their", "and", "they"]);
146
- var results = trie.findPrefix("theyre");
147
- expect(results[0]).toBe("they");
148
- expect(results[1]).toBe("re");
149
- });
150
-
151
- it("should return empty array if no full prefix matches found.", function(){
152
- var trie = new Trie();
153
- trie.addStrings(["a","ab","bc","cd","abc"]);
154
- var results = trie.keysWithPrefix("not-found");
155
- expect(results.length).toEqual(0);
156
- });
157
-
158
- it("should be able to execute the find_prefix search without a match", function(){
159
- var trie = new Trie();
160
- trie.addStrings(["their", "and"]);
161
- var results = trie.findPrefix("theyre");
162
- expect(results[0]).toBe(null);
163
- expect(results[1]).toBe("yre");
164
- });
165
- });
166
-
167
- describe("case sensitivity", function(){
168
-
169
- it("should be case sensitive by default", function(){
170
- var trie = new Trie();
171
- trie.addString("test");
172
- expect(trie.contains("TEST")).toBe(false);
173
- });
174
-
175
- it("should have contains in case-insensitive mode", function(){
176
- var trie = new Trie(false);
177
- trie.addString("test");
178
- expect(trie.contains("TEST")).toBe(true);
179
- });
180
-
181
- it("should have case-insensitive contains when the strings are added with case", function(){
182
- var trie = new Trie(false);
183
- trie.addString("teSt");
184
- expect(trie.contains("test")).toBe(true);
185
- });
186
-
187
- it("should have findMatchesOnPath in case-insensitive mode", function(){
188
- var trie = new Trie(false);
189
- trie.addStrings(["a","ab","bc","cd","abc"]);
190
- var results = trie.findMatchesOnPath("ABcD");
191
- expect(results).toContain("a");
192
- expect(results).toContain("ab");
193
- expect(results).toContain("abc");
194
- expect(results).not.toContain("bc");
195
- expect(results).not.toContain("cd");
196
- });
197
-
198
- it("should have findPrefix in case-insensitive mode", function(){
199
- var trie = new Trie(false);
200
- trie.addStrings(["thEIr", "And", "theY"]);
201
- var results = trie.findPrefix("ThEyRe");
202
- expect(results[0]).toBe("they");
203
- expect(results[1]).toBe("re");
204
- });
205
- });
206
- });