natural 0.2.0 → 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 (382) hide show
  1. package/.editorconfig +7 -0
  2. package/README.md +3 -3
  3. package/lib/natural/inflectors/present_verb_inflector.js +1 -0
  4. package/lib/natural/phonetics/double_metaphone.js +9 -4
  5. package/lib/natural/phonetics/metaphone.js +4 -0
  6. package/lib/natural/phonetics/soundex.js +11 -7
  7. package/lib/natural/stemmers/porter_stemmer.js +90 -62
  8. package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
  9. package/lib/natural/stemmers/stemmer_pt.js +65 -0
  10. package/lib/natural/stemmers/token.js +163 -0
  11. package/lib/natural/util/stopwords_pt.js +136 -0
  12. package/package.json +2 -2
  13. package/spec/double_metaphone_spec.js +10 -1
  14. package/spec/metaphone_spec.js +5 -0
  15. package/spec/porter_stemmer_pt_spec.js +50 -0
  16. package/spec/porter_stemmer_spec.js +45 -0
  17. package/spec/present_verb_inflector_spec.js +3 -0
  18. package/spec/soundex_spec.js +13 -9
  19. package/spec/stemmer_token_spec.js +161 -0
  20. package/spec/test_data/snowball_pt.txt +32016 -0
  21. package/coverage/coverage.json +0 -1
  22. package/coverage/lcov-report/index.html +0 -584
  23. package/coverage/lcov-report/io_spec/index.html +0 -350
  24. package/coverage/lcov-report/io_spec/tfidf_spec.js.html +0 -469
  25. package/coverage/lcov-report/lib/natural/analyzers/index.html +0 -350
  26. package/coverage/lcov-report/lib/natural/analyzers/sentence_analyzer.js.html +0 -850
  27. package/coverage/lcov-report/lib/natural/classifiers/bayes_classifier.js.html +0 -496
  28. package/coverage/lcov-report/lib/natural/classifiers/classifier.js.html +0 -823
  29. package/coverage/lcov-report/lib/natural/classifiers/index.html +0 -376
  30. package/coverage/lcov-report/lib/natural/classifiers/logistic_regression_classifier.js.html +0 -502
  31. package/coverage/lcov-report/lib/natural/distance/dice_coefficient.js.html +0 -529
  32. package/coverage/lcov-report/lib/natural/distance/index.html +0 -376
  33. package/coverage/lcov-report/lib/natural/distance/jaro-winkler_distance.js.html +0 -670
  34. package/coverage/lcov-report/lib/natural/distance/levenshtein_distance.js.html +0 -526
  35. package/coverage/lcov-report/lib/natural/index.html +0 -350
  36. package/coverage/lcov-report/lib/natural/index.js.html +0 -547
  37. package/coverage/lcov-report/lib/natural/inflectors/count_inflector.js.html +0 -484
  38. package/coverage/lcov-report/lib/natural/inflectors/form_set.js.html +0 -406
  39. package/coverage/lcov-report/lib/natural/inflectors/fr/count_inflector.js.html +0 -520
  40. package/coverage/lcov-report/lib/natural/inflectors/fr/index.html +0 -363
  41. package/coverage/lcov-report/lib/natural/inflectors/fr/noun_inflector.js.html +0 -1027
  42. package/coverage/lcov-report/lib/natural/inflectors/index.html +0 -402
  43. package/coverage/lcov-report/lib/natural/inflectors/ja/index.html +0 -350
  44. package/coverage/lcov-report/lib/natural/inflectors/ja/noun_inflector.js.html +0 -727
  45. package/coverage/lcov-report/lib/natural/inflectors/noun_inflector.js.html +0 -637
  46. package/coverage/lcov-report/lib/natural/inflectors/present_verb_inflector.js.html +0 -544
  47. package/coverage/lcov-report/lib/natural/inflectors/singular_plural_inflector.js.html +0 -649
  48. package/coverage/lcov-report/lib/natural/ngrams/index.html +0 -363
  49. package/coverage/lcov-report/lib/natural/ngrams/ngrams.js.html +0 -595
  50. package/coverage/lcov-report/lib/natural/ngrams/ngrams_zh.js.html +0 -571
  51. package/coverage/lcov-report/lib/natural/normalizers/index.html +0 -389
  52. package/coverage/lcov-report/lib/natural/normalizers/normalizer.js.html +0 -607
  53. package/coverage/lcov-report/lib/natural/normalizers/normalizer_ja.js.html +0 -2194
  54. package/coverage/lcov-report/lib/natural/normalizers/normalizer_no.js.html +0 -496
  55. package/coverage/lcov-report/lib/natural/normalizers/remove_diacritics.js.html +0 -685
  56. package/coverage/lcov-report/lib/natural/phonetics/dm_soundex.js.html +0 -1063
  57. package/coverage/lcov-report/lib/natural/phonetics/double_metaphone.js.html +0 -1840
  58. package/coverage/lcov-report/lib/natural/phonetics/index.html +0 -402
  59. package/coverage/lcov-report/lib/natural/phonetics/metaphone.js.html +0 -886
  60. package/coverage/lcov-report/lib/natural/phonetics/phonetic.js.html +0 -484
  61. package/coverage/lcov-report/lib/natural/phonetics/soundex.js.html +0 -562
  62. package/coverage/lcov-report/lib/natural/spellcheck/index.html +0 -350
  63. package/coverage/lcov-report/lib/natural/spellcheck/spellcheck.js.html +0 -562
  64. package/coverage/lcov-report/lib/natural/stemmers/index.html +0 -571
  65. package/coverage/lcov-report/lib/natural/stemmers/lancaster_rules.js.html +0 -2692
  66. package/coverage/lcov-report/lib/natural/stemmers/lancaster_stemmer.js.html +0 -544
  67. package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer.js.html +0 -937
  68. package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_es.js.html +0 -985
  69. package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_fa.js.html +0 -418
  70. package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_fr.js.html +0 -1450
  71. package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_it.js.html +0 -1018
  72. package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_no.js.html +0 -784
  73. package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_ru.js.html +0 -775
  74. package/coverage/lcov-report/lib/natural/stemmers/stemmer.js.html +0 -505
  75. package/coverage/lcov-report/lib/natural/stemmers/stemmer_es.js.html +0 -496
  76. package/coverage/lcov-report/lib/natural/stemmers/stemmer_fa.js.html +0 -484
  77. package/coverage/lcov-report/lib/natural/stemmers/stemmer_fr.js.html +0 -496
  78. package/coverage/lcov-report/lib/natural/stemmers/stemmer_it.js.html +0 -427
  79. package/coverage/lcov-report/lib/natural/stemmers/stemmer_ja.js.html +0 -736
  80. package/coverage/lcov-report/lib/natural/stemmers/stemmer_no.js.html +0 -505
  81. package/coverage/lcov-report/lib/natural/stemmers/stemmer_pl.js.html +0 -496
  82. package/coverage/lcov-report/lib/natural/stemmers/stemmer_ru.js.html +0 -496
  83. package/coverage/lcov-report/lib/natural/tfidf/index.html +0 -350
  84. package/coverage/lcov-report/lib/natural/tfidf/tfidf.js.html +0 -904
  85. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer.js.html +0 -430
  86. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_es.js.html +0 -430
  87. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_fa.js.html +0 -466
  88. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_fr.js.html +0 -430
  89. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_it.js.html +0 -430
  90. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_nl.js.html +0 -430
  91. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_no.js.html +0 -439
  92. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_pl.js.html +0 -457
  93. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_pt.js.html +0 -442
  94. package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_ru.js.html +0 -457
  95. package/coverage/lcov-report/lib/natural/tokenizers/index.html +0 -519
  96. package/coverage/lcov-report/lib/natural/tokenizers/regexp_tokenizer.js.html +0 -580
  97. package/coverage/lcov-report/lib/natural/tokenizers/tokenizer.js.html +0 -475
  98. package/coverage/lcov-report/lib/natural/tokenizers/tokenizer_ja.js.html +0 -1153
  99. package/coverage/lcov-report/lib/natural/tokenizers/treebank_word_tokenizer.js.html +0 -544
  100. package/coverage/lcov-report/lib/natural/transliterators/ja/index.html +0 -350
  101. package/coverage/lcov-report/lib/natural/transliterators/ja/index.js.html +0 -2068
  102. package/coverage/lcov-report/lib/natural/trie/index.html +0 -350
  103. package/coverage/lcov-report/lib/natural/trie/trie.js.html +0 -1012
  104. package/coverage/lcov-report/lib/natural/util/bag.js.html +0 -472
  105. package/coverage/lcov-report/lib/natural/util/edge_weighted_digraph.js.html +0 -658
  106. package/coverage/lcov-report/lib/natural/util/index.html +0 -532
  107. package/coverage/lcov-report/lib/natural/util/longest_path_tree.js.html +0 -619
  108. package/coverage/lcov-report/lib/natural/util/shortest_path_tree.js.html +0 -622
  109. package/coverage/lcov-report/lib/natural/util/stopwords.js.html +0 -445
  110. package/coverage/lcov-report/lib/natural/util/stopwords_es.js.html +0 -430
  111. package/coverage/lcov-report/lib/natural/util/stopwords_fa.js.html +0 -436
  112. package/coverage/lcov-report/lib/natural/util/stopwords_fr.js.html +0 -904
  113. package/coverage/lcov-report/lib/natural/util/stopwords_it.js.html +0 -478
  114. package/coverage/lcov-report/lib/natural/util/stopwords_ja.js.html +0 -499
  115. package/coverage/lcov-report/lib/natural/util/stopwords_no.js.html +0 -445
  116. package/coverage/lcov-report/lib/natural/util/stopwords_pl.js.html +0 -508
  117. package/coverage/lcov-report/lib/natural/util/stopwords_ru.js.html +0 -445
  118. package/coverage/lcov-report/lib/natural/util/topological.js.html +0 -616
  119. package/coverage/lcov-report/lib/natural/util/utils.js.html +0 -679
  120. package/coverage/lcov-report/lib/natural/wordnet/data_file.js.html +0 -580
  121. package/coverage/lcov-report/lib/natural/wordnet/index.html +0 -389
  122. package/coverage/lcov-report/lib/natural/wordnet/index_file.js.html +0 -742
  123. package/coverage/lcov-report/lib/natural/wordnet/wordnet.js.html +0 -829
  124. package/coverage/lcov-report/lib/natural/wordnet/wordnet_file.js.html +0 -529
  125. package/coverage/lcov-report/natural/analyzers/index.html +0 -350
  126. package/coverage/lcov-report/natural/analyzers/sentence_analyzer.js.html +0 -850
  127. package/coverage/lcov-report/natural/classifiers/bayes_classifier.js.html +0 -496
  128. package/coverage/lcov-report/natural/classifiers/classifier.js.html +0 -823
  129. package/coverage/lcov-report/natural/classifiers/index.html +0 -376
  130. package/coverage/lcov-report/natural/classifiers/logistic_regression_classifier.js.html +0 -502
  131. package/coverage/lcov-report/natural/distance/dice_coefficient.js.html +0 -529
  132. package/coverage/lcov-report/natural/distance/index.html +0 -376
  133. package/coverage/lcov-report/natural/distance/jaro-winkler_distance.js.html +0 -670
  134. package/coverage/lcov-report/natural/distance/levenshtein_distance.js.html +0 -526
  135. package/coverage/lcov-report/natural/index.html +0 -350
  136. package/coverage/lcov-report/natural/index.js.html +0 -433
  137. package/coverage/lcov-report/natural/inflectors/count_inflector.js.html +0 -484
  138. package/coverage/lcov-report/natural/inflectors/form_set.js.html +0 -406
  139. package/coverage/lcov-report/natural/inflectors/fr/index.html +0 -350
  140. package/coverage/lcov-report/natural/inflectors/fr/noun_inflector.js.html +0 -1027
  141. package/coverage/lcov-report/natural/inflectors/index.html +0 -402
  142. package/coverage/lcov-report/natural/inflectors/ja/index.html +0 -350
  143. package/coverage/lcov-report/natural/inflectors/ja/noun_inflector.js.html +0 -727
  144. package/coverage/lcov-report/natural/inflectors/noun_inflector.js.html +0 -637
  145. package/coverage/lcov-report/natural/inflectors/present_verb_inflector.js.html +0 -544
  146. package/coverage/lcov-report/natural/inflectors/singular_plural_inflector.js.html +0 -649
  147. package/coverage/lcov-report/natural/lib/natural/analyzers/index.html +0 -350
  148. package/coverage/lcov-report/natural/lib/natural/analyzers/sentence_analyzer.js.html +0 -850
  149. package/coverage/lcov-report/natural/lib/natural/classifiers/bayes_classifier.js.html +0 -496
  150. package/coverage/lcov-report/natural/lib/natural/classifiers/classifier.js.html +0 -823
  151. package/coverage/lcov-report/natural/lib/natural/classifiers/index.html +0 -376
  152. package/coverage/lcov-report/natural/lib/natural/classifiers/logistic_regression_classifier.js.html +0 -502
  153. package/coverage/lcov-report/natural/lib/natural/distance/dice_coefficient.js.html +0 -529
  154. package/coverage/lcov-report/natural/lib/natural/distance/index.html +0 -376
  155. package/coverage/lcov-report/natural/lib/natural/distance/jaro-winkler_distance.js.html +0 -670
  156. package/coverage/lcov-report/natural/lib/natural/distance/levenshtein_distance.js.html +0 -526
  157. package/coverage/lcov-report/natural/lib/natural/index.html +0 -350
  158. package/coverage/lcov-report/natural/lib/natural/index.js.html +0 -547
  159. package/coverage/lcov-report/natural/lib/natural/inflectors/count_inflector.js.html +0 -484
  160. package/coverage/lcov-report/natural/lib/natural/inflectors/form_set.js.html +0 -406
  161. package/coverage/lcov-report/natural/lib/natural/inflectors/fr/index.html +0 -350
  162. package/coverage/lcov-report/natural/lib/natural/inflectors/fr/noun_inflector.js.html +0 -1027
  163. package/coverage/lcov-report/natural/lib/natural/inflectors/index.html +0 -402
  164. package/coverage/lcov-report/natural/lib/natural/inflectors/ja/index.html +0 -350
  165. package/coverage/lcov-report/natural/lib/natural/inflectors/ja/noun_inflector.js.html +0 -727
  166. package/coverage/lcov-report/natural/lib/natural/inflectors/noun_inflector.js.html +0 -637
  167. package/coverage/lcov-report/natural/lib/natural/inflectors/present_verb_inflector.js.html +0 -544
  168. package/coverage/lcov-report/natural/lib/natural/inflectors/singular_plural_inflector.js.html +0 -649
  169. package/coverage/lcov-report/natural/lib/natural/ngrams/index.html +0 -363
  170. package/coverage/lcov-report/natural/lib/natural/ngrams/ngrams.js.html +0 -595
  171. package/coverage/lcov-report/natural/lib/natural/ngrams/ngrams_zh.js.html +0 -571
  172. package/coverage/lcov-report/natural/lib/natural/normalizers/index.html +0 -389
  173. package/coverage/lcov-report/natural/lib/natural/normalizers/normalizer.js.html +0 -607
  174. package/coverage/lcov-report/natural/lib/natural/normalizers/normalizer_ja.js.html +0 -2194
  175. package/coverage/lcov-report/natural/lib/natural/normalizers/normalizer_no.js.html +0 -496
  176. package/coverage/lcov-report/natural/lib/natural/normalizers/remove_diacritics.js.html +0 -685
  177. package/coverage/lcov-report/natural/lib/natural/phonetics/dm_soundex.js.html +0 -1063
  178. package/coverage/lcov-report/natural/lib/natural/phonetics/double_metaphone.js.html +0 -1840
  179. package/coverage/lcov-report/natural/lib/natural/phonetics/index.html +0 -402
  180. package/coverage/lcov-report/natural/lib/natural/phonetics/metaphone.js.html +0 -886
  181. package/coverage/lcov-report/natural/lib/natural/phonetics/phonetic.js.html +0 -484
  182. package/coverage/lcov-report/natural/lib/natural/phonetics/soundex.js.html +0 -562
  183. package/coverage/lcov-report/natural/lib/natural/stemmers/index.html +0 -571
  184. package/coverage/lcov-report/natural/lib/natural/stemmers/lancaster_rules.js.html +0 -2692
  185. package/coverage/lcov-report/natural/lib/natural/stemmers/lancaster_stemmer.js.html +0 -544
  186. package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer.js.html +0 -937
  187. package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_es.js.html +0 -985
  188. package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_fa.js.html +0 -418
  189. package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_fr.js.html +0 -1450
  190. package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_it.js.html +0 -1018
  191. package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_no.js.html +0 -784
  192. package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_ru.js.html +0 -775
  193. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer.js.html +0 -505
  194. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_es.js.html +0 -496
  195. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_fa.js.html +0 -484
  196. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_fr.js.html +0 -496
  197. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_it.js.html +0 -427
  198. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_ja.js.html +0 -736
  199. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_no.js.html +0 -505
  200. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_pl.js.html +0 -496
  201. package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_ru.js.html +0 -496
  202. package/coverage/lcov-report/natural/lib/natural/tfidf/index.html +0 -350
  203. package/coverage/lcov-report/natural/lib/natural/tfidf/tfidf.js.html +0 -904
  204. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer.js.html +0 -430
  205. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_es.js.html +0 -430
  206. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_fa.js.html +0 -466
  207. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_fr.js.html +0 -430
  208. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_it.js.html +0 -430
  209. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_nl.js.html +0 -430
  210. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_no.js.html +0 -439
  211. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_pl.js.html +0 -457
  212. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_pt.js.html +0 -442
  213. package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_ru.js.html +0 -457
  214. package/coverage/lcov-report/natural/lib/natural/tokenizers/index.html +0 -519
  215. package/coverage/lcov-report/natural/lib/natural/tokenizers/regexp_tokenizer.js.html +0 -580
  216. package/coverage/lcov-report/natural/lib/natural/tokenizers/tokenizer.js.html +0 -475
  217. package/coverage/lcov-report/natural/lib/natural/tokenizers/tokenizer_ja.js.html +0 -1153
  218. package/coverage/lcov-report/natural/lib/natural/tokenizers/treebank_word_tokenizer.js.html +0 -544
  219. package/coverage/lcov-report/natural/lib/natural/transliterators/ja/index.html +0 -350
  220. package/coverage/lcov-report/natural/lib/natural/transliterators/ja/index.js.html +0 -2068
  221. package/coverage/lcov-report/natural/lib/natural/trie/index.html +0 -350
  222. package/coverage/lcov-report/natural/lib/natural/trie/trie.js.html +0 -1012
  223. package/coverage/lcov-report/natural/lib/natural/util/bag.js.html +0 -472
  224. package/coverage/lcov-report/natural/lib/natural/util/edge_weighted_digraph.js.html +0 -658
  225. package/coverage/lcov-report/natural/lib/natural/util/index.html +0 -532
  226. package/coverage/lcov-report/natural/lib/natural/util/longest_path_tree.js.html +0 -619
  227. package/coverage/lcov-report/natural/lib/natural/util/shortest_path_tree.js.html +0 -622
  228. package/coverage/lcov-report/natural/lib/natural/util/stopwords.js.html +0 -445
  229. package/coverage/lcov-report/natural/lib/natural/util/stopwords_es.js.html +0 -430
  230. package/coverage/lcov-report/natural/lib/natural/util/stopwords_fa.js.html +0 -436
  231. package/coverage/lcov-report/natural/lib/natural/util/stopwords_fr.js.html +0 -904
  232. package/coverage/lcov-report/natural/lib/natural/util/stopwords_it.js.html +0 -478
  233. package/coverage/lcov-report/natural/lib/natural/util/stopwords_ja.js.html +0 -499
  234. package/coverage/lcov-report/natural/lib/natural/util/stopwords_no.js.html +0 -445
  235. package/coverage/lcov-report/natural/lib/natural/util/stopwords_pl.js.html +0 -508
  236. package/coverage/lcov-report/natural/lib/natural/util/stopwords_ru.js.html +0 -445
  237. package/coverage/lcov-report/natural/lib/natural/util/topological.js.html +0 -616
  238. package/coverage/lcov-report/natural/lib/natural/util/utils.js.html +0 -679
  239. package/coverage/lcov-report/natural/lib/natural/wordnet/data_file.js.html +0 -580
  240. package/coverage/lcov-report/natural/lib/natural/wordnet/index.html +0 -389
  241. package/coverage/lcov-report/natural/lib/natural/wordnet/index_file.js.html +0 -742
  242. package/coverage/lcov-report/natural/lib/natural/wordnet/wordnet.js.html +0 -829
  243. package/coverage/lcov-report/natural/lib/natural/wordnet/wordnet_file.js.html +0 -529
  244. package/coverage/lcov-report/natural/ngrams/index.html +0 -363
  245. package/coverage/lcov-report/natural/ngrams/ngrams.js.html +0 -595
  246. package/coverage/lcov-report/natural/ngrams/ngrams_zh.js.html +0 -571
  247. package/coverage/lcov-report/natural/normalizers/index.html +0 -389
  248. package/coverage/lcov-report/natural/normalizers/normalizer.js.html +0 -607
  249. package/coverage/lcov-report/natural/normalizers/normalizer_ja.js.html +0 -2194
  250. package/coverage/lcov-report/natural/normalizers/normalizer_no.js.html +0 -496
  251. package/coverage/lcov-report/natural/normalizers/remove_diacritics.js.html +0 -685
  252. package/coverage/lcov-report/natural/phonetics/dm_soundex.js.html +0 -1063
  253. package/coverage/lcov-report/natural/phonetics/double_metaphone.js.html +0 -1840
  254. package/coverage/lcov-report/natural/phonetics/index.html +0 -402
  255. package/coverage/lcov-report/natural/phonetics/metaphone.js.html +0 -886
  256. package/coverage/lcov-report/natural/phonetics/phonetic.js.html +0 -484
  257. package/coverage/lcov-report/natural/phonetics/soundex.js.html +0 -562
  258. package/coverage/lcov-report/natural/stemmers/index.html +0 -571
  259. package/coverage/lcov-report/natural/stemmers/lancaster_rules.js.html +0 -2692
  260. package/coverage/lcov-report/natural/stemmers/lancaster_stemmer.js.html +0 -544
  261. package/coverage/lcov-report/natural/stemmers/porter_stemmer.js.html +0 -937
  262. package/coverage/lcov-report/natural/stemmers/porter_stemmer_es.js.html +0 -985
  263. package/coverage/lcov-report/natural/stemmers/porter_stemmer_fa.js.html +0 -418
  264. package/coverage/lcov-report/natural/stemmers/porter_stemmer_fr.js.html +0 -1450
  265. package/coverage/lcov-report/natural/stemmers/porter_stemmer_it.js.html +0 -1018
  266. package/coverage/lcov-report/natural/stemmers/porter_stemmer_no.js.html +0 -784
  267. package/coverage/lcov-report/natural/stemmers/porter_stemmer_ru.js.html +0 -775
  268. package/coverage/lcov-report/natural/stemmers/stemmer.js.html +0 -505
  269. package/coverage/lcov-report/natural/stemmers/stemmer_es.js.html +0 -496
  270. package/coverage/lcov-report/natural/stemmers/stemmer_fa.js.html +0 -484
  271. package/coverage/lcov-report/natural/stemmers/stemmer_fr.js.html +0 -496
  272. package/coverage/lcov-report/natural/stemmers/stemmer_it.js.html +0 -427
  273. package/coverage/lcov-report/natural/stemmers/stemmer_ja.js.html +0 -736
  274. package/coverage/lcov-report/natural/stemmers/stemmer_no.js.html +0 -505
  275. package/coverage/lcov-report/natural/stemmers/stemmer_pl.js.html +0 -496
  276. package/coverage/lcov-report/natural/stemmers/stemmer_ru.js.html +0 -496
  277. package/coverage/lcov-report/natural/tfidf/index.html +0 -350
  278. package/coverage/lcov-report/natural/tfidf/tfidf.js.html +0 -904
  279. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer.js.html +0 -430
  280. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_es.js.html +0 -430
  281. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_fa.js.html +0 -466
  282. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_fr.js.html +0 -430
  283. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_it.js.html +0 -430
  284. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_nl.js.html +0 -430
  285. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_no.js.html +0 -439
  286. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_pl.js.html +0 -457
  287. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_pt.js.html +0 -442
  288. package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_ru.js.html +0 -457
  289. package/coverage/lcov-report/natural/tokenizers/index.html +0 -519
  290. package/coverage/lcov-report/natural/tokenizers/regexp_tokenizer.js.html +0 -580
  291. package/coverage/lcov-report/natural/tokenizers/tokenizer.js.html +0 -475
  292. package/coverage/lcov-report/natural/tokenizers/tokenizer_ja.js.html +0 -1153
  293. package/coverage/lcov-report/natural/tokenizers/treebank_word_tokenizer.js.html +0 -544
  294. package/coverage/lcov-report/natural/transliterators/ja/index.html +0 -350
  295. package/coverage/lcov-report/natural/transliterators/ja/index.js.html +0 -2068
  296. package/coverage/lcov-report/natural/trie/index.html +0 -350
  297. package/coverage/lcov-report/natural/trie/trie.js.html +0 -1012
  298. package/coverage/lcov-report/natural/util/bag.js.html +0 -472
  299. package/coverage/lcov-report/natural/util/edge_weighted_digraph.js.html +0 -658
  300. package/coverage/lcov-report/natural/util/index.html +0 -532
  301. package/coverage/lcov-report/natural/util/longest_path_tree.js.html +0 -619
  302. package/coverage/lcov-report/natural/util/shortest_path_tree.js.html +0 -622
  303. package/coverage/lcov-report/natural/util/stopwords.js.html +0 -445
  304. package/coverage/lcov-report/natural/util/stopwords_es.js.html +0 -430
  305. package/coverage/lcov-report/natural/util/stopwords_fa.js.html +0 -436
  306. package/coverage/lcov-report/natural/util/stopwords_fr.js.html +0 -904
  307. package/coverage/lcov-report/natural/util/stopwords_it.js.html +0 -478
  308. package/coverage/lcov-report/natural/util/stopwords_ja.js.html +0 -499
  309. package/coverage/lcov-report/natural/util/stopwords_no.js.html +0 -445
  310. package/coverage/lcov-report/natural/util/stopwords_pl.js.html +0 -508
  311. package/coverage/lcov-report/natural/util/stopwords_ru.js.html +0 -445
  312. package/coverage/lcov-report/natural/util/topological.js.html +0 -616
  313. package/coverage/lcov-report/natural/util/utils.js.html +0 -679
  314. package/coverage/lcov-report/natural/wordnet/data_file.js.html +0 -580
  315. package/coverage/lcov-report/natural/wordnet/index.html +0 -389
  316. package/coverage/lcov-report/natural/wordnet/index_file.js.html +0 -742
  317. package/coverage/lcov-report/natural/wordnet/wordnet.js.html +0 -829
  318. package/coverage/lcov-report/natural/wordnet/wordnet_file.js.html +0 -529
  319. package/coverage/lcov-report/normalizers/index.html +0 -350
  320. package/coverage/lcov-report/normalizers/normalizer.js.html +0 -607
  321. package/coverage/lcov-report/prettify.css +0 -1
  322. package/coverage/lcov-report/prettify.js +0 -1
  323. package/coverage/lcov-report/spec/aggressive_tokenizer_es_spec.js.html +0 -430
  324. package/coverage/lcov-report/spec/aggressive_tokenizer_fr_spec.js.html +0 -625
  325. package/coverage/lcov-report/spec/aggressive_tokenizer_nl_spec.js.html +0 -430
  326. package/coverage/lcov-report/spec/aggressive_tokenizer_pt_spec.js.html +0 -490
  327. package/coverage/lcov-report/spec/aggressive_tokenizer_spec.js.html +0 -490
  328. package/coverage/lcov-report/spec/bayes_classifier_spec.js.html +0 -841
  329. package/coverage/lcov-report/spec/classifier_spec.js.html +0 -847
  330. package/coverage/lcov-report/spec/count_inflector_fr_spec.js.html +0 -454
  331. package/coverage/lcov-report/spec/count_inflector_spec.js.html +0 -538
  332. package/coverage/lcov-report/spec/dice_coefficient_spec.js.html +0 -400
  333. package/coverage/lcov-report/spec/double_metaphone_spec.js.html +0 -2548
  334. package/coverage/lcov-report/spec/index.html +0 -883
  335. package/coverage/lcov-report/spec/jaro-winkler_spec.js.html +0 -481
  336. package/coverage/lcov-report/spec/lancaster_stemmer_spec.js.html +0 -541
  337. package/coverage/lcov-report/spec/levenshtein_spec.js.html +0 -520
  338. package/coverage/lcov-report/spec/logistic_regression_classifier_spec.js.html +0 -688
  339. package/coverage/lcov-report/spec/longest_path_tree_spec.js.html +0 -628
  340. package/coverage/lcov-report/spec/metaphone_spec.js.html +0 -1063
  341. package/coverage/lcov-report/spec/ngram_spec.js.html +0 -712
  342. package/coverage/lcov-report/spec/ngram_zh_spec.js.html +0 -688
  343. package/coverage/lcov-report/spec/normalizer_ja_spec.js.html +0 -802
  344. package/coverage/lcov-report/spec/normalizer_no_spec.js.html +0 -655
  345. package/coverage/lcov-report/spec/normalizer_spec.js.html +0 -742
  346. package/coverage/lcov-report/spec/noun_inflector_fr_spec.js.html +0 -1750
  347. package/coverage/lcov-report/spec/noun_inflector_ja_spec.js.html +0 -658
  348. package/coverage/lcov-report/spec/noun_inflector_spec.js.html +0 -1132
  349. package/coverage/lcov-report/spec/porter_stemmer_fr_spec.js.html +0 -625
  350. package/coverage/lcov-report/spec/porter_stemmer_it_spec.js.html +0 -454
  351. package/coverage/lcov-report/spec/porter_stemmer_no_spec.js.html +0 -751
  352. package/coverage/lcov-report/spec/porter_stemmer_ru_spec.js.html +0 -511
  353. package/coverage/lcov-report/spec/porter_stemmer_spec.js.html +0 -733
  354. package/coverage/lcov-report/spec/present_verb_inflector_spec.js.html +0 -697
  355. package/coverage/lcov-report/spec/remove_diacritics_spec.js.html +0 -415
  356. package/coverage/lcov-report/spec/sentence_analyzer_spec.js.html +0 -1153
  357. package/coverage/lcov-report/spec/shortest_path_tree_spec.js.html +0 -718
  358. package/coverage/lcov-report/spec/soundex_spec.js.html +0 -784
  359. package/coverage/lcov-report/spec/spellcheck_spec.js.html +0 -598
  360. package/coverage/lcov-report/spec/stemmer_ja_spec.js.html +0 -520
  361. package/coverage/lcov-report/spec/tfidf_spec.js.html +0 -1288
  362. package/coverage/lcov-report/spec/tokenizer_ja_spec.js.html +0 -496
  363. package/coverage/lcov-report/spec/transliterator_ja_spec.js.html +0 -631
  364. package/coverage/lcov-report/spec/treebank_word_tokenizer_spec.js.html +0 -430
  365. package/coverage/lcov-report/spec/trie_spec.js.html +0 -940
  366. package/coverage/lcov-report/util/index.html +0 -350
  367. package/coverage/lcov-report/util/utils.js.html +0 -679
  368. package/coverage/lcov.info +0 -11094
  369. package/lib/natural/parsers/Agenda.js +0 -68
  370. package/lib/natural/parsers/CYKParser.js +0 -87
  371. package/lib/natural/parsers/CYK_Item.js +0 -159
  372. package/lib/natural/parsers/Chart.js +0 -211
  373. package/lib/natural/parsers/ChartParser.js +0 -60
  374. package/lib/natural/parsers/DoubleDottedItem.js +0 -226
  375. package/lib/natural/parsers/EarleyItem.js +0 -155
  376. package/lib/natural/parsers/EarleyParser.js +0 -58
  377. package/lib/natural/parsers/FunctionWordTagger.js +0 -84
  378. package/lib/natural/parsers/GoalItem.js +0 -206
  379. package/lib/natural/parsers/GrammarParser.js +0 -1289
  380. package/lib/natural/parsers/HeadCornerParser.js +0 -101
  381. package/lib/natural/parsers/LeftCornerParser.js +0 -58
  382. package/lib/natural/parsers/PEG-grammar-for-unification-grammar.txt +0 -345
package/.editorconfig ADDED
@@ -0,0 +1,7 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+ indent_style = space
7
+ indent_size = 2
package/README.md CHANGED
@@ -184,7 +184,7 @@ tokenize and stem the text.
184
184
 
185
185
  ```javascript
186
186
  classifier.addDocument('i am long qqqq', 'buy');
187
- classifier.addDocument('buy the q''s', 'buy');
187
+ classifier.addDocument('buy the q\'s', 'buy');
188
188
  classifier.addDocument('short gold', 'sell');
189
189
  classifier.addDocument('sell gold', 'sell');
190
190
 
@@ -208,8 +208,8 @@ You have access to the set of matched classes and the associated value from the
208
208
  Outputs:
209
209
 
210
210
  ```javascript
211
- [ { label: 'sell', value: 0.39999999999999997 },
212
- { label: 'buy', value: 0.19999999999999998 } ]
211
+ [ { label: 'buy', value: 0.39999999999999997 },
212
+ { label: 'sell', value: 0.19999999999999998 } ]
213
213
  ```
214
214
 
215
215
  From this:
@@ -51,6 +51,7 @@ var VerbInflector = function() {
51
51
  this.addIrregular("am", "are");
52
52
  this.addIrregular("is", "are");
53
53
  this.addIrregular("was", "were");
54
+ this.addIrregular("has", "have");
54
55
 
55
56
  this.singularForms.regularForms.push([/ed$/i, 'ed']);
56
57
  this.singularForms.regularForms.push([/ss$/i, 'sses']);
@@ -66,7 +66,8 @@ function process(token, maxLength) {
66
66
  }
67
67
 
68
68
  function handleC() {
69
- if(pos > 1 && !isVowel(token[pos - 2])
69
+
70
+ if(pos >= 1 && !isVowel(token[pos - 2])
70
71
  && token[pos - 1] == 'A' && token[pos + 1] == 'H'
71
72
  && (token[pos + 2] != 'I' && token[pos + 2] != 'I')
72
73
  || subMatch(-2, 4, ['BACHER', 'MACHER'])) {
@@ -74,7 +75,9 @@ function process(token, maxLength) {
74
75
  pos++;
75
76
  } else if(pos == 0 && token.substring(1, 6) == 'EASAR') {
76
77
  add('S');
77
- pos++;
78
+ add('S');
79
+ add('R');
80
+ pos += 6;
78
81
  } else if(token.substring(pos + 1, pos + 4) == 'HIA') {
79
82
  add('K');
80
83
  pos++;
@@ -84,7 +87,7 @@ function process(token, maxLength) {
84
87
  pos++;
85
88
  } else if(pos == 0
86
89
  && (subMatch(1, 6, ['HARAC', 'HARIS'])
87
- || subMatch(1, 3, ['HOR', 'HUM', 'HIA', 'HEM']))
90
+ || subMatch(1, 4, ['HOR', 'HUM', 'HIA', 'HEM']))
88
91
  && token.substring(pos + 1, pos + 5) != 'HORE') {
89
92
  add('K');
90
93
  pos++;
@@ -96,6 +99,7 @@ function process(token, maxLength) {
96
99
  && subMatch(2, 3, ['B', 'F', 'H', 'L', 'M', 'N', 'R', 'V', 'W']))) {
97
100
  add('K');
98
101
  } else if(pos > 0) {
102
+
99
103
  if(token.substring(0, 2) == 'MC') {
100
104
  add('K');
101
105
  } else {
@@ -415,6 +419,7 @@ function process(token, maxLength) {
415
419
  }
416
420
 
417
421
  while(pos < token.length) {
422
+
418
423
  switch(token[pos]) {
419
424
  case 'A': case 'E': case 'I': case 'O': case 'U': case 'Y':
420
425
  case 'Ê': case 'É': case 'É': case'À':
@@ -488,7 +493,7 @@ function process(token, maxLength) {
488
493
  }
489
494
 
490
495
  pos++;
491
- }
496
+ }
492
497
 
493
498
  return [truncate(primary, maxLength), truncate(secondary, maxLength)];
494
499
  }
@@ -38,7 +38,11 @@ function dropBafterMAtEnd(token) {
38
38
  }
39
39
 
40
40
  function cTransform(token) {
41
+
42
+
41
43
  token = token.replace(/([^s]|^)(c)(h)/g, '$1x$3').trim();
44
+
45
+
42
46
  token = token.replace(/cia/g, 'xia');
43
47
  token = token.replace(/c(i|e|y)/g, 's$1');
44
48
  token = token.replace(/c/g, 'k');
@@ -47,7 +47,7 @@ function transformR(token) {
47
47
  }
48
48
 
49
49
  function condense(token) {
50
- return token.replace(/(\d)[hw]?\1+/g, '$1').replace(/[hw]/g, '');
50
+ return token.replace(/(\d)?\1+/g, '$1');
51
51
  }
52
52
 
53
53
  function padRight0(token) {
@@ -57,16 +57,20 @@ function padRight0(token) {
57
57
  return token;
58
58
  }
59
59
 
60
+ function transform(token) {
61
+ return transformLipps(transformThroats(
62
+ transformToungue(transformL(transformHum(transformR(token))))));
63
+ }
64
+
60
65
  var SoundEx = new Phonetic();
61
66
  module.exports = SoundEx;
62
67
 
63
68
  SoundEx.process = function(token, maxLength) {
64
- token = token.toLowerCase();
65
-
66
- return token.charAt(0).toUpperCase() + padRight0(condense(transformLipps(transformThroats(
67
- transformToungue(transformL(transformHum(transformR(
68
- token.substr(1, token.length - 1).replace(/[aeiouy]/g, '')))))))
69
- )).substr(0, (maxLength && maxLength - 1) || 3);
69
+ token = token.toLowerCase();
70
+ var transformed = condense(transform(token.substr(1, token.length - 1))); // anything that isn't a digit goes
71
+ // deal with duplicate INITIAL consonant SOUNDS
72
+ transformed = transformed.replace(new RegExp("^" + transform(token.charAt(0))), '');
73
+ return token.charAt(0).toUpperCase() + padRight0(transformed.replace(/\D/g, '')).substr(0, (maxLength && maxLength - 1) || 3);
70
74
  };
71
75
 
72
76
  // export for tests;
@@ -25,19 +25,19 @@ var Stemmer = require('./stemmer');
25
25
  // denote groups of consecutive consonants with a C and consecutive vowels
26
26
  // with a V.
27
27
  function categorizeGroups(token) {
28
- return token.replace(/[^aeiou]+/g, 'C').replace(/[aeiouy]+/g, 'V');
28
+ return token.replace(/[^aeiouy]+y/g, 'CV').replace(/[aeiou]+/g, 'V').replace(/[^V]+/g, 'C');
29
29
  }
30
30
 
31
31
  // denote single consonants with a C and single vowels with a V
32
32
  function categorizeChars(token) {
33
- return token.replace(/[^aeiou]/g, 'C').replace(/[aeiouy]/g, 'V');
33
+ return token.replace(/[^aeiouy]y/g, 'CV').replace(/[aeiou]/g, 'V').replace(/[^V]/g, 'C');
34
34
  }
35
35
 
36
36
  // calculate the "measure" M of a word. M is the count of VC sequences dropping
37
37
  // an initial C if it exists and a trailing V if it exists.
38
38
  function measure(token) {
39
39
  if(!token)
40
- return -1;
40
+ return -1;
41
41
 
42
42
  return categorizeGroups(token).replace(/^C/, '').replace(/V$/, '').length / 2;
43
43
  }
@@ -67,14 +67,12 @@ function attemptReplace(token, pattern, replacement, callback) {
67
67
  // attempt to replace a list of patterns/replacements on a token for a minimum
68
68
  // measure M.
69
69
  function attemptReplacePatterns(token, replacements, measureThreshold) {
70
- var replacement = null;
70
+ var replacement = token;
71
71
 
72
- for(var i = 0; i < replacements.length; i++) {
73
- if(measureThreshold == null || measure(attemptReplace(token, replacements[i][0], '')) > measureThreshold)
74
- replacement = attemptReplace(token, replacements[i][0], replacements[i][1]);
75
-
76
- if(replacement)
77
- break;
72
+ for(var i = 0; i < replacements.length; i++) {
73
+ if(measureThreshold == null || measure(attemptReplace(token, replacements[i][0], replacements[i][1])) > measureThreshold) {
74
+ replacement = attemptReplace(replacement, replacements[i][0], replacements[i][2]) || replacement;
75
+ }
78
76
  }
79
77
 
80
78
  return replacement;
@@ -83,50 +81,73 @@ function attemptReplacePatterns(token, replacements, measureThreshold) {
83
81
  // replace a list of patterns/replacements on a word. if no match is made return
84
82
  // the original token.
85
83
  function replacePatterns(token, replacements, measureThreshold) {
86
- var result = attemptReplacePatterns(token, replacements, measureThreshold);
87
- token = result == null ? token : result;
88
-
89
- return token;
84
+ return attemptReplacePatterns(token, replacements, measureThreshold) || token;
85
+ }
86
+
87
+ // TODO: this should replace all of the messy replacement stuff above
88
+ function replaceRegex(token, regex, includeParts, minimumMeasure) {
89
+ var parts;
90
+ var result = '';
91
+
92
+ if(regex.test(token)) {
93
+ parts = regex.exec(token);
94
+
95
+ includeParts.forEach(function(i) {
96
+ result += parts[i];
97
+ });
98
+ }
99
+
100
+ if(measure(result) > minimumMeasure) {
101
+ return result;
102
+ }
103
+
104
+ return null;
90
105
  }
91
106
 
92
107
  // step 1a as defined for the porter stemmer algorithm.
93
108
  function step1a(token) {
94
- if(token.match(/(ss|i)es$/))
109
+ if(token.match(/(ss|i)es$/)) {
95
110
  return token.replace(/(ss|i)es$/, '$1');
96
-
97
- if(token.substr(-1) == 's' && token.substr(-2, 1) != 's' && token.length > 3)
111
+ }
112
+
113
+ if(token.substr(-1) == 's' && token.substr(-2, 1) != 's' && token.length > 2) {
98
114
  return token.replace(/s?$/, '');
99
-
115
+ }
116
+
100
117
  return token;
101
118
  }
102
119
 
103
120
  // step 1b as defined for the porter stemmer algorithm.
104
121
  function step1b(token) {
105
122
  if(token.substr(-3) == 'eed') {
106
- if(measure(token.substr(0, token.length - 3)) > 0)
123
+ if(measure(token.substr(0, token.length - 3)) > 0)
107
124
  return token.replace(/eed$/, 'ee');
108
125
  } else {
109
- var result = attemptReplace(token, /ed|ing$/, '', function(token) {
110
- if(categorizeGroups(token).indexOf('V') >= 0) {
111
- var result = attemptReplacePatterns(token, [['at', 'ate'], ['bl', 'ble'], ['iz', 'ize']]);
112
- if(result)
113
- return result;
114
- else {
115
- if(endsWithDoublCons(token) && token.match(/[^lsz]$/))
116
- return token.replace(/([^aeiou])\1$/, '$1');
117
-
118
- if(measure(token) == 1 && categorizeChars(token).substr(-3) == 'CVC' && token.match(/[^wxy]$/))
119
- return token + 'e';
120
- }
121
-
122
- return token;
123
- }
124
-
125
- return null;
126
- });
127
-
128
- if(result)
129
- return result;
126
+ var result = attemptReplace(token, /(ed|ing)$/, '', function(token) {
127
+ if(categorizeGroups(token).indexOf('V') >= 0) {
128
+ result = attemptReplacePatterns(token, [['at', '', 'ate'], ['bl', '', 'ble'], ['iz', '', 'ize']]);
129
+
130
+ if(result != token) {
131
+ return result;
132
+ } else {
133
+ if(endsWithDoublCons(token) && token.match(/[^lsz]$/)) {
134
+ return token.replace(/([^aeiou])\1$/, '$1');
135
+ }
136
+
137
+ if(measure(token) == 1 && categorizeChars(token).substr(-3) == 'CVC' && token.match(/[^wxy]$/)) {
138
+ return token + 'e';
139
+ }
140
+ }
141
+
142
+ return token;
143
+ }
144
+
145
+ return null;
146
+ });
147
+
148
+ if(result) {
149
+ return result;
150
+ }
130
151
  }
131
152
 
132
153
  return token;
@@ -134,44 +155,48 @@ function step1b(token) {
134
155
 
135
156
  // step 1c as defined for the porter stemmer algorithm.
136
157
  function step1c(token) {
137
- if(categorizeGroups(token).substr(-2, 1) == 'V') {
138
- if(token.substr(-1) == 'y')
139
- return token.replace(/y$/, 'i');
158
+ var categorizedGroups = categorizeGroups(token);
159
+
160
+ if(token.substr(-1) == 'y' && categorizedGroups.substr(0, categorizedGroups.length - 1).indexOf('V') > -1) {
161
+ return token.replace(/y$/, 'i');
140
162
  }
141
-
163
+
142
164
  return token;
143
165
  }
144
166
 
145
167
  // step 2 as defined for the porter stemmer algorithm.
146
168
  function step2(token) {
147
- return replacePatterns(token, [['ational', 'ate'], ['tional', 'tion'], ['enci', 'ence'], ['anci', 'ance'],
148
- ['izer', 'ize'], ['abli', 'able'], ['alli', 'al'], ['entli', 'ent'], ['eli', 'e'],
149
- ['ousli', 'ous'], ['ization', 'ize'], ['ation', 'ate'], ['ator', 'ate'],['alism', 'al'],
150
- ['iveness', 'ive'], ['fulness', 'ful'], ['ousness', 'ous'], ['aliti', 'al'],
151
- ['iviti', 'ive'], ['biliti', 'ble']], 0);
169
+ token = replacePatterns(token, [['ational', '', 'ate'], ['tional', '', 'tion'], ['enci', '', 'ence'], ['anci', '', 'ance'],
170
+ ['izer', '', 'ize'], ['abli', '', 'able'], ['bli', '', 'ble'], ['alli', '', 'al'], ['entli', '', 'ent'], ['eli', '', 'e'],
171
+ ['ousli', '', 'ous'], ['ization', '', 'ize'], ['ation', '', 'ate'], ['ator', '', 'ate'],['alism', '', 'al'],
172
+ ['iveness', '', 'ive'], ['fulness', '', 'ful'], ['ousness', '', 'ous'], ['aliti', '', 'al'],
173
+ ['iviti', '', 'ive'], ['biliti', '', 'ble'], ['logi', '', 'log']], 0);
174
+
175
+ return token;
152
176
  }
153
177
 
154
178
  // step 3 as defined for the porter stemmer algorithm.
155
179
  function step3(token) {
156
- return replacePatterns(token, [['icate', 'ic'], ['ative', ''], ['alize', 'al'],
157
- ['iciti', 'ic'], ['ical', 'ic'], ['ful', ''], ['ness', '']], 0);
180
+ return replacePatterns(token, [['icate', '', 'ic'], ['ative', '', ''], ['alize', '', 'al'],
181
+ ['iciti', '', 'ic'], ['ical', '', 'ic'], ['ful', '', ''], ['ness', '', '']], 0);
158
182
  }
159
183
 
160
184
  // step 4 as defined for the porter stemmer algorithm.
161
185
  function step4(token) {
162
- return replacePatterns(token, [['al', ''], ['ance', ''], ['ence', ''], ['er', ''],
163
- ['ic', ''], ['able', ''], ['ible', ''], ['ant', ''],
164
- ['ement', ''], ['ment', ''], ['ent', ''], [/([st])ion/, '$1'], ['ou', ''], ['ism', ''],
165
- ['ate', ''], ['iti', ''], ['ous', ''], ['ive', ''],
166
- ['ize', '']], 1);
186
+ return replaceRegex(token, /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/, [1], 1) ||
187
+ replaceRegex(token, /^(.+?)(s|t)(ion)$/, [1, 2], 1) ||
188
+ token;
167
189
  }
168
190
 
169
191
  // step 5a as defined for the porter stemmer algorithm.
170
192
  function step5a(token) {
171
- var m = measure(token);
172
-
173
- if(token.length > 3 && ((m > 1 && token.substr(-1) == 'e') || (m == 1 && !(categorizeChars(token).substr(-4, 3) == 'CVC' && token.match(/[^wxy].$/)))))
174
- return token.replace(/e$/, '');
193
+ var m = measure(token.replace(/e$/, ''));
194
+
195
+
196
+
197
+ if(m > 1 || (m == 1 && !(categorizeChars(token).substr(-4, 3) == 'CVC' && token.match(/[^wxy].$/)))) {
198
+ token = token.replace(/e$/, '');
199
+ }
175
200
 
176
201
  return token;
177
202
  }
@@ -179,8 +204,7 @@ function step5a(token) {
179
204
  // step 5b as defined for the porter stemmer algorithm.
180
205
  function step5b(token) {
181
206
  if(measure(token) > 1) {
182
- if(endsWithDoublCons(token) && token.substr(-2) == 'll')
183
- return token.replace(/ll$/, 'l');
207
+ return token.replace(/ll$/, 'l');
184
208
  }
185
209
 
186
210
  return token;
@@ -189,12 +213,16 @@ function step5b(token) {
189
213
  var PorterStemmer = new Stemmer();
190
214
  module.exports = PorterStemmer;
191
215
 
216
+
192
217
  // perform full stemming algorithm on a single word
193
218
  PorterStemmer.stem = function(token) {
219
+ if(token.length < 3) return token;
194
220
  return step5b(step5a(step4(step3(step2(step1c(step1b(step1a(token.toLowerCase())))))))).toString();
195
221
  };
196
222
 
197
223
  //exports for tests
224
+ PorterStemmer.categorizeGroups = categorizeGroups;
225
+ PorterStemmer.measure = measure;
198
226
  PorterStemmer.step1a = step1a;
199
227
  PorterStemmer.step1b = step1b;
200
228
  PorterStemmer.step1c = step1c;