natural 0.1.28 → 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 (117) hide show
  1. package/.editorconfig +7 -0
  2. package/.npmignore +4 -11
  3. package/README.md +190 -50
  4. package/bayes_classifier.json +1 -0
  5. package/lib/natural/analyzers/sentence_analyzer.js +8 -5
  6. package/lib/natural/brill_pos_tagger/data/Dutch/README.txt +2 -0
  7. package/lib/natural/brill_pos_tagger/data/Dutch/brill_CONTEXTRULES.jg +285 -0
  8. package/lib/natural/brill_pos_tagger/data/Dutch/brill_LEXICON.jg +11699 -0
  9. package/lib/natural/brill_pos_tagger/data/English/README.txt +8 -0
  10. package/lib/natural/brill_pos_tagger/data/English/lexicon_from_posjs.json +297827 -0
  11. package/lib/natural/brill_pos_tagger/data/English/tr_from_brill_paper.txt +10 -0
  12. package/lib/natural/brill_pos_tagger/data/English/tr_from_posjs.txt +18 -0
  13. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +136 -0
  14. package/lib/natural/brill_pos_tagger/lib/Predicate.js +410 -0
  15. package/lib/natural/brill_pos_tagger/lib/TF_Parser.js +717 -0
  16. package/lib/natural/brill_pos_tagger/lib/TF_Parser.pegjs +55 -0
  17. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +49 -0
  18. package/lib/natural/classifiers/bayes_classifier.js +6 -5
  19. package/lib/natural/classifiers/classifier.js +3 -2
  20. package/lib/natural/classifiers/logistic_regression_classifier.js +9 -5
  21. package/lib/natural/distance/dice_coefficient.js +22 -12
  22. package/lib/natural/distance/jaro-winkler_distance.js +13 -8
  23. package/lib/natural/index.js +6 -0
  24. package/lib/natural/inflectors/present_verb_inflector.js +1 -0
  25. package/lib/natural/ngrams/ngrams.js +6 -0
  26. package/lib/natural/normalizers/normalizer_ja.js +26 -8
  27. package/lib/natural/phonetics/double_metaphone.js +9 -4
  28. package/lib/natural/phonetics/metaphone.js +4 -0
  29. package/lib/natural/phonetics/soundex.js +11 -7
  30. package/lib/natural/spellcheck/spellcheck.js +80 -0
  31. package/lib/natural/stemmers/porter_stemmer.js +90 -62
  32. package/lib/natural/stemmers/porter_stemmer_fr.js +8 -3
  33. package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
  34. package/lib/natural/stemmers/stemmer.js +31 -6
  35. package/lib/natural/stemmers/stemmer_pt.js +65 -0
  36. package/lib/natural/stemmers/token.js +163 -0
  37. package/lib/natural/tfidf/tfidf.js +49 -18
  38. package/lib/natural/tokenizers/regexp_tokenizer.js +3 -3
  39. package/{examples/inflection/noun.js → lib/natural/tokenizers/sentence_tokenizer.js} +14 -10
  40. package/lib/natural/tokenizers/tokenizer_case.js +58 -0
  41. package/lib/natural/util/bag.js +1 -0
  42. package/lib/natural/util/stopwords_pt.js +136 -0
  43. package/lib/natural/wordnet/wordnet.js +2 -2
  44. package/lib/natural/wordnet/wordnet_file.js +1 -1
  45. package/lr_classifier.json +1 -0
  46. package/package.json +7 -4
  47. package/package.json~ +66 -0
  48. package/benchmarks/index.js +0 -32
  49. package/benchmarks/metaphone.js +0 -27
  50. package/benchmarks/soundex.js +0 -27
  51. package/examples/classification/basic.js +0 -35
  52. package/examples/classification/recall.js +0 -28
  53. package/examples/classification/store.js +0 -37
  54. package/examples/inflection/count.js +0 -35
  55. package/examples/inflection/noun_attach.js +0 -33
  56. package/examples/phonetics/compare.js +0 -39
  57. package/examples/phonetics/sounds_like.js +0 -40
  58. package/examples/phonetics/tokenize_and_phoneticize.js +0 -54
  59. package/examples/stemming/stem_corpus.js +0 -29
  60. package/examples/stemming/stem_word.js +0 -26
  61. package/examples/tfidf/array_example.js +0 -34
  62. package/examples/tfidf/multiple_terms.js +0 -33
  63. package/examples/tfidf/tfidf_example.js +0 -44
  64. package/io_spec/test_data/tfidf/one +0 -1
  65. package/io_spec/test_data/tfidf/two +0 -1
  66. package/io_spec/tfidf_spec.js +0 -50
  67. package/io_spec/wordnet_spec.js +0 -81
  68. package/spec/aggressive_tokenizer_es_spec.js +0 -36
  69. package/spec/aggressive_tokenizer_fr_spec.js +0 -101
  70. package/spec/aggressive_tokenizer_nl_spec.js +0 -36
  71. package/spec/aggressive_tokenizer_pt_spec.js +0 -56
  72. package/spec/aggressive_tokenizer_spec.js +0 -56
  73. package/spec/bayes_classifier_spec.js +0 -173
  74. package/spec/classifier_spec.js +0 -91
  75. package/spec/count_inflector_fr_spec.js +0 -44
  76. package/spec/count_inflector_spec.js +0 -73
  77. package/spec/dice_coefficient_spec.js +0 -26
  78. package/spec/double_metaphone_spec.js +0 -743
  79. package/spec/jaro-winkler_spec.js +0 -53
  80. package/spec/lancaster_stemmer_spec.js +0 -73
  81. package/spec/levenshtein_spec.js +0 -66
  82. package/spec/logistic_regression_classifier_spec.js +0 -122
  83. package/spec/longest_path_tree_spec.js +0 -102
  84. package/spec/metaphone_spec.js +0 -247
  85. package/spec/ngram_spec.js +0 -130
  86. package/spec/ngram_zh_spec.js +0 -122
  87. package/spec/normalizer_ja_spec.js +0 -154
  88. package/spec/normalizer_no_spec.js +0 -111
  89. package/spec/normalizer_spec.js +0 -118
  90. package/spec/noun_inflector_fr_spec.js +0 -476
  91. package/spec/noun_inflector_ja_spec.js +0 -112
  92. package/spec/noun_inflector_spec.js +0 -270
  93. package/spec/porter_stemmer_fr_spec.js +0 -101
  94. package/spec/porter_stemmer_it_spec.js +0 -44
  95. package/spec/porter_stemmer_no_spec.js +0 -143
  96. package/spec/porter_stemmer_ru_spec.js +0 -63
  97. package/spec/porter_stemmer_spec.js +0 -137
  98. package/spec/present_verb_inflector_spec.js +0 -125
  99. package/spec/sentence_analyzer_spec.js +0 -29
  100. package/spec/shortest_path_tree_spec.js +0 -132
  101. package/spec/soundex_spec.js +0 -154
  102. package/spec/stemmer_ja_spec.js +0 -66
  103. package/spec/test_data/snowball_fr.txt +0 -20402
  104. package/spec/test_data/snowball_it.txt +0 -35482
  105. package/spec/test_data/snowball_no.txt +0 -20628
  106. package/spec/test_data/tfdif_testcorpus.txt +0 -7
  107. package/spec/test_data/tfidf_document1.txt +0 -1
  108. package/spec/test_data/tfidf_document2.txt +0 -1
  109. package/spec/test_data/tfidf_document3.txt +0 -1
  110. package/spec/test_data/tfidf_document4.txt +0 -1
  111. package/spec/test_data/tfidf_teststopwords.txt +0 -1
  112. package/spec/test_data/wordnet_mini.sql +0 -95
  113. package/spec/tfidf_spec.js +0 -198
  114. package/spec/tokenizer_ja_spec.js +0 -58
  115. package/spec/transliterator_ja_spec.js +0 -103
  116. package/spec/treebank_word_tokenizer_spec.js +0 -36
  117. package/spec/trie_spec.js +0 -206
@@ -1,91 +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
- var natural = require('lib/natural');
24
-
25
- describe('classifier', function () {
26
- describe('events emitters', function () {
27
-
28
- it('should be emitted when a document is classified', function () {
29
- var classifier = new natural.BayesClassifier();
30
- classifier.addDocument('i fixed the box', 'computing');
31
- classifier.addDocument('i write code', 'computing');
32
- classifier.addDocument('nasty script code', 'computing');
33
- classifier.addDocument('write a book', 'literature');
34
- classifier.addDocument('read a book', 'literature');
35
- classifier.addDocument('study the books', 'literature');
36
-
37
- classifier.train();
38
-
39
- var pushedEvents = [];
40
-
41
- function eventRegister(obj) {
42
- pushedEvents.push(obj);
43
- };
44
-
45
- function assertEventResults() {
46
- teardown();
47
- expect(pushedEvents[0].index).toBe(0);
48
- expect(pushedEvents[0].total).toBe(6);
49
- expect(pushedEvents.length).toBe(6);
50
- }
51
-
52
- function teardown() {
53
- classifier.events.removeListener('trainedWithDocument', eventRegister);
54
- classifier.events.removeListener('doneTraining', assertEventResults);
55
- }
56
-
57
- classifier.events.on('trainedWithDocument', eventRegister);
58
- classifier.events.on('doneTraining', assertEventResults);
59
- });
60
-
61
- it('should emit events only on an instance of Classifier', function () {
62
- var classifier = new natural.BayesClassifier();
63
- classifier.addDocument('i fixed the box', 'computing');
64
- classifier.addDocument('i write code', 'computing');
65
- classifier.addDocument('write a book', 'literature');
66
- classifier.addDocument('study the books', 'literature');
67
-
68
- var pushedEvents = [];
69
-
70
- function eventRegister(obj) {
71
- pushedEvents.push(obj);
72
- };
73
-
74
- function assertEventResults() {
75
- teardown();
76
- expect(pushedEvents.length).toBe(0);
77
- }
78
-
79
- function teardown() {
80
- classifier.events.removeListener('trainedWithDocument', eventRegister);
81
- classifier.events.removeListener('doneTraining', assertEventResults);
82
- }
83
-
84
- var classifier2 = new natural.BayesClassifier();
85
- classifier2.events.on('trainedWithDocument', eventRegister);
86
- classifier.events.on('doneTraining', assertEventResults);
87
- classifier.train();
88
- });
89
-
90
- });
91
- });
@@ -1,44 +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 CountInflector = (require('../lib/natural/inflectors/fr/count_inflector'));
24
-
25
- describe('count_inflector', function() {
26
- it('should handle 1er cases', function() {
27
- expect(CountInflector.nth(1)).toBe('1er');
28
- });
29
-
30
- it('should handle the 2e cases', function() {
31
- expect(CountInflector.nth(0)).toBe('0e');
32
- expect(CountInflector.nth(2)).toBe('2e');
33
- expect(CountInflector.nth(3)).toBe('3e');
34
- expect(CountInflector.nth(5)).toBe('5e');
35
- expect(CountInflector.nth(11)).toBe('11e');
36
- expect(CountInflector.nth(100)).toBe('100e');
37
- expect(CountInflector.nth(999)).toBe('999e');
38
- });
39
-
40
- it('should handle roman numerals', function() {
41
- expect(CountInflector.nth('I')).toBe('Ier');
42
- expect(CountInflector.nth('XX')).toBe('XXe');
43
- });
44
- });
@@ -1,73 +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
- var CountInflector = (require('../lib/natural/inflectors/count_inflector'));
24
-
25
- describe('count_inflector', function() {
26
- it('should handle 1st cases', function() {
27
- expect(CountInflector.nth(1)).toBe('1st');
28
- expect(CountInflector.nth(101)).toBe('101st');
29
- expect(CountInflector.nth(11)).toNotBe('11st');
30
- expect(CountInflector.nth(111)).toNotBe('111st');
31
- });
32
-
33
- it('should handle the 12th cases', function() {
34
- expect(CountInflector.nth(12)).toBe('12th');
35
- expect(CountInflector.nth(112)).toBe('112th');
36
- expect(CountInflector.nth(1112)).toBe('1112th');
37
- });
38
-
39
- it('should handle the 11th cases', function() {
40
- expect(CountInflector.nth(11)).toBe('11th');
41
- expect(CountInflector.nth(111)).toBe('111th');
42
- expect(CountInflector.nth(1111)).toBe('1111th');
43
- });
44
-
45
- it('should handle the 13th cases', function() {
46
- expect(CountInflector.nth(13)).toBe('13th');
47
- expect(CountInflector.nth(113)).toBe('113th');
48
- expect(CountInflector.nth(1113)).toBe('1113th');
49
- });
50
-
51
- it('should handle the th cases', function() {
52
- expect(CountInflector.nth(10)).toBe('10th');
53
- expect(CountInflector.nth(4)).toBe('4th');
54
- expect(CountInflector.nth(400)).toBe('400th');
55
- expect(CountInflector.nth(404)).toBe('404th');
56
- expect(CountInflector.nth(5)).toBe('5th');
57
- expect(CountInflector.nth(5000)).toBe('5000th');
58
- expect(CountInflector.nth(5005)).toBe('5005th');
59
- expect(CountInflector.nth(9)).toBe('9th');
60
- expect(CountInflector.nth(90009)).toBe('90009th');
61
- expect(CountInflector.nth(90000)).toBe('90000th');
62
- });
63
-
64
- it('should handle 2nd cases', function() {
65
- expect(CountInflector.nth(2)).toBe('2nd');
66
- expect(CountInflector.nth(12)).toNotBe('12nd');
67
- });
68
-
69
- it('should handle 3rd cases', function() {
70
- expect(CountInflector.nth(3)).toBe('3rd');
71
- expect(CountInflector.nth(13)).toNotBe('13rd');
72
- });
73
- });
@@ -1,26 +0,0 @@
1
- var dice = require('../lib/natural/distance/dice_coefficient');
2
-
3
- describe('dice', function () {
4
-
5
- it('should handle exact matches', function () {
6
- expect(dice('john', 'john')).toBe(1);
7
- });
8
-
9
- it('should handle total mis-matches', function () {
10
- expect(dice('john', 'matt')).toBe(0);
11
- });
12
-
13
- // Example from http://en.wikipedia.org/wiki/Dice's_coefficient
14
- it('should handle a typical case', function () {
15
- expect(dice('night', 'nacht')).toBe(0.25);
16
- });
17
-
18
- it('should sanitize case', function () {
19
- expect(dice('night', 'NIGHT')).toBe(1);
20
- });
21
-
22
- it('should sanitize spacing', function () {
23
- expect(dice('the space', 'the space')).toBe(1);
24
- });
25
-
26
- });