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.
Files changed (134) hide show
  1. package/.editorconfig +7 -0
  2. package/LICENSE.txt +0 -0
  3. package/Makefile +0 -0
  4. package/README.md +237 -24
  5. package/benchmarks/index.js +1 -1
  6. package/benchmarks/metaphone.js +0 -0
  7. package/benchmarks/soundex.js +0 -0
  8. package/examples/classification/basic.js +0 -0
  9. package/examples/classification/recall.js +0 -0
  10. package/examples/classification/store.js +0 -0
  11. package/examples/inflection/count.js +0 -0
  12. package/examples/inflection/noun.js +0 -0
  13. package/examples/inflection/noun_attach.js +0 -0
  14. package/examples/phonetics/compare.js +0 -0
  15. package/examples/phonetics/sounds_like.js +0 -0
  16. package/examples/phonetics/tokenize_and_phoneticize.js +0 -0
  17. package/examples/stemming/stem_corpus.js +0 -0
  18. package/examples/stemming/stem_word.js +0 -0
  19. package/examples/tfidf/array_example.js +0 -0
  20. package/examples/tfidf/multiple_terms.js +0 -0
  21. package/examples/tfidf/tfidf_example.js +0 -0
  22. package/index.js +0 -0
  23. package/io_spec/test_data/tfidf/one +0 -0
  24. package/io_spec/test_data/tfidf/two +0 -0
  25. package/io_spec/tfidf_spec.js +0 -0
  26. package/io_spec/wordnet_spec.js +0 -0
  27. package/lib/natural/analyzers/sentence_analyzer.js +16 -13
  28. package/lib/natural/classifiers/bayes_classifier.js +6 -2
  29. package/lib/natural/classifiers/classifier.js +0 -0
  30. package/lib/natural/classifiers/logistic_regression_classifier.js +0 -0
  31. package/lib/natural/distance/dice_coefficient.js +0 -0
  32. package/lib/natural/distance/jaro-winkler_distance.js +13 -8
  33. package/lib/natural/distance/levenshtein_distance.js +0 -0
  34. package/lib/natural/index.js +8 -0
  35. package/lib/natural/inflectors/count_inflector.js +0 -0
  36. package/lib/natural/inflectors/form_set.js +0 -0
  37. package/lib/natural/inflectors/fr/count_inflector.js +0 -0
  38. package/lib/natural/inflectors/fr/noun_inflector.js +0 -0
  39. package/lib/natural/inflectors/ja/noun_inflector.js +0 -0
  40. package/lib/natural/inflectors/noun_inflector.js +0 -0
  41. package/lib/natural/inflectors/present_verb_inflector.js +1 -0
  42. package/lib/natural/inflectors/singular_plural_inflector.js +1 -2
  43. package/lib/natural/ngrams/ngrams.js +45 -8
  44. package/lib/natural/ngrams/ngrams_zh.js +83 -0
  45. package/lib/natural/normalizers/normalizer.js +30 -38
  46. package/lib/natural/normalizers/normalizer_ja.js +26 -8
  47. package/lib/natural/normalizers/normalizer_no.js +59 -0
  48. package/lib/natural/phonetics/double_metaphone.js +9 -4
  49. package/lib/natural/phonetics/metaphone.js +6 -1
  50. package/lib/natural/phonetics/phonetic.js +0 -0
  51. package/lib/natural/phonetics/soundex.js +11 -7
  52. package/lib/natural/spellcheck/spellcheck.js +80 -0
  53. package/lib/natural/stemmers/lancaster_rules.js +4 -4
  54. package/lib/natural/stemmers/lancaster_stemmer.js +0 -0
  55. package/lib/natural/stemmers/porter_stemmer.js +90 -63
  56. package/lib/natural/stemmers/porter_stemmer_es.js +22 -23
  57. package/lib/natural/stemmers/porter_stemmer_fr.js +377 -0
  58. package/lib/natural/stemmers/porter_stemmer_no.js +155 -0
  59. package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
  60. package/lib/natural/stemmers/stemmer.js +0 -0
  61. package/lib/natural/stemmers/stemmer_fr.js +58 -0
  62. package/lib/natural/stemmers/stemmer_no.js +61 -0
  63. package/lib/natural/stemmers/stemmer_pt.js +65 -0
  64. package/lib/natural/stemmers/token.js +163 -0
  65. package/lib/natural/tfidf/tfidf.js +50 -19
  66. package/lib/natural/tokenizers/aggressive_tokenizer.js +0 -0
  67. package/lib/natural/tokenizers/aggressive_tokenizer_es.js +0 -0
  68. package/lib/natural/tokenizers/aggressive_tokenizer_fr.js +36 -0
  69. package/lib/natural/tokenizers/aggressive_tokenizer_nl.js +0 -0
  70. package/lib/natural/tokenizers/aggressive_tokenizer_no.js +39 -0
  71. package/lib/natural/tokenizers/aggressive_tokenizer_pt.js +0 -0
  72. package/lib/natural/tokenizers/regexp_tokenizer.js +0 -0
  73. package/lib/natural/tokenizers/tokenizer.js +2 -2
  74. package/lib/natural/tokenizers/treebank_word_tokenizer.js +0 -0
  75. package/lib/natural/trie/trie.js +47 -0
  76. package/lib/natural/util/bag.js +50 -0
  77. package/lib/natural/util/edge_weighted_digraph.js +112 -0
  78. package/lib/natural/util/longest_path_tree.js +99 -0
  79. package/lib/natural/util/shortest_path_tree.js +100 -0
  80. package/lib/natural/util/stopwords.js +0 -0
  81. package/lib/natural/util/stopwords_fr.js +194 -0
  82. package/lib/natural/util/stopwords_nl.js +43 -0
  83. package/lib/natural/util/stopwords_no.js +42 -0
  84. package/lib/natural/util/stopwords_pt.js +136 -0
  85. package/lib/natural/util/topological.js +98 -0
  86. package/lib/natural/wordnet/data_file.js +0 -0
  87. package/lib/natural/wordnet/index_file.js +0 -0
  88. package/lib/natural/wordnet/wordnet.js +0 -0
  89. package/lib/natural/wordnet/wordnet_file.js +0 -0
  90. package/package.json +2 -2
  91. package/spec/aggressive_tokenizer_fr_spec.js +101 -0
  92. package/spec/aggressive_tokenizer_pt_spec.js +0 -0
  93. package/spec/aggressive_tokenizer_spec.js +0 -0
  94. package/spec/bayes_classifier_spec.js +12 -0
  95. package/spec/classifier_spec.js +84 -0
  96. package/spec/count_inflector_fr_spec.js +0 -0
  97. package/spec/count_inflector_spec.js +0 -0
  98. package/spec/dice_coefficient_spec.js +0 -0
  99. package/spec/double_metaphone_spec.js +10 -1
  100. package/spec/jaro-winkler_spec.js +0 -0
  101. package/spec/lancaster_stemmer_spec.js +10 -1
  102. package/spec/levenshtein_spec.js +0 -0
  103. package/spec/logistic_regression_classifier_spec.js +0 -0
  104. package/spec/longest_path_tree_spec.js +102 -0
  105. package/spec/metaphone_spec.js +10 -0
  106. package/spec/ngram_spec.js +61 -0
  107. package/spec/ngram_zh_spec.js +122 -0
  108. package/spec/normalizer_ja_spec.js +9 -3
  109. package/spec/normalizer_no_spec.js +111 -0
  110. package/spec/normalizer_spec.js +26 -5
  111. package/spec/noun_inflector_fr_spec.js +0 -0
  112. package/spec/noun_inflector_ja_spec.js +0 -0
  113. package/spec/noun_inflector_spec.js +0 -0
  114. package/spec/porter_stemmer_fr_spec.js +101 -0
  115. package/spec/porter_stemmer_no_spec.js +143 -0
  116. package/spec/porter_stemmer_pt_spec.js +50 -0
  117. package/spec/porter_stemmer_spec.js +49 -0
  118. package/spec/present_verb_inflector_spec.js +3 -0
  119. package/spec/remove_diacritics_spec.js +31 -0
  120. package/spec/sentence_analyzer_spec.js +248 -0
  121. package/spec/shortest_path_tree_spec.js +132 -0
  122. package/spec/soundex_spec.js +13 -9
  123. package/spec/spellcheck_spec.js +92 -0
  124. package/spec/stemmer_token_spec.js +161 -0
  125. package/spec/test_data/snowball_fr.txt +20402 -0
  126. package/spec/test_data/snowball_no.txt +20628 -0
  127. package/spec/test_data/snowball_pt.txt +32016 -0
  128. package/spec/test_data/tfdif_testcorpus.txt +0 -0
  129. package/spec/test_data/tfidf_teststopwords.txt +0 -0
  130. package/spec/test_data/wordnet_mini.sql +0 -0
  131. package/spec/tfidf_spec.js +153 -28
  132. package/spec/tokenizer_ja_spec.js +0 -0
  133. package/spec/treebank_word_tokenizer_spec.js +0 -0
  134. package/spec/trie_spec.js +27 -3
@@ -31,7 +31,6 @@ describe('normalizer', function() {
31
31
  it("should correctly normalize n't as not", function(){
32
32
  expect(JSON.stringify(normalizer.normalize_tokens(["hasn't"]))).toBe(JSON.stringify(["has", "not"]));
33
33
  expect(JSON.stringify(normalizer.normalize_tokens(["hadn't"]))).toBe(JSON.stringify(["had", "not"]));
34
- expect(JSON.stringify(normalizer.normalize_tokens(["hasn't"]))).toBe(JSON.stringify(["has", "not"]));
35
34
  expect(JSON.stringify(normalizer.normalize_tokens(["haven't"]))).toBe(JSON.stringify(["have", "not"]));
36
35
  });
37
36
 
@@ -63,7 +62,7 @@ describe('normalizer', function() {
63
62
  **/
64
63
  describe("special cases", function(){
65
64
  it("should convert can't to cannot", function(){
66
- expect(JSON.stringify(normalizer.normalize_tokens(["can't"]))).toBe(JSON.stringify(["cannot"]));
65
+ expect(JSON.stringify(normalizer.normalize_tokens(["can't"]))).toBe(JSON.stringify(["can","not"]));
67
66
  });
68
67
 
69
68
  it("should convert couldn't've as could not have", function(){
@@ -86,9 +85,9 @@ describe('normalizer', function() {
86
85
  it("should handle different cases on special case conversion", function(){
87
86
  expect(JSON.stringify(normalizer.normalize_tokens(["I'm"]))).toBe(JSON.stringify(["I", "am"]));
88
87
  expect(JSON.stringify(normalizer.normalize_tokens(["i'm"]))).toBe(JSON.stringify(["I", "am"]));
89
- expect(JSON.stringify(normalizer.normalize_tokens(["can't"]))).toBe(JSON.stringify(["cannot"]));
90
- expect(JSON.stringify(normalizer.normalize_tokens(["Can't"]))).toBe(JSON.stringify(["cannot"]));
91
- expect(JSON.stringify(normalizer.normalize_tokens(["CaN'T"]))).toBe(JSON.stringify(["cannot"]));
88
+ expect(JSON.stringify(normalizer.normalize_tokens(["can't"]))).toBe(JSON.stringify(["can", "not"]));
89
+ expect(JSON.stringify(normalizer.normalize_tokens(["Can't"]))).toBe(JSON.stringify(["can", "not"]));
90
+ expect(JSON.stringify(normalizer.normalize_tokens(["CaN'T"]))).toBe(JSON.stringify(["can", "not"]));
92
91
  expect(JSON.stringify(normalizer.normalize_tokens(["how'd"]))).toBe(JSON.stringify(["how", "did"]));
93
92
  expect(JSON.stringify(normalizer.normalize_tokens(["how'D"]))).toBe(JSON.stringify(["how", "did"]));
94
93
  expect(JSON.stringify(normalizer.normalize_tokens(["HOw'd"]))).toBe(JSON.stringify(["how", "did"]));
@@ -115,5 +114,27 @@ describe('normalizer', function() {
115
114
  expect(JSON.stringify(normalizer.normalize_tokens(["i'd"]))).toBe(JSON.stringify(["i", "would"]));
116
115
  expect(JSON.stringify(normalizer.normalize_tokens(["I'D"]))).toBe(JSON.stringify(["I", "would"]));
117
116
  });
117
+
118
+ it("should convert a string to an array for normalization", function() {
119
+ expect(JSON.stringify(normalizer.normalize_tokens("I'D"))).toBe(JSON.stringify(["I", "would"]));
120
+ });
121
+
122
+ it("should simply tokenize a string that does not match a rule", function() {
123
+ expect(JSON.stringify(normalizer.normalize_tokens(["Has", "not"]))).toBe(JSON.stringify(["Has", "not"]));
124
+ expect(JSON.stringify(normalizer.normalize_tokens(["HAs", "not"]))).toBe(JSON.stringify(["HAs", "not"]));
125
+ expect(JSON.stringify(normalizer.normalize_tokens(["has", "noT"]))).toBe(JSON.stringify(["has", "noT"]));
126
+ expect(JSON.stringify(normalizer.normalize_tokens(["It", "is"]))).toBe(JSON.stringify(["It", "is"]));
127
+ expect(JSON.stringify(normalizer.normalize_tokens(["IT", "is"]))).toBe(JSON.stringify(["IT", "is"]));
128
+ expect(JSON.stringify(normalizer.normalize_tokens(["it", "iS"]))).toBe(JSON.stringify(["it", "iS"]));
129
+ expect(JSON.stringify(normalizer.normalize_tokens(["We", "will"]))).toBe(JSON.stringify(["We", "will"]));
130
+ expect(JSON.stringify(normalizer.normalize_tokens(["WE", "will"]))).toBe(JSON.stringify(["WE", "will"]));
131
+ expect(JSON.stringify(normalizer.normalize_tokens(["we", "wiLl"]))).toBe(JSON.stringify(["we", "wiLl"]));
132
+ expect(JSON.stringify(normalizer.normalize_tokens(["How", "are"]))).toBe(JSON.stringify(["How", "are"]));
133
+ expect(JSON.stringify(normalizer.normalize_tokens(["hOW", "are"]))).toBe(JSON.stringify(["hOW", "are"]));
134
+ expect(JSON.stringify(normalizer.normalize_tokens(["how", "aRE"]))).toBe(JSON.stringify(["how", "aRE"]));
135
+ expect(JSON.stringify(normalizer.normalize_tokens(["I", "would"]))).toBe(JSON.stringify(["I", "would"]));
136
+ expect(JSON.stringify(normalizer.normalize_tokens(["i", "would"]))).toBe(JSON.stringify(["i", "would"]));
137
+ expect(JSON.stringify(normalizer.normalize_tokens(["I", "woulD"]))).toBe(JSON.stringify(["I", "woulD"]));
138
+ });
118
139
  });
119
140
  });
File without changes
File without changes
File without changes
@@ -0,0 +1,101 @@
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
+ var stemmer = require('../lib/natural/stemmers/porter_stemmer_fr');
24
+ var fs = require('fs');
25
+
26
+ describe('porter_stemmer', function() {
27
+
28
+ it('should prelude', function() {
29
+ expect(stemmer.prelude('JOUER')).toBe('joUer');
30
+ expect(stemmer.prelude('ennuie')).toBe('ennuIe');
31
+ expect(stemmer.prelude('yeux')).toBe('Yeux');
32
+ expect(stemmer.prelude('quand')).toBe('qUand');
33
+ });
34
+
35
+ it('should compute regions', function() {
36
+ expect(stemmer.regions('fameusement').r1).toBe(3);
37
+ expect(stemmer.regions('fameusement').r2).toBe(6);
38
+
39
+ expect(stemmer.regions('taii').r1).toBe(4);
40
+ expect(stemmer.regions('taii').r2).toBe(4);
41
+
42
+ expect(stemmer.regions('parade').rv).toBe(3);
43
+ expect(stemmer.regions('colet').rv).toBe(3);
44
+ expect(stemmer.regions('tapis').rv).toBe(3);
45
+ expect(stemmer.regions('aimer').rv).toBe(3);
46
+ expect(stemmer.regions('adorer').rv).toBe(3);
47
+ expect(stemmer.regions('voler').rv).toBe(2);
48
+ expect(stemmer.regions('tue').rv).toBe(2);
49
+ });
50
+
51
+ it('should compute longest suffix ends in Arr', function() {
52
+ expect(stemmer.endsinArr('voudriez', ['ez', 'iez', 'z'])).toBe('iez');
53
+ });
54
+
55
+ it('should stem some word', function() {
56
+ expect(stemmer.stem('volera')).toBe('vol');
57
+ expect(stemmer.stem('volerait')).toBe('vol');
58
+ expect(stemmer.stem('subitement')).toBe('subit');
59
+ expect(stemmer.stem('tempérament')).toBe('temper');
60
+ expect(stemmer.stem('voudriez')).toBe('voudr');
61
+ expect(stemmer.stem('vengeait')).toBe('veng');
62
+ expect(stemmer.stem('saisissement')).toBe('sais');
63
+ expect(stemmer.stem('transatlantique')).toBe('transatlant');
64
+ expect(stemmer.stem('premièrement')).toBe('premi');
65
+ expect(stemmer.stem('instruments')).toBe('instrument');
66
+ expect(stemmer.stem('trouverions')).toBe('trouv');
67
+ expect(stemmer.stem('voyiez')).toBe('voi');
68
+ expect(stemmer.stem('publicité')).toBe('publiqu');
69
+ expect(stemmer.stem('pitoyable')).toBe('pitoi');
70
+ });
71
+
72
+ it('should perform stemming on a lot of words', function() {
73
+ var ok = [];
74
+ var ko = [];
75
+ fs.readFileSync('spec/test_data/snowball_fr.txt').toString().split('\n').forEach(function(line) {
76
+ if (line) {
77
+ var fields = line.replace(/(\s)+/g, ' ').split(' ');
78
+ var stemmed = stemmer.stem(fields[0]);
79
+ var regs = stemmer.regions(fields[0]);
80
+ var txtRegions = {
81
+ r1: fields[0].substring(regs.r1),
82
+ r2: fields[0].substring(regs.r2),
83
+ rv: fields[0].substring(regs.rv)
84
+ }
85
+
86
+ if (stemmed === fields[1])
87
+ ok.push(fields[0]);
88
+ else
89
+ ko.push({
90
+ word: fields[0],
91
+ expected: fields[1],
92
+ actual: stemmed,
93
+ regions: txtRegions
94
+ });
95
+ }
96
+ });
97
+
98
+ expect(ko.length).toBe(0);
99
+ });
100
+
101
+ });
@@ -0,0 +1,143 @@
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
+ var stemmer = require('../lib/natural/stemmers/porter_stemmer_no'),
24
+ fs = require('fs');
25
+
26
+ describe('porter_stemmer_no', function() {
27
+ it('should perform step 1a', function() {
28
+ expect(stemmer.step1a('forenkla')).toBe('forenkl');
29
+ expect(stemmer.step1a('aase')).toBe('aas');
30
+ expect(stemmer.step1a('allerede')).toBe('aller');
31
+ expect(stemmer.step1a('aukande')).toBe('auk');
32
+ expect(stemmer.step1a('avbøtende')).toBe('avbøt');
33
+ expect(stemmer.step1a('avdelingane')).toBe('avdeling');
34
+ expect(stemmer.step1a('avgiftene')).toBe('avgift');
35
+ expect(stemmer.step1a('havnevirksomhetene')).toBe('havnevirksom');
36
+ expect(stemmer.step1a('heimelen')).toBe('heimel');
37
+ expect(stemmer.step1a('hovedvirksomheten')).toBe('hovedvirksom');
38
+ expect(stemmer.step1a('hovudreglar')).toBe('hovudregl');
39
+ expect(stemmer.step1a('hugger')).toBe('hugg');
40
+ expect(stemmer.step1a('importvirksomheter')).toBe('importvirksom');
41
+ expect(stemmer.step1a('ivaretas')).toBe('ivaret');
42
+ expect(stemmer.step1a('iverksettes')).toBe('iverksett');
43
+ expect(stemmer.step1a('konsekvensutredes')).toBe('konsekvensutr');
44
+ expect(stemmer.step1a('oversendes')).toBe('overs');
45
+ expect(stemmer.step1a('pensjonenes')).toBe('pensjon');
46
+ expect(stemmer.step1a('myndighetenes')).toBe('myndig');
47
+ expect(stemmer.step1a('møteleiarens')).toBe('møteleiar');
48
+ expect(stemmer.step1a('virksomhetens')).toBe('virksom');
49
+ expect(stemmer.step1a('aktørers')).toBe('aktør');
50
+ expect(stemmer.step1a('arbeidslivets')).toBe('arbeidsliv');
51
+ expect(stemmer.step1a('arbeidskapasitet')).toBe('arbeidskapasit');
52
+ expect(stemmer.step1a('arealknapphet')).toBe('arealknapp');
53
+ expect(stemmer.step1a('attgjevast')).toBe('attgjev');
54
+ });
55
+
56
+ it('should perform step 1b', function() {
57
+ expect(stemmer.step1b('hinder')).toBe('hinder');
58
+ expect(stemmer.step1b('erwerbs')).toBe('erwerb');
59
+ expect(stemmer.step1b('alltids')).toBe('alltid');
60
+ });
61
+
62
+ it('should perform step 1c', function() {
63
+ expect(stemmer.step1c('akkumulerte')).toBe('akkumuler');
64
+ expect(stemmer.step1c('akseptert')).toBe('aksepter');
65
+ });
66
+
67
+ it('should perform step 1 (a-c)', function() {
68
+ expect(stemmer.step1('andelar')).toBe('andel');
69
+ expect(stemmer.step1('andeleigar')).toBe('andeleig');
70
+ expect(stemmer.step1('andeleigarane')).toBe('andeleigar');
71
+ expect(stemmer.step1('andeleigarbok')).toBe('andeleigarbok');
72
+ expect(stemmer.step1('andelen')).toBe('andel');
73
+ expect(stemmer.step1('andelene')).toBe('andel');
74
+ expect(stemmer.step1('andeler')).toBe('andel');
75
+ expect(stemmer.step1('andelsbevis')).toBe('andelsbevis');
76
+ expect(stemmer.step1('andelsbok')).toBe('andelsbok');
77
+ expect(stemmer.step1('andelsboka')).toBe('andelsbok');
78
+ expect(stemmer.step1('andelsboligforening')).toBe('andelsboligforening');
79
+ expect(stemmer.step1('andelsboligforeninger')).toBe('andelsboligforening');
80
+ expect(stemmer.step1('andelsboligorganisation')).toBe('andelsboligorganisation');
81
+ expect(stemmer.step1('andelsboligorganisationer')).toBe('andelsboligorganisation');
82
+ expect(stemmer.step1('andelsbrev')).toBe('andelsbrev');
83
+ });
84
+
85
+ it('should perform step 2', function() {
86
+ expect(stemmer.step2('hvorvidt')).toBe('hvorvid');
87
+ expect(stemmer.step2('innovativt')).toBe('innovativ');
88
+ });
89
+
90
+ it('should perform step 3', function() {
91
+ expect(stemmer.step3('lovleg')).toBe('lov');
92
+ expect(stemmer.step3('konkurranseskadeleg')).toBe('konkurranseskad');
93
+ expect(stemmer.step3('lystig')).toBe('lyst');
94
+ expect(stemmer.step3('utrolig')).toBe('utro');
95
+ expect(stemmer.step3('utrøstelig')).toBe('utrøst');
96
+ expect(stemmer.step3('boliglov')).toBe('bolig');
97
+ expect(stemmer.step3('samvirkelov')).toBe('samvirk');
98
+ expect(stemmer.step3('arveavgiftslov')).toBe('arveavgift');
99
+ });
100
+
101
+ it('should perform stemming on a lot of words', function() {
102
+ var ok = [];
103
+ var ko = [];
104
+
105
+ fs.readFileSync('spec/test_data/snowball_no.txt').toString().split('\n').forEach(function(line) {
106
+ if (line) {
107
+ var fields = line.replace(/(\s)+/g, ' ').split(' ');
108
+ var stemmed = stemmer.stem(fields[0]);
109
+
110
+ if (stemmed === fields[1]) {
111
+ ok.push(fields[0]);
112
+ } else {
113
+ ko.push({
114
+ word: fields[0],
115
+ expected: fields[1],
116
+ actual: stemmed
117
+ });
118
+ }
119
+ }
120
+ });
121
+
122
+ expect(ko.length).toBe(0);
123
+ });
124
+
125
+ it('should perform complete stemming', function() {
126
+ expect(stemmer.step1a('forenkla')).toBe('forenkl');
127
+ expect(stemmer.step1a('aase')).toBe('aas');
128
+ expect(stemmer.step1a('allerede')).toBe('aller');
129
+ expect(stemmer.step1a('aukande')).toBe('auk');
130
+ expect(stemmer.step1a('avbøtende')).toBe('avbøt');
131
+ expect(stemmer.step1b('hinder')).toBe('hinder');
132
+ expect(stemmer.step1b('erwerbs')).toBe('erwerb');
133
+ expect(stemmer.step3('boliglov')).toBe('bolig');
134
+ expect(stemmer.step3('samvirkelov')).toBe('samvirk');
135
+ expect(stemmer.step3('arveavgiftslov')).toBe('arveavgift');
136
+ });
137
+
138
+ it('should tokenize and stem attached', function() {
139
+ stemmer.attach();
140
+ expect('forebygger vedlikeholdsbehovene'.tokenizeAndStem()).toEqual(['forebygg', 'vedlikeholdsbehov']);
141
+ expect('FOREBYGGER VEDLIKEHOLDSBEHOVENE'.tokenizeAndStem()).toEqual(['forebygg', 'vedlikeholdsbehov']);
142
+ });
143
+ });
@@ -0,0 +1,50 @@
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 PorterStemmer = require('../lib/natural/stemmers/porter_stemmer_pt'),
24
+ fs = require('fs');
25
+
26
+ describe('porter_stemmer_pt', function() {
27
+
28
+ it('should perform stemming on a lot of words', function() {
29
+ var errors = [];
30
+
31
+ fs.readFileSync('spec/test_data/snowball_pt.txt').toString().split('\n').forEach(function(line) {
32
+ if (line) {
33
+ var fields = line.replace(/\s+/g, ' ').split(' '),
34
+ stemmed = PorterStemmer.stem(fields[0]);
35
+
36
+ if (stemmed !== fields[1]) {
37
+ console.log('Error:', fields[0], 'Expected:', fields[1], 'Got:', stemmed);
38
+ errors.push({
39
+ word: fields[0],
40
+ expected: fields[1],
41
+ actual: stemmed
42
+ });
43
+ }
44
+ }
45
+ });
46
+
47
+ expect(errors.length).toBe(0);
48
+ });
49
+
50
+ });
@@ -23,6 +23,15 @@ THE SOFTWARE.
23
23
  var stemmer = require('../lib/natural/stemmers/porter_stemmer');
24
24
 
25
25
  describe('porter_stemmer', function() {
26
+ it('should categorizeGroups', function() {
27
+ expect(stemmer.categorizeGroups('syllog')).toBe('CVCVC');
28
+ expect(stemmer.categorizeGroups('gypsy')).toBe('CVCV');
29
+ });
30
+
31
+ it('should measure', function() {
32
+ expect(stemmer.measure('syllog')).toBe(2);
33
+ });
34
+
26
35
  it('should perform step 1a', function() {
27
36
  expect(stemmer.step1a('caresses')).toBe('caress');
28
37
  expect(stemmer.step1a('ponies')).toBe('poni');
@@ -125,6 +134,46 @@ describe('porter_stemmer', function() {
125
134
  expect(stemmer.stem('doing')).toBe('do');
126
135
  });
127
136
 
137
+ it('should perform stem animated to anim', function() {
138
+ expect(stemmer.stem('animated')).toBe('anim');
139
+ });
140
+
141
+ it('issue 176 - attemptReplace ed|ing', function() {
142
+ expect(stemmer.stem('aedile')).toBe('aedil');
143
+ expect(stemmer.stem('adoptedly')).toBe('adoptedli');
144
+ });
145
+
146
+ it('issue 176 - minimum length for final e', function() {
147
+ expect(stemmer.stem('ace')).toBe('ac');
148
+ });
149
+
150
+ it('issue 176 - minimum length for final s', function() {
151
+ expect(stemmer.stem('yes')).toBe('ye');
152
+ });
153
+
154
+ it('issue 176 - s/tion measure', function() {
155
+ expect(stemmer.stem('invasion')).toBe('invas');
156
+ });
157
+
158
+ it('issue 176 - vehement - step 4', function() {
159
+ expect(stemmer.stem('vehement')).toBe('vehement');
160
+ expect(stemmer.stem('syllogism')).toBe('syllog');
161
+ expect(stemmer.stem('gypsy')).toBe('gypsi');
162
+ });
163
+
164
+ it('issue 176 step 2', function() {
165
+ expect(stemmer.stem('terribly')).toBe('terribl');
166
+ expect(stemmer.stem('apology')).toBe('apolog');
167
+ });
168
+
169
+ it('issue 176 - step 5a', function() {
170
+ expect(stemmer.stem('type')).toBe('type');
171
+ });
172
+
173
+ it('issue 176 - corruptiblity', function() {
174
+ expect(stemmer.stem('corruptibility')).toBe('corrupt');
175
+ });
176
+
128
177
  it('should tokenize and stem attached', function() {
129
178
  stemmer.attach();
130
179
  expect('scoring stinks'.tokenizeAndStem()).toEqual(['score', 'stink']);
@@ -57,6 +57,7 @@ describe('present verb inflector', function() {
57
57
  it('should singularize irregular forms', function() {
58
58
  expect(inflector.singularize('are')).toBe('is');
59
59
  expect(inflector.singularize('were')).toBe('was');
60
+ expect(inflector.singularize('have')).toBe('has');
60
61
  });
61
62
 
62
63
  it('should singularize ies forms', function() {
@@ -105,6 +106,8 @@ describe('present verb inflector', function() {
105
106
  it('should pluralize irregular forms', function() {
106
107
  expect(inflector.pluralize('was')).toBe('were');
107
108
  expect(inflector.pluralize('is')).toBe('are');
109
+ expect(inflector.pluralize('am')).toBe('are');
110
+ expect(inflector.pluralize('has')).toBe('have');
108
111
  });
109
112
 
110
113
  it('should pluralize ies forms', function() {
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright (c) 2013, 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 removeDiacritics = require("../lib/natural/normalizers/remove_diacritics.js");
24
+
25
+ describe('remove_diacritics', function() {
26
+
27
+ it('should correctly remove diacritics', function () {
28
+ var original_phrase = 'piñon ça va über résumé';
29
+ expect(removeDiacritics(original_phrase)).toEqual('pinon ca va uber resume');
30
+ });
31
+ });