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
@@ -1,68 +0,0 @@
1
- /*
2
- Agenda class
3
- Copyright (C) 2014 Hugo W.L. ter Doest
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- // For deep comparing items including children
20
- var _ = require('underscore');
21
- var log4js = require('log4js');
22
- var logger = log4js.getLogger();
23
- logger.setLevel('ERROR');
24
-
25
- // Constructor
26
- function Agenda() {
27
- logger.debug("Agenda");
28
- this.agenda = [];
29
- }
30
-
31
- // Adds an item to the agenda if it is nog already on chart or agenda
32
- Agenda.prototype.add_item = function(item, chart) {
33
- var item_found = false;
34
- var nr_items = 0;
35
-
36
- logger.debug("Enter Agenda.add_item( "+ item.id + ")" + "; size of the agenda: " + this.agenda.length);
37
- if (chart.is_not_on_chart(item)) {
38
- this.agenda.some(function(item2) {
39
- if (_.isEqual(item, item2)) {
40
- item_found = true;
41
- return(true);
42
- }
43
- });
44
-
45
- if (!item_found) {
46
- this.agenda.push(item);
47
- logger.debug("Agenda.add_item; item added: " + item.id);
48
- nr_items = 1;
49
- }
50
- }
51
- logger.debug("Exit Agenda.add_item; size of the agenda: " + this.agenda.length);
52
- return(nr_items);
53
- };
54
-
55
- // Removes an item from the agenda and returns it
56
- Agenda.prototype.get_item = function() {
57
- var item = this.agenda.pop();
58
- logger.debug("Agenda.get_item: " + (item ? item.id : "agenda is empty"));
59
- return(item);
60
- };
61
-
62
- // Checks if the agenda is empty
63
- Agenda.prototype.is_non_empty = function() {
64
- logger.debug("Agenda.is_non_empty: " + (this.agenda !== []));
65
- return(this.agenda !== []);
66
- };
67
-
68
- module.exports = Agenda;
@@ -1,87 +0,0 @@
1
- /*
2
- Cocke Younger Kasami (CYK) chart parser
3
- Copyright (C) 2014 Hugo W.L. ter Doest
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- var log4js = require('log4js');
20
- var logger = log4js.getLogger();
21
- logger.setLevel('DEBUG');
22
-
23
- var Item = require('./CYK_Item');
24
- var Chart = require('./Chart');
25
- var ChartParser = require('./ChartParser');
26
-
27
- // Constructor for parser object
28
- // grammar is an object as defined in CFG.js
29
- function CYK_ChartParser(grammar) {
30
- logger.debug("Enter CYK_ChartParser: " + JSON.stringify(grammar));
31
- this.grammar = grammar;
32
- }
33
-
34
- CYK_ChartParser.prototype = Object.create(ChartParser.prototype);
35
-
36
-
37
- CYK_ChartParser.prototype.initialise = function(tagged_sentence) {
38
- logger.debug("Enter CYK_ChartParser.initialise");
39
- this.tagged_sentence = tagged_sentence;
40
- this.N = tagged_sentence.length;
41
- this.chart = new Chart(this.N);
42
- for (var i = 0; i < this.N; i++) {
43
- // Create a terminal item of the form Terminal -> *empty*
44
- var term_item = new Item({'lhs': tagged_sentence[i][0], 'rhs': []}, i, i+1);
45
- // Create a tag item of the form Categorie -> Terminal
46
- for (var j = 1; j < tagged_sentence[i].length; j++) {
47
- var tag_item = new Item({'lhs': this.tagged_sentence[i][j], 'rhs': [this.tagged_sentence[i][0]]}, i, i + 1);
48
- tag_item.children.push(term_item);
49
- this.chart.add_item(tag_item);
50
- logger.debug("CYK_Parser.initialise: |- " + tag_item.id);
51
- }
52
- }
53
- logger.debug("Exit CYK_ChartParser.initialise");
54
- };
55
-
56
- // This is the CYK chart parser
57
- // sentence is a tagged sentence of the form [[word, category], [word, category], ...]
58
- CYK_ChartParser.prototype.parse = function(tagged_sentence) {
59
- var that = this;
60
-
61
- logger.debug("Enter CYK_ChartParser.parse: " + JSON.stringify(tagged_sentence, null, 2));
62
- this.initialise(tagged_sentence);
63
- for (var i = 2; i <= this.N; ++i) { // Length of span
64
- for (var j = 0; j <= this.N - i; ++j) { // Start of span
65
- for (var k = i - 1; k >= 0; --k) { // Partition of span
66
- var items1 = that.chart.get_items_from_to(j, j + k);
67
- var items2 = that.chart.get_items_from_to(j + k, j + i);
68
- items1.forEach(function(item1) {
69
- items2.forEach(function(item2) {
70
- var matching_rules = that.grammar.get_rules_with_rhs(item1.data.rule.lhs, item2.data.rule.lhs);
71
- matching_rules.forEach(function(rule) {
72
- var item = new Item(rule, item1.data.from, item2.data.to);
73
- item.add_child(item1);
74
- item.add_child(item2);
75
- that.chart.add_item(item);
76
- logger.debug("CYK_ChartParser.parse: " + item1.id + ", " + item2.id + " |- " + item.id);
77
- });
78
- });
79
- });
80
- }
81
- }
82
- }
83
- logger.debug("Exit CYK_ChartParser.parse: " + JSON.stringify(this.chart, null, 2));
84
- return this.chart;
85
- };
86
-
87
- module.exports = CYK_ChartParser;
@@ -1,159 +0,0 @@
1
- /*
2
- CYK item class for CYK and Head-Corner Parsing
3
- Copyright (C) 2014 Hugo W.L. ter Doest
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- // NB: CYK items are completely recognised items of the form [X, i, j] meaning ai...aj can be generated from X
20
-
21
- var typeOf = require('typeof');
22
- var log4js = require('log4js');
23
- var logger = log4js.getLogger();
24
- logger.setLevel('ERROR');
25
-
26
-
27
- function CYK_Item(rule, i, j) {
28
- logger.debug("CYK_Item: " + rule + ", " + i + ", " + j);
29
- this.id = "CYK(" + rule.lhs + ", " + i + ", " + j + ")";
30
- this.name = rule.lhs;
31
- this.children = [];
32
- this.data = {};
33
- this.data.from = i;
34
- this.data.to = j;
35
- this.data.rule = rule;
36
- }
37
-
38
- module.exports = CYK_Item;
39
-
40
- var DoubleDottedItem = require('./DoubleDottedItem');
41
-
42
- CYK_Item.prototype.add_child = function(child) {
43
- logger.debug("CYK_Item.add_child: " + child.id);
44
- this.children.push(child);
45
- };
46
-
47
- CYK_Item.prototype.is_complete = function() {
48
- logger.debug("CYK_Item.is_complete: CYK items always are complete!");
49
- return(true);
50
- };
51
-
52
- CYK_Item.prototype.combine_with_chart = function(chart, agenda, grammar) {
53
- var nr_items_added = 0;
54
-
55
- logger.debug("Enter CYK_Item.combine_with_chart:" + this.id);
56
- nr_items_added += this.hc_predict(chart, agenda, grammar);
57
- nr_items_added += this.left_complete(chart, agenda, grammar);
58
- nr_items_added += this.right_complete(chart, agenda, grammar);
59
- logger.debug("Exit CYK_Item.combine_with_chart: number of items added: " + nr_items_added);
60
- return(nr_items_added);
61
- };
62
-
63
- // Adds double dotted items to the chart based on goal and CYK items
64
- CYK_Item.prototype.hc_predict = function(chart, agenda, grammar) {
65
- var that = this;
66
- var nr_items_added = 0;
67
-
68
- logger.debug("Enter CYK_Item.hc_predict: " + this.id);
69
- var items = chart.get_items_from_to(this.data.from, this.data.to);
70
- items.forEach(function(item) {
71
- if (typeOf(item) === "goalitem") {
72
- // Create head-corner items
73
- var rules = grammar.get_rules_with_head(that.data.rule.lhs);
74
- rules.forEach(function(rule) {
75
- if (grammar.is_headcorner_of(rule.lhs, item.data.nonterminal)) {
76
- var new_item = new DoubleDottedItem(rule, rule.head, rule.head+1, that.data.from, that.data.to);
77
- new_item.children.push(that);
78
- nr_items_added += agenda.add_item(new_item, chart);
79
- logger.debug("CYK_Item.hc_predict: " + item.id +", " + that.id + " |- " + new_item.id);
80
- }
81
- });
82
- }
83
- });
84
- logger.debug("Exit CYK_Item.hc_predict: number of items added: " + nr_items_added);
85
- return(nr_items_added);
86
- };
87
-
88
- CYK_Item.prototype.left_complete = function (chart, agenda, grammar) {
89
- var nr_items_added = 0;
90
- var that = this;
91
-
92
- logger.debug("Enter CYK_Item.left_complete: " + this.id);
93
- var goals = chart.get_items_from(this.data.from);
94
- var doubledotteditems = chart.get_items_from(this.data.to);
95
- doubledotteditems.forEach(function(doubledotteditem) {
96
- if ((typeOf(doubledotteditem) === "doubledotteditem") && (doubledotteditem.data.left_dot > 0)) {
97
- goals.forEach(function(goal) {
98
- if (typeOf(goal) === "goalitem") {
99
- logger.debug("CYK_Item.left_complete: trying" + goal.id + ", " + that.id + ", " + doubledotteditem);
100
- if ((doubledotteditem.data.rule.rhs[doubledotteditem.data.left_dot-1] === that.data.rule.lhs) &&
101
- grammar.is_headcorner_of(doubledotteditem.data.rule.lhs, goal.data.nonterminal) ) {
102
- new_item = doubledotteditem.copy();
103
- new_item.recognise_left(that);
104
- nr_items_added += agenda.add_item(new_item, chart);
105
- logger.debug("CYK_Item.left_complete: " + goal.id + ", " + that.id + ", " + doubledotteditem + " |- " + new_item.id);
106
- }
107
- }
108
- });
109
- }
110
- });
111
- logger.debug("Exit CYK_Item.left_complete: number of items added: " + nr_items_added);
112
- return(nr_items_added);
113
- };
114
-
115
- CYK_Item.prototype.right_complete = function (chart, agenda, grammar) {
116
- var that = this;
117
- var nr_items_added = 0;
118
-
119
- logger.debug("Enter CYK_Item.right_complete: " + this.id);
120
- var goals = chart.get_items_to(this.data.to);
121
- var doubledotteditems = chart.get_items_to(this.data.from);
122
- doubledotteditems.forEach(function(doubledotteditem) {
123
- if (typeOf(doubledotteditem) === "doubledotteditem") {
124
- goals.forEach(function(goal) {
125
- if (typeOf(goal) === "goalitem") {
126
- logger.debug("CYK_Item.right_complete: trying: " + goal.id + ", " + doubledotteditem + ", " + that.id);
127
- if ((doubledotteditem.data.rule.rhs[doubledotteditem.data.right_dot] === that.data.rule.lhs) &&
128
- grammar.is_headcorner_of(doubledotteditem.data.rule.lhs, goal.data.nonterminal) ) {
129
- new_item = doubledotteditem.copy();
130
- new_item.recognise_right(that);
131
- nr_items_added += agenda.add_item(new_item, chart);
132
- logger.debug("CYK_Item.right_complete: " + goal.id + ", " + doubledotteditem + ", " + that.id + " |- " + new_item.id);
133
- }
134
- }
135
- });
136
- }
137
- });
138
- logger.debug("Exit CYK_Item.right_complete: number of items added: " + nr_items_added);
139
- return(nr_items_added);
140
- };
141
-
142
- CYK_Item.prototype.create_parse_tree = function() {
143
- logger.debug("Enter CYK_Item.create_parse_tree: " + this.id);
144
- var subtree = this.data.rule.lhs;
145
- if (this.children.length === 0) {
146
- subtree += "(" + this.data.rule.rhs + ")";
147
- }
148
- else {
149
- subtree += "(";
150
- var i;
151
- for (i = 0; i < this.children.length; i++) {
152
- subtree += this.children[i].create_parse_tree() + (i < this.children.length - 1 ? "," : "");
153
- }
154
- subtree += ")";
155
- }
156
- logger.debug("Exit CYK_Item.create_parse_tree: " + subtree);
157
- return(subtree);
158
- };
159
-
@@ -1,211 +0,0 @@
1
- /*
2
- Generic chart that can be used for all chart parsers
3
- Copyright (C) 2014 Hugo W.L. ter Doest
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- // Implements a chart with from/to edges. Items are added by chart.add_item(i, j, item)
20
- // Items are identified by their id. Items that have the same id are not added to the same edge.
21
-
22
- // For deep comparing items including children
23
- var _ = require('underscore');
24
- var typeOf = require('typeof');
25
- var log4js = require('log4js');
26
- var logger = log4js.getLogger();
27
- logger.setLevel('DEBUG');
28
-
29
- // Creates a chart for recognition of a sentence of length N
30
- function Chart(N) {
31
- logger.debug("Chart: " + N);
32
- this.N = N;
33
- this.outgoing_edges = new Array(N+1);
34
- this.incoming_edges = new Array(N+1);
35
-
36
- var i;
37
- for (i = 0; i <= N; i++) {
38
- this.outgoing_edges[i] = {};
39
- this.incoming_edges[i] = {};
40
- }
41
- }
42
-
43
- // Adds an item to the chart if it is not already there; returns 1 if the item was added, 0 otherwise
44
- // Items are compared using deep compare (so including children)
45
- Chart.prototype.add_item = function(item) {
46
- var nr_items_added = 0;
47
- var item_found = false;
48
-
49
- logger.debug("Enter Chart.add_item: " + item.id);
50
- if (this.outgoing_edges[item.data.from][item.id]) {
51
- // item already exists -> deep compare
52
- this.outgoing_edges[item.data.from][item.id].some(function(item2) {
53
- if (_.isEqual(item, item2)) {
54
- item_found = true;
55
- return(true);
56
- }
57
- });
58
- if (!item_found) {
59
- // if not found -> add item to chart
60
- logger.debug("Chart.add_item: " + this.outgoing_edges[item.data.from][item.id]);
61
- this.outgoing_edges[item.data.from][item.id].push(item);
62
- logger.debug("Chart.add_item: " + this.incoming_edges[item.data.to][item.id]);
63
- if (!this.incoming_edges[item.data.to][item.id]) {
64
- this.incoming_edges[item.data.to][item.id] = [];
65
- }
66
- this.incoming_edges[item.data.to][item.id].push(item);
67
- nr_items_added = 1;
68
- }
69
- }
70
- else {
71
- // item does not exist -> add to the chart
72
- this.outgoing_edges[item.data.from][item.id] = [item];
73
- this.incoming_edges[item.data.to][item.id] = [item];
74
- nr_items_added = 1;
75
- }
76
-
77
- logger.debug("Exit Chart.add_item: number of items added: " + nr_items_added);
78
- return(nr_items_added);
79
- };
80
-
81
- Chart.prototype.is_not_on_chart = function(item) {
82
- var item_found = false;
83
-
84
- logger.debug("Enter Chart.is_not_on_chart " + item.id);
85
- if (this.outgoing_edges[item.data.from][item.id]) {
86
- // item already exists -> deep compare
87
- this.outgoing_edges[item.data.from][item.id].some(function(item2) {
88
- if (_.isEqual(item, item2)) {
89
- item_found = true;
90
- return(true);
91
- }
92
- });
93
- }
94
- logger.debug("Exit Chart.is_not_on_chart: " + item_found);
95
- return(!item_found);
96
- };
97
-
98
- // Returns all items that span i to j
99
- Chart.prototype.get_items_from_to = function(i, j) {
100
- var res = [];
101
- var that = this;
102
-
103
- logger.debug("Enter Chart.get_items_from_to(" + i + ", " + j + ")");
104
- Object.keys(this.outgoing_edges[i]).forEach(function(item_id){
105
- if (that.outgoing_edges[i][item_id].length > 0) {
106
- if (that.outgoing_edges[i][item_id][0].data.to === j) {
107
- res = res.concat(that.outgoing_edges[i][item_id]);
108
- }
109
- }
110
- });
111
- logger.debug("Exit Chart.get_items_from_to: " + JSON.stringify(res));
112
- return(res);
113
- };
114
-
115
- Chart.prototype.get_items_from = function(i) {
116
- var res = [];
117
- var that = this;
118
-
119
- logger.debug("Enter Chart.get_items_from(" + i + ")");
120
- Object.keys(this.outgoing_edges[i]).forEach(function(item_id){
121
- res = res.concat(that.outgoing_edges[i][item_id]);
122
- });
123
- logger.debug("Exit Chart.get_items_from: " + res);
124
- return(res);
125
- };
126
-
127
- Chart.prototype.get_items_to = function(j) {
128
- var res = [];
129
- var that = this;
130
-
131
- logger.debug("Enter Chart.get_items_to(" + j + ")");
132
- Object.keys(this.incoming_edges[j]).forEach(function(item_id){
133
- res = res.concat(that.incoming_edges[j][item_id]);
134
- });
135
- logger.debug("Exit Chart.get_items_to:" + res);
136
- return(res);
137
- };
138
-
139
- Chart.prototype.nr_items_to = function(j) {
140
- var that = this;
141
- var nr_items = 0;
142
-
143
- logger.debug("Enter Chart.nr_items_to(" + j + ")");
144
- Object.keys(this.incoming_edges[j]).forEach(function(item_id){
145
- nr_items += that.incoming_edges[j][item_id].length;
146
- });
147
- logger.debug("Exit Chart.nr_items_to: " + nr_items);
148
- return(nr_items);
149
- };
150
-
151
- // Returns all complete items that span i to j
152
- Chart.prototype.get_complete_items_from_to = function(i, j) {
153
- var res = [];
154
- var that = this;
155
-
156
- logger.debug("Enter Chart.get_complete_items_from_to(" + i + ", " + j + ")");
157
- this.get_items_from_to(i, j).forEach(function(item){
158
- if (item.is_complete()) {
159
- res.push(item);
160
- }
161
- });
162
- logger.debug("Exit Chart.get_complete_items_from_to: " + res);
163
- return(res);
164
- };
165
-
166
- // Returns all complete items span i to j AND start with nonterminal A
167
- Chart.prototype.full_parse_items = function(A) {
168
- var that = this;
169
- var items = [];
170
-
171
- logger.debug("Enter Chart.full_parse_items(" + A + ")");
172
- this.get_complete_items_from_to(0, this.N).forEach(function(item) {
173
- if (item.data.rule.lhs === A) {
174
- items.push(item);
175
- }
176
- });
177
- logger.debug("Exit Chart.full_parse_items: " + items);
178
- return(items);
179
- };
180
-
181
- // Returns the parse trees in textual bracketed form
182
- // item_type selects the right type of item to create the parse tree from
183
- Chart.prototype.parse_trees = function(nonterminal, item_type) {
184
- var that = this;
185
- var parses = [];
186
-
187
- logger.debug("Enter Chart.parse_items(" + nonterminal + ", " + item_type + ")");
188
- this.get_items_from_to(0, this.N).forEach(function(item) {
189
- if (typeOf(item) === item_type) {
190
- if ((item.data.rule.lhs === nonterminal) && item.is_complete()) {
191
- parses.push(item.create_parse_tree());
192
- }
193
- }
194
- });
195
- logger.debug("Exit Chart.parse_items:" + parses);
196
- return(parses);
197
- };
198
-
199
- // Returns the total number of items on the chart
200
- Chart.prototype.nr_of_items = function() {
201
- var nr_items = 0;
202
-
203
- logger.debug("Enter Chart.nr_of_items()");
204
- for (i = 0; i <= this.N; i++) {
205
- nr_items += this.nr_items_to(i);
206
- }
207
- logger.debug("Exit Chart.nr_of_items: " + nr_items);
208
- return(nr_items);
209
- };
210
-
211
- module.exports = Chart;
@@ -1,60 +0,0 @@
1
- /*
2
- Generic chart parser that can be used to create different types of chart parsers
3
- Copyright (C) 2014 Hugo W.L. ter Doest
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- var log4js = require('log4js');
20
- var logger = log4js.getLogger();
21
- logger.setLevel('ERROR');
22
-
23
- var EarleyItem = require('./EarleyItem');
24
- var Chart = require('./Chart');
25
-
26
- ChartParser.prototype.initialise = function(tagged_sentence) {
27
- var that = this;
28
- var nr_items_added = 0;
29
-
30
- logger.debug('Enter ChartParser.initialise');
31
- this.tagged_sentence = tagged_sentence;
32
- this.N = this.tagged_sentence.length;
33
- // Initialise chart
34
- this.chart = new Chart(this.N);
35
- // Add items for rules that have the start symbol as left-hand-side
36
- var rules = this.grammar.rules_with_lhs(this.grammar.get_start_symbol());
37
- rules.forEach(function(rule) {
38
- var new_item = new EarleyItem(rule, 0, 0, 0);
39
- nr_items_added += that.chart.add_item(new_item);
40
- });
41
-
42
- // Add items for the tagged sentence
43
- for (var i = 0; i < this.N; i++) {
44
- // Create terminal item
45
- var term_item = new EarleyItem({'lhs': this.tagged_sentence[i][0], 'rhs': ''}, 1, i, i + 1);
46
- // Add tag items
47
- for (var j = 1; j < tagged_sentence[i].length; j++) {
48
- var tag_item = new EarleyItem({'lhs': this.tagged_sentence[i][j], 'rhs': [this.tagged_sentence[i][0]]}, 1, i, i + 1);
49
- tag_item.append_child(term_item);
50
- nr_items_added += this.chart.add_item(tag_item);
51
- logger.debug("ChartParser.initialise: |- " + tag_item.id);
52
- }
53
- }
54
- logger.debug("Exit ChartParser.initialise; number of items added: " + nr_items_added);
55
- return(nr_items_added);
56
- };
57
-
58
- function ChartParser() {}
59
-
60
- module.exports = ChartParser;