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,1289 +0,0 @@
1
- module.exports=Grammar = (function() {
2
- /*
3
- * Generated by PEG.js 0.8.0.
4
- *
5
- * http://pegjs.majda.cz/
6
- */
7
-
8
- function peg$subclass(child, parent) {
9
- function ctor() { this.constructor = child; }
10
- ctor.prototype = parent.prototype;
11
- child.prototype = new ctor();
12
- }
13
-
14
- function SyntaxError(message, expected, found, offset, line, column) {
15
- this.message = message;
16
- this.expected = expected;
17
- this.found = found;
18
- this.offset = offset;
19
- this.line = line;
20
- this.column = column;
21
-
22
- this.name = "SyntaxError";
23
- }
24
-
25
- peg$subclass(SyntaxError, Error);
26
-
27
- function parse(input) {
28
- var options = arguments.length > 1 ? arguments[1] : {},
29
-
30
- peg$FAILED = {},
31
-
32
- peg$startRuleFunctions = { grammar: peg$parsegrammar },
33
- peg$startRuleFunction = peg$parsegrammar,
34
-
35
- peg$c0 = [],
36
- peg$c1 = peg$FAILED,
37
- peg$c2 = function(rules) {
38
- grammar = new Grammar();
39
- for (var i = 0; i < rules.length; i++) {
40
- grammar.production_rules.push(rules[i][1]);
41
- }
42
- grammar.start_symbol = grammar.production_rules[0].lhs;
43
- grammar.nonterminals = nonterminals;
44
- grammar.is_CNF = is_CNF;
45
- grammar.symbols = symbols;
46
- return(grammar);
47
- },
48
- peg$c3 = function(rule, cseq) {
49
- if (cseq) {
50
- rule.constraints = cseq;
51
- }
52
- return(rule);
53
- },
54
- peg$c4 = null,
55
- peg$c5 = function(lhs, rhs_1, head, rhs_2) {
56
- var rhs = [];
57
- var head_pos = 0;
58
-
59
- rhs = rhs_1;
60
- if (head) {
61
- head_pos = rhs_1.length;
62
- rhs.push(head[1]);
63
- }
64
- rhs = rhs.concat(rhs_2);
65
- rhs.forEach(function(symbol) {
66
- symbols[symbol] = true;
67
- });
68
- var rule = new Rule(lhs, rhs, head_pos);
69
- nonterminals[lhs] = true;
70
- symbols[lhs] = true;
71
- if ((rule.rhs.length > 2) || (rule.rhs.length === 0)) {
72
- is_CNF = false;
73
- }
74
- return(rule);
75
- },
76
- peg$c6 = function(nt) {
77
- return(nt);
78
- },
79
- peg$c7 = function(path, atom) {
80
- var constraint = new Constraint(path, atom);
81
- return(constraint);
82
- },
83
- peg$c8 = function(path1, path2) {
84
- var constraint = new Constraint(path1, path2);
85
- return(constraint);
86
- },
87
- peg$c9 = function(idseq) {
88
- return(idseq);
89
- },
90
- peg$c10 = /^[a-zA-Z_0-9]/,
91
- peg$c11 = { type: "class", value: "[a-zA-Z_0-9]", description: "[a-zA-Z_0-9]" },
92
- peg$c12 = function(characters) {
93
- var s = "";
94
- for (var i = 0; i < characters.length; i++) {
95
- s += characters[i];
96
- }
97
- return(s);
98
- },
99
- peg$c13 = /^[a-zA-Z_0-9$]/,
100
- peg$c14 = { type: "class", value: "[a-zA-Z_0-9$]", description: "[a-zA-Z_0-9$]" },
101
- peg$c15 = "->",
102
- peg$c16 = { type: "literal", value: "->", description: "\"->\"" },
103
- peg$c17 = "<",
104
- peg$c18 = { type: "literal", value: "<", description: "\"<\"" },
105
- peg$c19 = ">",
106
- peg$c20 = { type: "literal", value: ">", description: "\">\"" },
107
- peg$c21 = "=",
108
- peg$c22 = { type: "literal", value: "=", description: "\"=\"" },
109
- peg$c23 = "*",
110
- peg$c24 = { type: "literal", value: "*", description: "\"*\"" },
111
- peg$c25 = "\r\n",
112
- peg$c26 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" },
113
- peg$c27 = "\n",
114
- peg$c28 = { type: "literal", value: "\n", description: "\"\\n\"" },
115
- peg$c29 = "\r",
116
- peg$c30 = { type: "literal", value: "\r", description: "\"\\r\"" },
117
- peg$c31 = "//",
118
- peg$c32 = { type: "literal", value: "//", description: "\"//\"" },
119
- peg$c33 = void 0,
120
- peg$c34 = { type: "any", description: "any character" },
121
- peg$c35 = " ",
122
- peg$c36 = { type: "literal", value: " ", description: "\" \"" },
123
- peg$c37 = "\t",
124
- peg$c38 = { type: "literal", value: "\t", description: "\"\\t\"" },
125
-
126
- peg$currPos = 0,
127
- peg$reportedPos = 0,
128
- peg$cachedPos = 0,
129
- peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
130
- peg$maxFailPos = 0,
131
- peg$maxFailExpected = [],
132
- peg$silentFails = 0,
133
-
134
- peg$result;
135
-
136
- if ("startRule" in options) {
137
- if (!(options.startRule in peg$startRuleFunctions)) {
138
- throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
139
- }
140
-
141
- peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
142
- }
143
-
144
- function text() {
145
- return input.substring(peg$reportedPos, peg$currPos);
146
- }
147
-
148
- function offset() {
149
- return peg$reportedPos;
150
- }
151
-
152
- function line() {
153
- return peg$computePosDetails(peg$reportedPos).line;
154
- }
155
-
156
- function column() {
157
- return peg$computePosDetails(peg$reportedPos).column;
158
- }
159
-
160
- function expected(description) {
161
- throw peg$buildException(
162
- null,
163
- [{ type: "other", description: description }],
164
- peg$reportedPos
165
- );
166
- }
167
-
168
- function error(message) {
169
- throw peg$buildException(message, null, peg$reportedPos);
170
- }
171
-
172
- function peg$computePosDetails(pos) {
173
- function advance(details, startPos, endPos) {
174
- var p, ch;
175
-
176
- for (p = startPos; p < endPos; p++) {
177
- ch = input.charAt(p);
178
- if (ch === "\n") {
179
- if (!details.seenCR) { details.line++; }
180
- details.column = 1;
181
- details.seenCR = false;
182
- } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
183
- details.line++;
184
- details.column = 1;
185
- details.seenCR = true;
186
- } else {
187
- details.column++;
188
- details.seenCR = false;
189
- }
190
- }
191
- }
192
-
193
- if (peg$cachedPos !== pos) {
194
- if (peg$cachedPos > pos) {
195
- peg$cachedPos = 0;
196
- peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
197
- }
198
- advance(peg$cachedPosDetails, peg$cachedPos, pos);
199
- peg$cachedPos = pos;
200
- }
201
-
202
- return peg$cachedPosDetails;
203
- }
204
-
205
- function peg$fail(expected) {
206
- if (peg$currPos < peg$maxFailPos) { return; }
207
-
208
- if (peg$currPos > peg$maxFailPos) {
209
- peg$maxFailPos = peg$currPos;
210
- peg$maxFailExpected = [];
211
- }
212
-
213
- peg$maxFailExpected.push(expected);
214
- }
215
-
216
- function peg$buildException(message, expected, pos) {
217
- function cleanupExpected(expected) {
218
- var i = 1;
219
-
220
- expected.sort(function(a, b) {
221
- if (a.description < b.description) {
222
- return -1;
223
- } else if (a.description > b.description) {
224
- return 1;
225
- } else {
226
- return 0;
227
- }
228
- });
229
-
230
- while (i < expected.length) {
231
- if (expected[i - 1] === expected[i]) {
232
- expected.splice(i, 1);
233
- } else {
234
- i++;
235
- }
236
- }
237
- }
238
-
239
- function buildMessage(expected, found) {
240
- function stringEscape(s) {
241
- function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
242
-
243
- return s
244
- .replace(/\\/g, '\\\\')
245
- .replace(/"/g, '\\"')
246
- .replace(/\x08/g, '\\b')
247
- .replace(/\t/g, '\\t')
248
- .replace(/\n/g, '\\n')
249
- .replace(/\f/g, '\\f')
250
- .replace(/\r/g, '\\r')
251
- .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
252
- .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
253
- .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
254
- .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
255
- }
256
-
257
- var expectedDescs = new Array(expected.length),
258
- expectedDesc, foundDesc, i;
259
-
260
- for (i = 0; i < expected.length; i++) {
261
- expectedDescs[i] = expected[i].description;
262
- }
263
-
264
- expectedDesc = expected.length > 1
265
- ? expectedDescs.slice(0, -1).join(", ")
266
- + " or "
267
- + expectedDescs[expected.length - 1]
268
- : expectedDescs[0];
269
-
270
- foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
271
-
272
- return "Expected " + expectedDesc + " but " + foundDesc + " found.";
273
- }
274
-
275
- var posDetails = peg$computePosDetails(pos),
276
- found = pos < input.length ? input.charAt(pos) : null;
277
-
278
- if (expected !== null) {
279
- cleanupExpected(expected);
280
- }
281
-
282
- return new SyntaxError(
283
- message !== null ? message : buildMessage(expected, found),
284
- expected,
285
- found,
286
- pos,
287
- posDetails.line,
288
- posDetails.column
289
- );
290
- }
291
-
292
- function peg$parsegrammar() {
293
- var s0, s1, s2, s3, s4, s5;
294
-
295
- s0 = peg$currPos;
296
- s1 = [];
297
- s2 = peg$currPos;
298
- s3 = peg$parseS();
299
- if (s3 !== peg$FAILED) {
300
- s4 = peg$parseproduction_rule();
301
- if (s4 !== peg$FAILED) {
302
- s5 = peg$parseS();
303
- if (s5 !== peg$FAILED) {
304
- s3 = [s3, s4, s5];
305
- s2 = s3;
306
- } else {
307
- peg$currPos = s2;
308
- s2 = peg$c1;
309
- }
310
- } else {
311
- peg$currPos = s2;
312
- s2 = peg$c1;
313
- }
314
- } else {
315
- peg$currPos = s2;
316
- s2 = peg$c1;
317
- }
318
- if (s2 !== peg$FAILED) {
319
- while (s2 !== peg$FAILED) {
320
- s1.push(s2);
321
- s2 = peg$currPos;
322
- s3 = peg$parseS();
323
- if (s3 !== peg$FAILED) {
324
- s4 = peg$parseproduction_rule();
325
- if (s4 !== peg$FAILED) {
326
- s5 = peg$parseS();
327
- if (s5 !== peg$FAILED) {
328
- s3 = [s3, s4, s5];
329
- s2 = s3;
330
- } else {
331
- peg$currPos = s2;
332
- s2 = peg$c1;
333
- }
334
- } else {
335
- peg$currPos = s2;
336
- s2 = peg$c1;
337
- }
338
- } else {
339
- peg$currPos = s2;
340
- s2 = peg$c1;
341
- }
342
- }
343
- } else {
344
- s1 = peg$c1;
345
- }
346
- if (s1 !== peg$FAILED) {
347
- peg$reportedPos = s0;
348
- s1 = peg$c2(s1);
349
- }
350
- s0 = s1;
351
-
352
- return s0;
353
- }
354
-
355
- function peg$parseproduction_rule() {
356
- var s0, s1, s2, s3;
357
-
358
- s0 = peg$currPos;
359
- s1 = peg$parserule();
360
- if (s1 !== peg$FAILED) {
361
- s2 = [];
362
- s3 = peg$parseconstraint();
363
- while (s3 !== peg$FAILED) {
364
- s2.push(s3);
365
- s3 = peg$parseconstraint();
366
- }
367
- if (s2 !== peg$FAILED) {
368
- peg$reportedPos = s0;
369
- s1 = peg$c3(s1, s2);
370
- s0 = s1;
371
- } else {
372
- peg$currPos = s0;
373
- s0 = peg$c1;
374
- }
375
- } else {
376
- peg$currPos = s0;
377
- s0 = peg$c1;
378
- }
379
-
380
- return s0;
381
- }
382
-
383
- function peg$parserule() {
384
- var s0, s1, s2, s3, s4, s5, s6, s7;
385
-
386
- s0 = peg$currPos;
387
- s1 = peg$parsenonterminal();
388
- if (s1 !== peg$FAILED) {
389
- s2 = peg$parseArrow();
390
- if (s2 !== peg$FAILED) {
391
- s3 = [];
392
- s4 = peg$parseidentifier_no_eol();
393
- while (s4 !== peg$FAILED) {
394
- s3.push(s4);
395
- s4 = peg$parseidentifier_no_eol();
396
- }
397
- if (s3 !== peg$FAILED) {
398
- s4 = peg$currPos;
399
- s5 = peg$parseHeadIndicator();
400
- if (s5 !== peg$FAILED) {
401
- s6 = peg$parseidentifier_no_eol();
402
- if (s6 !== peg$FAILED) {
403
- s7 = peg$parseHeadIndicator();
404
- if (s7 !== peg$FAILED) {
405
- s5 = [s5, s6, s7];
406
- s4 = s5;
407
- } else {
408
- peg$currPos = s4;
409
- s4 = peg$c1;
410
- }
411
- } else {
412
- peg$currPos = s4;
413
- s4 = peg$c1;
414
- }
415
- } else {
416
- peg$currPos = s4;
417
- s4 = peg$c1;
418
- }
419
- if (s4 === peg$FAILED) {
420
- s4 = peg$c4;
421
- }
422
- if (s4 !== peg$FAILED) {
423
- s5 = [];
424
- s6 = peg$parseidentifier_no_eol();
425
- while (s6 !== peg$FAILED) {
426
- s5.push(s6);
427
- s6 = peg$parseidentifier_no_eol();
428
- }
429
- if (s5 !== peg$FAILED) {
430
- s6 = peg$parseEOL();
431
- if (s6 === peg$FAILED) {
432
- s6 = peg$parseEOI();
433
- }
434
- if (s6 !== peg$FAILED) {
435
- peg$reportedPos = s0;
436
- s1 = peg$c5(s1, s3, s4, s5);
437
- s0 = s1;
438
- } else {
439
- peg$currPos = s0;
440
- s0 = peg$c1;
441
- }
442
- } else {
443
- peg$currPos = s0;
444
- s0 = peg$c1;
445
- }
446
- } else {
447
- peg$currPos = s0;
448
- s0 = peg$c1;
449
- }
450
- } else {
451
- peg$currPos = s0;
452
- s0 = peg$c1;
453
- }
454
- } else {
455
- peg$currPos = s0;
456
- s0 = peg$c1;
457
- }
458
- } else {
459
- peg$currPos = s0;
460
- s0 = peg$c1;
461
- }
462
-
463
- return s0;
464
- }
465
-
466
- function peg$parsenonterminal() {
467
- var s0, s1, s2;
468
-
469
- s0 = peg$currPos;
470
- s1 = peg$parseidentifier();
471
- if (s1 !== peg$FAILED) {
472
- s2 = peg$parseS();
473
- if (s2 !== peg$FAILED) {
474
- peg$reportedPos = s0;
475
- s1 = peg$c6(s1);
476
- s0 = s1;
477
- } else {
478
- peg$currPos = s0;
479
- s0 = peg$c1;
480
- }
481
- } else {
482
- peg$currPos = s0;
483
- s0 = peg$c1;
484
- }
485
-
486
- return s0;
487
- }
488
-
489
- function peg$parseconstraint() {
490
- var s0, s1, s2, s3;
491
-
492
- s0 = peg$currPos;
493
- s1 = peg$parsefeature_path();
494
- if (s1 !== peg$FAILED) {
495
- s2 = peg$parseEqual();
496
- if (s2 !== peg$FAILED) {
497
- s3 = peg$parseidentifier();
498
- if (s3 !== peg$FAILED) {
499
- peg$reportedPos = s0;
500
- s1 = peg$c7(s1, s3);
501
- s0 = s1;
502
- } else {
503
- peg$currPos = s0;
504
- s0 = peg$c1;
505
- }
506
- } else {
507
- peg$currPos = s0;
508
- s0 = peg$c1;
509
- }
510
- } else {
511
- peg$currPos = s0;
512
- s0 = peg$c1;
513
- }
514
- if (s0 === peg$FAILED) {
515
- s0 = peg$currPos;
516
- s1 = peg$parsefeature_path();
517
- if (s1 !== peg$FAILED) {
518
- s2 = peg$parseEqual();
519
- if (s2 !== peg$FAILED) {
520
- s3 = peg$parsefeature_path();
521
- if (s3 !== peg$FAILED) {
522
- peg$reportedPos = s0;
523
- s1 = peg$c8(s1, s3);
524
- s0 = s1;
525
- } else {
526
- peg$currPos = s0;
527
- s0 = peg$c1;
528
- }
529
- } else {
530
- peg$currPos = s0;
531
- s0 = peg$c1;
532
- }
533
- } else {
534
- peg$currPos = s0;
535
- s0 = peg$c1;
536
- }
537
- }
538
-
539
- return s0;
540
- }
541
-
542
- function peg$parsefeature_path() {
543
- var s0, s1, s2, s3;
544
-
545
- s0 = peg$currPos;
546
- s1 = peg$parsePathOpen();
547
- if (s1 !== peg$FAILED) {
548
- s2 = peg$parseidentifier_seq();
549
- if (s2 !== peg$FAILED) {
550
- s3 = peg$parsePathClose();
551
- if (s3 !== peg$FAILED) {
552
- peg$reportedPos = s0;
553
- s1 = peg$c9(s2);
554
- s0 = s1;
555
- } else {
556
- peg$currPos = s0;
557
- s0 = peg$c1;
558
- }
559
- } else {
560
- peg$currPos = s0;
561
- s0 = peg$c1;
562
- }
563
- } else {
564
- peg$currPos = s0;
565
- s0 = peg$c1;
566
- }
567
-
568
- return s0;
569
- }
570
-
571
- function peg$parseidentifier_seq() {
572
- var s0, s1;
573
-
574
- s0 = [];
575
- s1 = peg$parseidentifier();
576
- while (s1 !== peg$FAILED) {
577
- s0.push(s1);
578
- s1 = peg$parseidentifier();
579
- }
580
-
581
- return s0;
582
- }
583
-
584
- function peg$parseidentifier() {
585
- var s0, s1, s2;
586
-
587
- s0 = peg$currPos;
588
- s1 = [];
589
- if (peg$c10.test(input.charAt(peg$currPos))) {
590
- s2 = input.charAt(peg$currPos);
591
- peg$currPos++;
592
- } else {
593
- s2 = peg$FAILED;
594
- if (peg$silentFails === 0) { peg$fail(peg$c11); }
595
- }
596
- if (s2 !== peg$FAILED) {
597
- while (s2 !== peg$FAILED) {
598
- s1.push(s2);
599
- if (peg$c10.test(input.charAt(peg$currPos))) {
600
- s2 = input.charAt(peg$currPos);
601
- peg$currPos++;
602
- } else {
603
- s2 = peg$FAILED;
604
- if (peg$silentFails === 0) { peg$fail(peg$c11); }
605
- }
606
- }
607
- } else {
608
- s1 = peg$c1;
609
- }
610
- if (s1 !== peg$FAILED) {
611
- s2 = peg$parseS();
612
- if (s2 !== peg$FAILED) {
613
- peg$reportedPos = s0;
614
- s1 = peg$c12(s1);
615
- s0 = s1;
616
- } else {
617
- peg$currPos = s0;
618
- s0 = peg$c1;
619
- }
620
- } else {
621
- peg$currPos = s0;
622
- s0 = peg$c1;
623
- }
624
-
625
- return s0;
626
- }
627
-
628
- function peg$parseidentifier_no_eol() {
629
- var s0, s1, s2;
630
-
631
- s0 = peg$currPos;
632
- s1 = [];
633
- if (peg$c13.test(input.charAt(peg$currPos))) {
634
- s2 = input.charAt(peg$currPos);
635
- peg$currPos++;
636
- } else {
637
- s2 = peg$FAILED;
638
- if (peg$silentFails === 0) { peg$fail(peg$c14); }
639
- }
640
- if (s2 !== peg$FAILED) {
641
- while (s2 !== peg$FAILED) {
642
- s1.push(s2);
643
- if (peg$c13.test(input.charAt(peg$currPos))) {
644
- s2 = input.charAt(peg$currPos);
645
- peg$currPos++;
646
- } else {
647
- s2 = peg$FAILED;
648
- if (peg$silentFails === 0) { peg$fail(peg$c14); }
649
- }
650
- }
651
- } else {
652
- s1 = peg$c1;
653
- }
654
- if (s1 !== peg$FAILED) {
655
- s2 = peg$parseS_no_eol();
656
- if (s2 !== peg$FAILED) {
657
- peg$reportedPos = s0;
658
- s1 = peg$c12(s1);
659
- s0 = s1;
660
- } else {
661
- peg$currPos = s0;
662
- s0 = peg$c1;
663
- }
664
- } else {
665
- peg$currPos = s0;
666
- s0 = peg$c1;
667
- }
668
-
669
- return s0;
670
- }
671
-
672
- function peg$parseArrow() {
673
- var s0, s1, s2;
674
-
675
- s0 = peg$currPos;
676
- if (input.substr(peg$currPos, 2) === peg$c15) {
677
- s1 = peg$c15;
678
- peg$currPos += 2;
679
- } else {
680
- s1 = peg$FAILED;
681
- if (peg$silentFails === 0) { peg$fail(peg$c16); }
682
- }
683
- if (s1 !== peg$FAILED) {
684
- s2 = peg$parseS_no_eol();
685
- if (s2 !== peg$FAILED) {
686
- s1 = [s1, s2];
687
- s0 = s1;
688
- } else {
689
- peg$currPos = s0;
690
- s0 = peg$c1;
691
- }
692
- } else {
693
- peg$currPos = s0;
694
- s0 = peg$c1;
695
- }
696
-
697
- return s0;
698
- }
699
-
700
- function peg$parsePathOpen() {
701
- var s0, s1, s2;
702
-
703
- s0 = peg$currPos;
704
- if (input.charCodeAt(peg$currPos) === 60) {
705
- s1 = peg$c17;
706
- peg$currPos++;
707
- } else {
708
- s1 = peg$FAILED;
709
- if (peg$silentFails === 0) { peg$fail(peg$c18); }
710
- }
711
- if (s1 !== peg$FAILED) {
712
- s2 = peg$parseS();
713
- if (s2 !== peg$FAILED) {
714
- s1 = [s1, s2];
715
- s0 = s1;
716
- } else {
717
- peg$currPos = s0;
718
- s0 = peg$c1;
719
- }
720
- } else {
721
- peg$currPos = s0;
722
- s0 = peg$c1;
723
- }
724
-
725
- return s0;
726
- }
727
-
728
- function peg$parsePathClose() {
729
- var s0, s1, s2;
730
-
731
- s0 = peg$currPos;
732
- if (input.charCodeAt(peg$currPos) === 62) {
733
- s1 = peg$c19;
734
- peg$currPos++;
735
- } else {
736
- s1 = peg$FAILED;
737
- if (peg$silentFails === 0) { peg$fail(peg$c20); }
738
- }
739
- if (s1 !== peg$FAILED) {
740
- s2 = peg$parseS();
741
- if (s2 !== peg$FAILED) {
742
- s1 = [s1, s2];
743
- s0 = s1;
744
- } else {
745
- peg$currPos = s0;
746
- s0 = peg$c1;
747
- }
748
- } else {
749
- peg$currPos = s0;
750
- s0 = peg$c1;
751
- }
752
-
753
- return s0;
754
- }
755
-
756
- function peg$parseEqual() {
757
- var s0, s1, s2;
758
-
759
- s0 = peg$currPos;
760
- if (input.charCodeAt(peg$currPos) === 61) {
761
- s1 = peg$c21;
762
- peg$currPos++;
763
- } else {
764
- s1 = peg$FAILED;
765
- if (peg$silentFails === 0) { peg$fail(peg$c22); }
766
- }
767
- if (s1 !== peg$FAILED) {
768
- s2 = peg$parseS();
769
- if (s2 !== peg$FAILED) {
770
- s1 = [s1, s2];
771
- s0 = s1;
772
- } else {
773
- peg$currPos = s0;
774
- s0 = peg$c1;
775
- }
776
- } else {
777
- peg$currPos = s0;
778
- s0 = peg$c1;
779
- }
780
-
781
- return s0;
782
- }
783
-
784
- function peg$parseHeadIndicator() {
785
- var s0, s1, s2;
786
-
787
- s0 = peg$currPos;
788
- if (input.charCodeAt(peg$currPos) === 42) {
789
- s1 = peg$c23;
790
- peg$currPos++;
791
- } else {
792
- s1 = peg$FAILED;
793
- if (peg$silentFails === 0) { peg$fail(peg$c24); }
794
- }
795
- if (s1 !== peg$FAILED) {
796
- s2 = peg$parseS_no_eol();
797
- if (s2 !== peg$FAILED) {
798
- s1 = [s1, s2];
799
- s0 = s1;
800
- } else {
801
- peg$currPos = s0;
802
- s0 = peg$c1;
803
- }
804
- } else {
805
- peg$currPos = s0;
806
- s0 = peg$c1;
807
- }
808
-
809
- return s0;
810
- }
811
-
812
- function peg$parseEOL() {
813
- var s0;
814
-
815
- if (input.substr(peg$currPos, 2) === peg$c25) {
816
- s0 = peg$c25;
817
- peg$currPos += 2;
818
- } else {
819
- s0 = peg$FAILED;
820
- if (peg$silentFails === 0) { peg$fail(peg$c26); }
821
- }
822
- if (s0 === peg$FAILED) {
823
- if (input.charCodeAt(peg$currPos) === 10) {
824
- s0 = peg$c27;
825
- peg$currPos++;
826
- } else {
827
- s0 = peg$FAILED;
828
- if (peg$silentFails === 0) { peg$fail(peg$c28); }
829
- }
830
- if (s0 === peg$FAILED) {
831
- if (input.charCodeAt(peg$currPos) === 13) {
832
- s0 = peg$c29;
833
- peg$currPos++;
834
- } else {
835
- s0 = peg$FAILED;
836
- if (peg$silentFails === 0) { peg$fail(peg$c30); }
837
- }
838
- }
839
- }
840
-
841
- return s0;
842
- }
843
-
844
- function peg$parseComment() {
845
- var s0, s1, s2, s3, s4, s5;
846
-
847
- s0 = peg$currPos;
848
- if (input.substr(peg$currPos, 2) === peg$c31) {
849
- s1 = peg$c31;
850
- peg$currPos += 2;
851
- } else {
852
- s1 = peg$FAILED;
853
- if (peg$silentFails === 0) { peg$fail(peg$c32); }
854
- }
855
- if (s1 !== peg$FAILED) {
856
- s2 = [];
857
- s3 = peg$currPos;
858
- s4 = peg$currPos;
859
- peg$silentFails++;
860
- s5 = peg$parseEOL();
861
- peg$silentFails--;
862
- if (s5 === peg$FAILED) {
863
- s4 = peg$c33;
864
- } else {
865
- peg$currPos = s4;
866
- s4 = peg$c1;
867
- }
868
- if (s4 !== peg$FAILED) {
869
- if (input.length > peg$currPos) {
870
- s5 = input.charAt(peg$currPos);
871
- peg$currPos++;
872
- } else {
873
- s5 = peg$FAILED;
874
- if (peg$silentFails === 0) { peg$fail(peg$c34); }
875
- }
876
- if (s5 !== peg$FAILED) {
877
- s4 = [s4, s5];
878
- s3 = s4;
879
- } else {
880
- peg$currPos = s3;
881
- s3 = peg$c1;
882
- }
883
- } else {
884
- peg$currPos = s3;
885
- s3 = peg$c1;
886
- }
887
- while (s3 !== peg$FAILED) {
888
- s2.push(s3);
889
- s3 = peg$currPos;
890
- s4 = peg$currPos;
891
- peg$silentFails++;
892
- s5 = peg$parseEOL();
893
- peg$silentFails--;
894
- if (s5 === peg$FAILED) {
895
- s4 = peg$c33;
896
- } else {
897
- peg$currPos = s4;
898
- s4 = peg$c1;
899
- }
900
- if (s4 !== peg$FAILED) {
901
- if (input.length > peg$currPos) {
902
- s5 = input.charAt(peg$currPos);
903
- peg$currPos++;
904
- } else {
905
- s5 = peg$FAILED;
906
- if (peg$silentFails === 0) { peg$fail(peg$c34); }
907
- }
908
- if (s5 !== peg$FAILED) {
909
- s4 = [s4, s5];
910
- s3 = s4;
911
- } else {
912
- peg$currPos = s3;
913
- s3 = peg$c1;
914
- }
915
- } else {
916
- peg$currPos = s3;
917
- s3 = peg$c1;
918
- }
919
- }
920
- if (s2 !== peg$FAILED) {
921
- s3 = peg$parseEOL();
922
- if (s3 === peg$FAILED) {
923
- s3 = peg$parseEOI();
924
- }
925
- if (s3 !== peg$FAILED) {
926
- s1 = [s1, s2, s3];
927
- s0 = s1;
928
- } else {
929
- peg$currPos = s0;
930
- s0 = peg$c1;
931
- }
932
- } else {
933
- peg$currPos = s0;
934
- s0 = peg$c1;
935
- }
936
- } else {
937
- peg$currPos = s0;
938
- s0 = peg$c1;
939
- }
940
-
941
- return s0;
942
- }
943
-
944
- function peg$parseS() {
945
- var s0, s1;
946
-
947
- s0 = [];
948
- if (input.charCodeAt(peg$currPos) === 32) {
949
- s1 = peg$c35;
950
- peg$currPos++;
951
- } else {
952
- s1 = peg$FAILED;
953
- if (peg$silentFails === 0) { peg$fail(peg$c36); }
954
- }
955
- if (s1 === peg$FAILED) {
956
- if (input.charCodeAt(peg$currPos) === 9) {
957
- s1 = peg$c37;
958
- peg$currPos++;
959
- } else {
960
- s1 = peg$FAILED;
961
- if (peg$silentFails === 0) { peg$fail(peg$c38); }
962
- }
963
- if (s1 === peg$FAILED) {
964
- s1 = peg$parseEOL();
965
- if (s1 === peg$FAILED) {
966
- s1 = peg$parseComment();
967
- }
968
- }
969
- }
970
- while (s1 !== peg$FAILED) {
971
- s0.push(s1);
972
- if (input.charCodeAt(peg$currPos) === 32) {
973
- s1 = peg$c35;
974
- peg$currPos++;
975
- } else {
976
- s1 = peg$FAILED;
977
- if (peg$silentFails === 0) { peg$fail(peg$c36); }
978
- }
979
- if (s1 === peg$FAILED) {
980
- if (input.charCodeAt(peg$currPos) === 9) {
981
- s1 = peg$c37;
982
- peg$currPos++;
983
- } else {
984
- s1 = peg$FAILED;
985
- if (peg$silentFails === 0) { peg$fail(peg$c38); }
986
- }
987
- if (s1 === peg$FAILED) {
988
- s1 = peg$parseEOL();
989
- if (s1 === peg$FAILED) {
990
- s1 = peg$parseComment();
991
- }
992
- }
993
- }
994
- }
995
-
996
- return s0;
997
- }
998
-
999
- function peg$parseS_no_eol() {
1000
- var s0, s1;
1001
-
1002
- s0 = [];
1003
- if (input.charCodeAt(peg$currPos) === 32) {
1004
- s1 = peg$c35;
1005
- peg$currPos++;
1006
- } else {
1007
- s1 = peg$FAILED;
1008
- if (peg$silentFails === 0) { peg$fail(peg$c36); }
1009
- }
1010
- if (s1 === peg$FAILED) {
1011
- if (input.charCodeAt(peg$currPos) === 9) {
1012
- s1 = peg$c37;
1013
- peg$currPos++;
1014
- } else {
1015
- s1 = peg$FAILED;
1016
- if (peg$silentFails === 0) { peg$fail(peg$c38); }
1017
- }
1018
- if (s1 === peg$FAILED) {
1019
- s1 = peg$parseComment();
1020
- }
1021
- }
1022
- while (s1 !== peg$FAILED) {
1023
- s0.push(s1);
1024
- if (input.charCodeAt(peg$currPos) === 32) {
1025
- s1 = peg$c35;
1026
- peg$currPos++;
1027
- } else {
1028
- s1 = peg$FAILED;
1029
- if (peg$silentFails === 0) { peg$fail(peg$c36); }
1030
- }
1031
- if (s1 === peg$FAILED) {
1032
- if (input.charCodeAt(peg$currPos) === 9) {
1033
- s1 = peg$c37;
1034
- peg$currPos++;
1035
- } else {
1036
- s1 = peg$FAILED;
1037
- if (peg$silentFails === 0) { peg$fail(peg$c38); }
1038
- }
1039
- if (s1 === peg$FAILED) {
1040
- s1 = peg$parseComment();
1041
- }
1042
- }
1043
- }
1044
-
1045
- return s0;
1046
- }
1047
-
1048
- function peg$parseEOI() {
1049
- var s0, s1;
1050
-
1051
- s0 = peg$currPos;
1052
- peg$silentFails++;
1053
- if (input.length > peg$currPos) {
1054
- s1 = input.charAt(peg$currPos);
1055
- peg$currPos++;
1056
- } else {
1057
- s1 = peg$FAILED;
1058
- if (peg$silentFails === 0) { peg$fail(peg$c34); }
1059
- }
1060
- peg$silentFails--;
1061
- if (s1 === peg$FAILED) {
1062
- s0 = peg$c33;
1063
- } else {
1064
- peg$currPos = s0;
1065
- s0 = peg$c1;
1066
- }
1067
-
1068
- return s0;
1069
- }
1070
-
1071
-
1072
- var is_CNF = true;
1073
- var nonterminals = {};
1074
- var symbols = {};
1075
-
1076
- function Atom(val) {
1077
- this.atom = val;
1078
- }
1079
-
1080
- function Path(ids) {
1081
- this.path = ids;
1082
- }
1083
-
1084
- function Rule(lhs, rhs, head) {
1085
- this.lhs = lhs;
1086
- this.rhs = rhs;
1087
- this.head = head;
1088
- }
1089
-
1090
- function Constraint(left_op, right_op) {
1091
- this.left = left_op;
1092
- this.right = right_op;
1093
- }
1094
-
1095
- function Grammar() {
1096
- this.production_rules = [];
1097
- this.nonterminals = {};
1098
- this.symbols = {};
1099
- this.start_symbol = "";
1100
- this.is_CNF = true;
1101
- }
1102
-
1103
- //Checks if B is a nonterminal
1104
- Grammar.prototype.is_nonterminal = function(B) {
1105
- console.log("Checking if " + B + " is a nonterminal: " + this.nonterminals[B]);
1106
- return (this.nonterminals[B]);
1107
- };
1108
-
1109
- //Checks if B is a (pre)terminal
1110
- Grammar.prototype.is_terminal = function(B) {
1111
- console.log("Checking if " + B + " is a (pre)terminal: " + !this.nonterminals[B]);
1112
- return (!this.nonterminals[B]);
1113
- };
1114
-
1115
- // Looks up all rules with lhs B
1116
- Grammar.prototype.rules_with_lhs = function(B) {
1117
- var rules = [];
1118
-
1119
- this.production_rules.forEach(function(rule) {
1120
- if (rule.lhs === B) {
1121
- rules.push(rule);
1122
- }
1123
- });
1124
- return(rules);
1125
- };
1126
-
1127
- // Returns the start production rule which is the first rule read from file
1128
- Grammar.prototype.start_rule = function() {
1129
- return(this.production_rules[0]);
1130
- };
1131
-
1132
- // Returns the start symbol
1133
- Grammar.prototype.get_start_symbol = function() {
1134
- return(this.start_symbol);
1135
- };
1136
-
1137
- // Returns all rules that match right hand side nonterminals s and t
1138
- Grammar.prototype.get_rules_with_rhs = function(s, t) {
1139
- var res = [];
1140
-
1141
- this.production_rules.forEach(function(rule) {
1142
- if ((rule.rhs.length === 2) && (rule.rhs[0] === s) && (rule.rhs[1] === t)) {
1143
- res.push(rule);
1144
- }
1145
- });
1146
- return res;
1147
- };
1148
-
1149
- // Based on: http://folk.uio.no/plison/pdfs/lectures/compling2010/pdfs/compling2010-parsingcfg-solutions.pdf
1150
- Grammar.prototype.compute_lc_relation = function() {
1151
- that = this;
1152
- // Compute the first order lc relation
1153
- this.lc = {};
1154
- this.production_rules.forEach(function(rule) {
1155
- if (!that.lc[rule.lhs]) {
1156
- that.lc[rule.lhs] = {};
1157
- }
1158
- if (that.is_nonterminal(rule.rhs[0])) {
1159
- that.lc[rule.lhs][rule.rhs[0]] = true;
1160
- }
1161
- });
1162
- // Reflexive closure
1163
- Object.keys(this.nonterminals).forEach(function(A){
1164
- if (!that.lc[A]) {
1165
- that.lc[A] = {};
1166
- }
1167
- that.lc[A][A] = true;
1168
- });
1169
- // Transitive closure
1170
- var changed;
1171
- do {
1172
- changed = false;
1173
- Object.keys(this.nonterminals).forEach(function(A) {
1174
- Object.keys(that.lc[A]).forEach(function(B) {
1175
- Object.keys(that.lc[B]).forEach(function(C) {
1176
- if (!that.lc[A][C]) {
1177
- // add all left corners of C to A
1178
- Object.keys(that.lc[C]).forEach(function(D){
1179
- that.lc[A][D] = true;
1180
- changed = true;
1181
- });
1182
- }
1183
- });
1184
- });
1185
- });
1186
- } while (changed);
1187
- };
1188
-
1189
- Grammar.prototype.rules_with_leftmost_daughter = function (B) {
1190
- rules = [];
1191
-
1192
- this.production_rules.forEach(function(rule) {
1193
- if (rule.rhs[0] === B) {
1194
- rules.push(rule);
1195
- }
1196
- });
1197
- return(rules);
1198
- };
1199
-
1200
- Grammar.prototype.is_leftcorner_of = function(B, C) {
1201
- if (this.lc[C]) {
1202
- return(this.lc[C][B]);
1203
- }
1204
- else {
1205
- return(false);
1206
- }
1207
- };
1208
-
1209
- // Check if nonterminal A is head-corner of nonterminal B
1210
- Grammar.prototype.is_headcorner_of = function(A, B) {
1211
- if (this.hc[B]) {
1212
- return(this.hc[B][A]);
1213
- }
1214
- else {
1215
- return(false);
1216
- }
1217
- }
1218
-
1219
- // Get rules with nonterminal H as head
1220
- Grammar.prototype.get_rules_with_head = function(H) {
1221
- var res = [];
1222
-
1223
- this.production_rules.forEach(function(rule) {
1224
- if (rule.rhs[rule.head] === H) {
1225
- res.push(rule);
1226
- }
1227
- });
1228
- return(res);
1229
- };
1230
-
1231
- // Computation of the head-corner relation follows the pattern of the
1232
- // computation of the lef-corner relation
1233
- Grammar.prototype.compute_hc_relation = function() {
1234
- that = this;
1235
- // Compute the first order hc relation
1236
- this.hc = {};
1237
- this.production_rules.forEach(function(rule) {
1238
- if (!that.hc[rule.lhs]) {
1239
- that.hc[rule.lhs] = {};
1240
- }
1241
- that.hc[rule.lhs][rule.rhs[rule.head]] = true;
1242
- });
1243
- // Reflexive closure
1244
- Object.keys(this.symbols).forEach(function(A){
1245
- if (!that.hc[A]) {
1246
- that.hc[A] = {};
1247
- }
1248
- that.hc[A][A] = true;
1249
- });
1250
- // Transitive closure
1251
- var changed;
1252
- do {
1253
- changed = false;
1254
- Object.keys(this.symbols).forEach(function(A) {
1255
- Object.keys(that.hc[A]).forEach(function(B) {
1256
- Object.keys(that.hc[B]).forEach(function(C) {
1257
- if (!that.hc[A][C]) {
1258
- // add all head corners of C to A
1259
- Object.keys(that.hc[C]).forEach(function(D){
1260
- that.hc[A][D] = true;
1261
- changed = true;
1262
- });
1263
- }
1264
- });
1265
- });
1266
- });
1267
- } while (changed);
1268
- };
1269
-
1270
-
1271
-
1272
- peg$result = peg$startRuleFunction();
1273
-
1274
- if (peg$result !== peg$FAILED && peg$currPos === input.length) {
1275
- return peg$result;
1276
- } else {
1277
- if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1278
- peg$fail({ type: "end", description: "end of input" });
1279
- }
1280
-
1281
- throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
1282
- }
1283
- }
1284
-
1285
- return {
1286
- SyntaxError: SyntaxError,
1287
- parse: parse
1288
- };
1289
- })();