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.
- package/.editorconfig +7 -0
- package/README.md +3 -3
- package/lib/natural/inflectors/present_verb_inflector.js +1 -0
- package/lib/natural/phonetics/double_metaphone.js +9 -4
- package/lib/natural/phonetics/metaphone.js +4 -0
- package/lib/natural/phonetics/soundex.js +11 -7
- package/lib/natural/stemmers/porter_stemmer.js +90 -62
- package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
- package/lib/natural/stemmers/stemmer_pt.js +65 -0
- package/lib/natural/stemmers/token.js +163 -0
- package/lib/natural/util/stopwords_pt.js +136 -0
- package/package.json +2 -2
- package/spec/double_metaphone_spec.js +10 -1
- package/spec/metaphone_spec.js +5 -0
- package/spec/porter_stemmer_pt_spec.js +50 -0
- package/spec/porter_stemmer_spec.js +45 -0
- package/spec/present_verb_inflector_spec.js +3 -0
- package/spec/soundex_spec.js +13 -9
- package/spec/stemmer_token_spec.js +161 -0
- package/spec/test_data/snowball_pt.txt +32016 -0
- package/coverage/coverage.json +0 -1
- package/coverage/lcov-report/index.html +0 -584
- package/coverage/lcov-report/io_spec/index.html +0 -350
- package/coverage/lcov-report/io_spec/tfidf_spec.js.html +0 -469
- package/coverage/lcov-report/lib/natural/analyzers/index.html +0 -350
- package/coverage/lcov-report/lib/natural/analyzers/sentence_analyzer.js.html +0 -850
- package/coverage/lcov-report/lib/natural/classifiers/bayes_classifier.js.html +0 -496
- package/coverage/lcov-report/lib/natural/classifiers/classifier.js.html +0 -823
- package/coverage/lcov-report/lib/natural/classifiers/index.html +0 -376
- package/coverage/lcov-report/lib/natural/classifiers/logistic_regression_classifier.js.html +0 -502
- package/coverage/lcov-report/lib/natural/distance/dice_coefficient.js.html +0 -529
- package/coverage/lcov-report/lib/natural/distance/index.html +0 -376
- package/coverage/lcov-report/lib/natural/distance/jaro-winkler_distance.js.html +0 -670
- package/coverage/lcov-report/lib/natural/distance/levenshtein_distance.js.html +0 -526
- package/coverage/lcov-report/lib/natural/index.html +0 -350
- package/coverage/lcov-report/lib/natural/index.js.html +0 -547
- package/coverage/lcov-report/lib/natural/inflectors/count_inflector.js.html +0 -484
- package/coverage/lcov-report/lib/natural/inflectors/form_set.js.html +0 -406
- package/coverage/lcov-report/lib/natural/inflectors/fr/count_inflector.js.html +0 -520
- package/coverage/lcov-report/lib/natural/inflectors/fr/index.html +0 -363
- package/coverage/lcov-report/lib/natural/inflectors/fr/noun_inflector.js.html +0 -1027
- package/coverage/lcov-report/lib/natural/inflectors/index.html +0 -402
- package/coverage/lcov-report/lib/natural/inflectors/ja/index.html +0 -350
- package/coverage/lcov-report/lib/natural/inflectors/ja/noun_inflector.js.html +0 -727
- package/coverage/lcov-report/lib/natural/inflectors/noun_inflector.js.html +0 -637
- package/coverage/lcov-report/lib/natural/inflectors/present_verb_inflector.js.html +0 -544
- package/coverage/lcov-report/lib/natural/inflectors/singular_plural_inflector.js.html +0 -649
- package/coverage/lcov-report/lib/natural/ngrams/index.html +0 -363
- package/coverage/lcov-report/lib/natural/ngrams/ngrams.js.html +0 -595
- package/coverage/lcov-report/lib/natural/ngrams/ngrams_zh.js.html +0 -571
- package/coverage/lcov-report/lib/natural/normalizers/index.html +0 -389
- package/coverage/lcov-report/lib/natural/normalizers/normalizer.js.html +0 -607
- package/coverage/lcov-report/lib/natural/normalizers/normalizer_ja.js.html +0 -2194
- package/coverage/lcov-report/lib/natural/normalizers/normalizer_no.js.html +0 -496
- package/coverage/lcov-report/lib/natural/normalizers/remove_diacritics.js.html +0 -685
- package/coverage/lcov-report/lib/natural/phonetics/dm_soundex.js.html +0 -1063
- package/coverage/lcov-report/lib/natural/phonetics/double_metaphone.js.html +0 -1840
- package/coverage/lcov-report/lib/natural/phonetics/index.html +0 -402
- package/coverage/lcov-report/lib/natural/phonetics/metaphone.js.html +0 -886
- package/coverage/lcov-report/lib/natural/phonetics/phonetic.js.html +0 -484
- package/coverage/lcov-report/lib/natural/phonetics/soundex.js.html +0 -562
- package/coverage/lcov-report/lib/natural/spellcheck/index.html +0 -350
- package/coverage/lcov-report/lib/natural/spellcheck/spellcheck.js.html +0 -562
- package/coverage/lcov-report/lib/natural/stemmers/index.html +0 -571
- package/coverage/lcov-report/lib/natural/stemmers/lancaster_rules.js.html +0 -2692
- package/coverage/lcov-report/lib/natural/stemmers/lancaster_stemmer.js.html +0 -544
- package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer.js.html +0 -937
- package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_es.js.html +0 -985
- package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_fa.js.html +0 -418
- package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_fr.js.html +0 -1450
- package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_it.js.html +0 -1018
- package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_no.js.html +0 -784
- package/coverage/lcov-report/lib/natural/stemmers/porter_stemmer_ru.js.html +0 -775
- package/coverage/lcov-report/lib/natural/stemmers/stemmer.js.html +0 -505
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_es.js.html +0 -496
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_fa.js.html +0 -484
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_fr.js.html +0 -496
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_it.js.html +0 -427
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_ja.js.html +0 -736
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_no.js.html +0 -505
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_pl.js.html +0 -496
- package/coverage/lcov-report/lib/natural/stemmers/stemmer_ru.js.html +0 -496
- package/coverage/lcov-report/lib/natural/tfidf/index.html +0 -350
- package/coverage/lcov-report/lib/natural/tfidf/tfidf.js.html +0 -904
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer.js.html +0 -430
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_es.js.html +0 -430
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_fa.js.html +0 -466
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_fr.js.html +0 -430
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_it.js.html +0 -430
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_nl.js.html +0 -430
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_no.js.html +0 -439
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_pl.js.html +0 -457
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_pt.js.html +0 -442
- package/coverage/lcov-report/lib/natural/tokenizers/aggressive_tokenizer_ru.js.html +0 -457
- package/coverage/lcov-report/lib/natural/tokenizers/index.html +0 -519
- package/coverage/lcov-report/lib/natural/tokenizers/regexp_tokenizer.js.html +0 -580
- package/coverage/lcov-report/lib/natural/tokenizers/tokenizer.js.html +0 -475
- package/coverage/lcov-report/lib/natural/tokenizers/tokenizer_ja.js.html +0 -1153
- package/coverage/lcov-report/lib/natural/tokenizers/treebank_word_tokenizer.js.html +0 -544
- package/coverage/lcov-report/lib/natural/transliterators/ja/index.html +0 -350
- package/coverage/lcov-report/lib/natural/transliterators/ja/index.js.html +0 -2068
- package/coverage/lcov-report/lib/natural/trie/index.html +0 -350
- package/coverage/lcov-report/lib/natural/trie/trie.js.html +0 -1012
- package/coverage/lcov-report/lib/natural/util/bag.js.html +0 -472
- package/coverage/lcov-report/lib/natural/util/edge_weighted_digraph.js.html +0 -658
- package/coverage/lcov-report/lib/natural/util/index.html +0 -532
- package/coverage/lcov-report/lib/natural/util/longest_path_tree.js.html +0 -619
- package/coverage/lcov-report/lib/natural/util/shortest_path_tree.js.html +0 -622
- package/coverage/lcov-report/lib/natural/util/stopwords.js.html +0 -445
- package/coverage/lcov-report/lib/natural/util/stopwords_es.js.html +0 -430
- package/coverage/lcov-report/lib/natural/util/stopwords_fa.js.html +0 -436
- package/coverage/lcov-report/lib/natural/util/stopwords_fr.js.html +0 -904
- package/coverage/lcov-report/lib/natural/util/stopwords_it.js.html +0 -478
- package/coverage/lcov-report/lib/natural/util/stopwords_ja.js.html +0 -499
- package/coverage/lcov-report/lib/natural/util/stopwords_no.js.html +0 -445
- package/coverage/lcov-report/lib/natural/util/stopwords_pl.js.html +0 -508
- package/coverage/lcov-report/lib/natural/util/stopwords_ru.js.html +0 -445
- package/coverage/lcov-report/lib/natural/util/topological.js.html +0 -616
- package/coverage/lcov-report/lib/natural/util/utils.js.html +0 -679
- package/coverage/lcov-report/lib/natural/wordnet/data_file.js.html +0 -580
- package/coverage/lcov-report/lib/natural/wordnet/index.html +0 -389
- package/coverage/lcov-report/lib/natural/wordnet/index_file.js.html +0 -742
- package/coverage/lcov-report/lib/natural/wordnet/wordnet.js.html +0 -829
- package/coverage/lcov-report/lib/natural/wordnet/wordnet_file.js.html +0 -529
- package/coverage/lcov-report/natural/analyzers/index.html +0 -350
- package/coverage/lcov-report/natural/analyzers/sentence_analyzer.js.html +0 -850
- package/coverage/lcov-report/natural/classifiers/bayes_classifier.js.html +0 -496
- package/coverage/lcov-report/natural/classifiers/classifier.js.html +0 -823
- package/coverage/lcov-report/natural/classifiers/index.html +0 -376
- package/coverage/lcov-report/natural/classifiers/logistic_regression_classifier.js.html +0 -502
- package/coverage/lcov-report/natural/distance/dice_coefficient.js.html +0 -529
- package/coverage/lcov-report/natural/distance/index.html +0 -376
- package/coverage/lcov-report/natural/distance/jaro-winkler_distance.js.html +0 -670
- package/coverage/lcov-report/natural/distance/levenshtein_distance.js.html +0 -526
- package/coverage/lcov-report/natural/index.html +0 -350
- package/coverage/lcov-report/natural/index.js.html +0 -433
- package/coverage/lcov-report/natural/inflectors/count_inflector.js.html +0 -484
- package/coverage/lcov-report/natural/inflectors/form_set.js.html +0 -406
- package/coverage/lcov-report/natural/inflectors/fr/index.html +0 -350
- package/coverage/lcov-report/natural/inflectors/fr/noun_inflector.js.html +0 -1027
- package/coverage/lcov-report/natural/inflectors/index.html +0 -402
- package/coverage/lcov-report/natural/inflectors/ja/index.html +0 -350
- package/coverage/lcov-report/natural/inflectors/ja/noun_inflector.js.html +0 -727
- package/coverage/lcov-report/natural/inflectors/noun_inflector.js.html +0 -637
- package/coverage/lcov-report/natural/inflectors/present_verb_inflector.js.html +0 -544
- package/coverage/lcov-report/natural/inflectors/singular_plural_inflector.js.html +0 -649
- package/coverage/lcov-report/natural/lib/natural/analyzers/index.html +0 -350
- package/coverage/lcov-report/natural/lib/natural/analyzers/sentence_analyzer.js.html +0 -850
- package/coverage/lcov-report/natural/lib/natural/classifiers/bayes_classifier.js.html +0 -496
- package/coverage/lcov-report/natural/lib/natural/classifiers/classifier.js.html +0 -823
- package/coverage/lcov-report/natural/lib/natural/classifiers/index.html +0 -376
- package/coverage/lcov-report/natural/lib/natural/classifiers/logistic_regression_classifier.js.html +0 -502
- package/coverage/lcov-report/natural/lib/natural/distance/dice_coefficient.js.html +0 -529
- package/coverage/lcov-report/natural/lib/natural/distance/index.html +0 -376
- package/coverage/lcov-report/natural/lib/natural/distance/jaro-winkler_distance.js.html +0 -670
- package/coverage/lcov-report/natural/lib/natural/distance/levenshtein_distance.js.html +0 -526
- package/coverage/lcov-report/natural/lib/natural/index.html +0 -350
- package/coverage/lcov-report/natural/lib/natural/index.js.html +0 -547
- package/coverage/lcov-report/natural/lib/natural/inflectors/count_inflector.js.html +0 -484
- package/coverage/lcov-report/natural/lib/natural/inflectors/form_set.js.html +0 -406
- package/coverage/lcov-report/natural/lib/natural/inflectors/fr/index.html +0 -350
- package/coverage/lcov-report/natural/lib/natural/inflectors/fr/noun_inflector.js.html +0 -1027
- package/coverage/lcov-report/natural/lib/natural/inflectors/index.html +0 -402
- package/coverage/lcov-report/natural/lib/natural/inflectors/ja/index.html +0 -350
- package/coverage/lcov-report/natural/lib/natural/inflectors/ja/noun_inflector.js.html +0 -727
- package/coverage/lcov-report/natural/lib/natural/inflectors/noun_inflector.js.html +0 -637
- package/coverage/lcov-report/natural/lib/natural/inflectors/present_verb_inflector.js.html +0 -544
- package/coverage/lcov-report/natural/lib/natural/inflectors/singular_plural_inflector.js.html +0 -649
- package/coverage/lcov-report/natural/lib/natural/ngrams/index.html +0 -363
- package/coverage/lcov-report/natural/lib/natural/ngrams/ngrams.js.html +0 -595
- package/coverage/lcov-report/natural/lib/natural/ngrams/ngrams_zh.js.html +0 -571
- package/coverage/lcov-report/natural/lib/natural/normalizers/index.html +0 -389
- package/coverage/lcov-report/natural/lib/natural/normalizers/normalizer.js.html +0 -607
- package/coverage/lcov-report/natural/lib/natural/normalizers/normalizer_ja.js.html +0 -2194
- package/coverage/lcov-report/natural/lib/natural/normalizers/normalizer_no.js.html +0 -496
- package/coverage/lcov-report/natural/lib/natural/normalizers/remove_diacritics.js.html +0 -685
- package/coverage/lcov-report/natural/lib/natural/phonetics/dm_soundex.js.html +0 -1063
- package/coverage/lcov-report/natural/lib/natural/phonetics/double_metaphone.js.html +0 -1840
- package/coverage/lcov-report/natural/lib/natural/phonetics/index.html +0 -402
- package/coverage/lcov-report/natural/lib/natural/phonetics/metaphone.js.html +0 -886
- package/coverage/lcov-report/natural/lib/natural/phonetics/phonetic.js.html +0 -484
- package/coverage/lcov-report/natural/lib/natural/phonetics/soundex.js.html +0 -562
- package/coverage/lcov-report/natural/lib/natural/stemmers/index.html +0 -571
- package/coverage/lcov-report/natural/lib/natural/stemmers/lancaster_rules.js.html +0 -2692
- package/coverage/lcov-report/natural/lib/natural/stemmers/lancaster_stemmer.js.html +0 -544
- package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer.js.html +0 -937
- package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_es.js.html +0 -985
- package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_fa.js.html +0 -418
- package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_fr.js.html +0 -1450
- package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_it.js.html +0 -1018
- package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_no.js.html +0 -784
- package/coverage/lcov-report/natural/lib/natural/stemmers/porter_stemmer_ru.js.html +0 -775
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer.js.html +0 -505
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_es.js.html +0 -496
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_fa.js.html +0 -484
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_fr.js.html +0 -496
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_it.js.html +0 -427
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_ja.js.html +0 -736
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_no.js.html +0 -505
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_pl.js.html +0 -496
- package/coverage/lcov-report/natural/lib/natural/stemmers/stemmer_ru.js.html +0 -496
- package/coverage/lcov-report/natural/lib/natural/tfidf/index.html +0 -350
- package/coverage/lcov-report/natural/lib/natural/tfidf/tfidf.js.html +0 -904
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer.js.html +0 -430
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_es.js.html +0 -430
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_fa.js.html +0 -466
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_fr.js.html +0 -430
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_it.js.html +0 -430
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_nl.js.html +0 -430
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_no.js.html +0 -439
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_pl.js.html +0 -457
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_pt.js.html +0 -442
- package/coverage/lcov-report/natural/lib/natural/tokenizers/aggressive_tokenizer_ru.js.html +0 -457
- package/coverage/lcov-report/natural/lib/natural/tokenizers/index.html +0 -519
- package/coverage/lcov-report/natural/lib/natural/tokenizers/regexp_tokenizer.js.html +0 -580
- package/coverage/lcov-report/natural/lib/natural/tokenizers/tokenizer.js.html +0 -475
- package/coverage/lcov-report/natural/lib/natural/tokenizers/tokenizer_ja.js.html +0 -1153
- package/coverage/lcov-report/natural/lib/natural/tokenizers/treebank_word_tokenizer.js.html +0 -544
- package/coverage/lcov-report/natural/lib/natural/transliterators/ja/index.html +0 -350
- package/coverage/lcov-report/natural/lib/natural/transliterators/ja/index.js.html +0 -2068
- package/coverage/lcov-report/natural/lib/natural/trie/index.html +0 -350
- package/coverage/lcov-report/natural/lib/natural/trie/trie.js.html +0 -1012
- package/coverage/lcov-report/natural/lib/natural/util/bag.js.html +0 -472
- package/coverage/lcov-report/natural/lib/natural/util/edge_weighted_digraph.js.html +0 -658
- package/coverage/lcov-report/natural/lib/natural/util/index.html +0 -532
- package/coverage/lcov-report/natural/lib/natural/util/longest_path_tree.js.html +0 -619
- package/coverage/lcov-report/natural/lib/natural/util/shortest_path_tree.js.html +0 -622
- package/coverage/lcov-report/natural/lib/natural/util/stopwords.js.html +0 -445
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_es.js.html +0 -430
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_fa.js.html +0 -436
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_fr.js.html +0 -904
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_it.js.html +0 -478
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_ja.js.html +0 -499
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_no.js.html +0 -445
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_pl.js.html +0 -508
- package/coverage/lcov-report/natural/lib/natural/util/stopwords_ru.js.html +0 -445
- package/coverage/lcov-report/natural/lib/natural/util/topological.js.html +0 -616
- package/coverage/lcov-report/natural/lib/natural/util/utils.js.html +0 -679
- package/coverage/lcov-report/natural/lib/natural/wordnet/data_file.js.html +0 -580
- package/coverage/lcov-report/natural/lib/natural/wordnet/index.html +0 -389
- package/coverage/lcov-report/natural/lib/natural/wordnet/index_file.js.html +0 -742
- package/coverage/lcov-report/natural/lib/natural/wordnet/wordnet.js.html +0 -829
- package/coverage/lcov-report/natural/lib/natural/wordnet/wordnet_file.js.html +0 -529
- package/coverage/lcov-report/natural/ngrams/index.html +0 -363
- package/coverage/lcov-report/natural/ngrams/ngrams.js.html +0 -595
- package/coverage/lcov-report/natural/ngrams/ngrams_zh.js.html +0 -571
- package/coverage/lcov-report/natural/normalizers/index.html +0 -389
- package/coverage/lcov-report/natural/normalizers/normalizer.js.html +0 -607
- package/coverage/lcov-report/natural/normalizers/normalizer_ja.js.html +0 -2194
- package/coverage/lcov-report/natural/normalizers/normalizer_no.js.html +0 -496
- package/coverage/lcov-report/natural/normalizers/remove_diacritics.js.html +0 -685
- package/coverage/lcov-report/natural/phonetics/dm_soundex.js.html +0 -1063
- package/coverage/lcov-report/natural/phonetics/double_metaphone.js.html +0 -1840
- package/coverage/lcov-report/natural/phonetics/index.html +0 -402
- package/coverage/lcov-report/natural/phonetics/metaphone.js.html +0 -886
- package/coverage/lcov-report/natural/phonetics/phonetic.js.html +0 -484
- package/coverage/lcov-report/natural/phonetics/soundex.js.html +0 -562
- package/coverage/lcov-report/natural/stemmers/index.html +0 -571
- package/coverage/lcov-report/natural/stemmers/lancaster_rules.js.html +0 -2692
- package/coverage/lcov-report/natural/stemmers/lancaster_stemmer.js.html +0 -544
- package/coverage/lcov-report/natural/stemmers/porter_stemmer.js.html +0 -937
- package/coverage/lcov-report/natural/stemmers/porter_stemmer_es.js.html +0 -985
- package/coverage/lcov-report/natural/stemmers/porter_stemmer_fa.js.html +0 -418
- package/coverage/lcov-report/natural/stemmers/porter_stemmer_fr.js.html +0 -1450
- package/coverage/lcov-report/natural/stemmers/porter_stemmer_it.js.html +0 -1018
- package/coverage/lcov-report/natural/stemmers/porter_stemmer_no.js.html +0 -784
- package/coverage/lcov-report/natural/stemmers/porter_stemmer_ru.js.html +0 -775
- package/coverage/lcov-report/natural/stemmers/stemmer.js.html +0 -505
- package/coverage/lcov-report/natural/stemmers/stemmer_es.js.html +0 -496
- package/coverage/lcov-report/natural/stemmers/stemmer_fa.js.html +0 -484
- package/coverage/lcov-report/natural/stemmers/stemmer_fr.js.html +0 -496
- package/coverage/lcov-report/natural/stemmers/stemmer_it.js.html +0 -427
- package/coverage/lcov-report/natural/stemmers/stemmer_ja.js.html +0 -736
- package/coverage/lcov-report/natural/stemmers/stemmer_no.js.html +0 -505
- package/coverage/lcov-report/natural/stemmers/stemmer_pl.js.html +0 -496
- package/coverage/lcov-report/natural/stemmers/stemmer_ru.js.html +0 -496
- package/coverage/lcov-report/natural/tfidf/index.html +0 -350
- package/coverage/lcov-report/natural/tfidf/tfidf.js.html +0 -904
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer.js.html +0 -430
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_es.js.html +0 -430
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_fa.js.html +0 -466
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_fr.js.html +0 -430
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_it.js.html +0 -430
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_nl.js.html +0 -430
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_no.js.html +0 -439
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_pl.js.html +0 -457
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_pt.js.html +0 -442
- package/coverage/lcov-report/natural/tokenizers/aggressive_tokenizer_ru.js.html +0 -457
- package/coverage/lcov-report/natural/tokenizers/index.html +0 -519
- package/coverage/lcov-report/natural/tokenizers/regexp_tokenizer.js.html +0 -580
- package/coverage/lcov-report/natural/tokenizers/tokenizer.js.html +0 -475
- package/coverage/lcov-report/natural/tokenizers/tokenizer_ja.js.html +0 -1153
- package/coverage/lcov-report/natural/tokenizers/treebank_word_tokenizer.js.html +0 -544
- package/coverage/lcov-report/natural/transliterators/ja/index.html +0 -350
- package/coverage/lcov-report/natural/transliterators/ja/index.js.html +0 -2068
- package/coverage/lcov-report/natural/trie/index.html +0 -350
- package/coverage/lcov-report/natural/trie/trie.js.html +0 -1012
- package/coverage/lcov-report/natural/util/bag.js.html +0 -472
- package/coverage/lcov-report/natural/util/edge_weighted_digraph.js.html +0 -658
- package/coverage/lcov-report/natural/util/index.html +0 -532
- package/coverage/lcov-report/natural/util/longest_path_tree.js.html +0 -619
- package/coverage/lcov-report/natural/util/shortest_path_tree.js.html +0 -622
- package/coverage/lcov-report/natural/util/stopwords.js.html +0 -445
- package/coverage/lcov-report/natural/util/stopwords_es.js.html +0 -430
- package/coverage/lcov-report/natural/util/stopwords_fa.js.html +0 -436
- package/coverage/lcov-report/natural/util/stopwords_fr.js.html +0 -904
- package/coverage/lcov-report/natural/util/stopwords_it.js.html +0 -478
- package/coverage/lcov-report/natural/util/stopwords_ja.js.html +0 -499
- package/coverage/lcov-report/natural/util/stopwords_no.js.html +0 -445
- package/coverage/lcov-report/natural/util/stopwords_pl.js.html +0 -508
- package/coverage/lcov-report/natural/util/stopwords_ru.js.html +0 -445
- package/coverage/lcov-report/natural/util/topological.js.html +0 -616
- package/coverage/lcov-report/natural/util/utils.js.html +0 -679
- package/coverage/lcov-report/natural/wordnet/data_file.js.html +0 -580
- package/coverage/lcov-report/natural/wordnet/index.html +0 -389
- package/coverage/lcov-report/natural/wordnet/index_file.js.html +0 -742
- package/coverage/lcov-report/natural/wordnet/wordnet.js.html +0 -829
- package/coverage/lcov-report/natural/wordnet/wordnet_file.js.html +0 -529
- package/coverage/lcov-report/normalizers/index.html +0 -350
- package/coverage/lcov-report/normalizers/normalizer.js.html +0 -607
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -1
- package/coverage/lcov-report/spec/aggressive_tokenizer_es_spec.js.html +0 -430
- package/coverage/lcov-report/spec/aggressive_tokenizer_fr_spec.js.html +0 -625
- package/coverage/lcov-report/spec/aggressive_tokenizer_nl_spec.js.html +0 -430
- package/coverage/lcov-report/spec/aggressive_tokenizer_pt_spec.js.html +0 -490
- package/coverage/lcov-report/spec/aggressive_tokenizer_spec.js.html +0 -490
- package/coverage/lcov-report/spec/bayes_classifier_spec.js.html +0 -841
- package/coverage/lcov-report/spec/classifier_spec.js.html +0 -847
- package/coverage/lcov-report/spec/count_inflector_fr_spec.js.html +0 -454
- package/coverage/lcov-report/spec/count_inflector_spec.js.html +0 -538
- package/coverage/lcov-report/spec/dice_coefficient_spec.js.html +0 -400
- package/coverage/lcov-report/spec/double_metaphone_spec.js.html +0 -2548
- package/coverage/lcov-report/spec/index.html +0 -883
- package/coverage/lcov-report/spec/jaro-winkler_spec.js.html +0 -481
- package/coverage/lcov-report/spec/lancaster_stemmer_spec.js.html +0 -541
- package/coverage/lcov-report/spec/levenshtein_spec.js.html +0 -520
- package/coverage/lcov-report/spec/logistic_regression_classifier_spec.js.html +0 -688
- package/coverage/lcov-report/spec/longest_path_tree_spec.js.html +0 -628
- package/coverage/lcov-report/spec/metaphone_spec.js.html +0 -1063
- package/coverage/lcov-report/spec/ngram_spec.js.html +0 -712
- package/coverage/lcov-report/spec/ngram_zh_spec.js.html +0 -688
- package/coverage/lcov-report/spec/normalizer_ja_spec.js.html +0 -802
- package/coverage/lcov-report/spec/normalizer_no_spec.js.html +0 -655
- package/coverage/lcov-report/spec/normalizer_spec.js.html +0 -742
- package/coverage/lcov-report/spec/noun_inflector_fr_spec.js.html +0 -1750
- package/coverage/lcov-report/spec/noun_inflector_ja_spec.js.html +0 -658
- package/coverage/lcov-report/spec/noun_inflector_spec.js.html +0 -1132
- package/coverage/lcov-report/spec/porter_stemmer_fr_spec.js.html +0 -625
- package/coverage/lcov-report/spec/porter_stemmer_it_spec.js.html +0 -454
- package/coverage/lcov-report/spec/porter_stemmer_no_spec.js.html +0 -751
- package/coverage/lcov-report/spec/porter_stemmer_ru_spec.js.html +0 -511
- package/coverage/lcov-report/spec/porter_stemmer_spec.js.html +0 -733
- package/coverage/lcov-report/spec/present_verb_inflector_spec.js.html +0 -697
- package/coverage/lcov-report/spec/remove_diacritics_spec.js.html +0 -415
- package/coverage/lcov-report/spec/sentence_analyzer_spec.js.html +0 -1153
- package/coverage/lcov-report/spec/shortest_path_tree_spec.js.html +0 -718
- package/coverage/lcov-report/spec/soundex_spec.js.html +0 -784
- package/coverage/lcov-report/spec/spellcheck_spec.js.html +0 -598
- package/coverage/lcov-report/spec/stemmer_ja_spec.js.html +0 -520
- package/coverage/lcov-report/spec/tfidf_spec.js.html +0 -1288
- package/coverage/lcov-report/spec/tokenizer_ja_spec.js.html +0 -496
- package/coverage/lcov-report/spec/transliterator_ja_spec.js.html +0 -631
- package/coverage/lcov-report/spec/treebank_word_tokenizer_spec.js.html +0 -430
- package/coverage/lcov-report/spec/trie_spec.js.html +0 -940
- package/coverage/lcov-report/util/index.html +0 -350
- package/coverage/lcov-report/util/utils.js.html +0 -679
- package/coverage/lcov.info +0 -11094
- package/lib/natural/parsers/Agenda.js +0 -68
- package/lib/natural/parsers/CYKParser.js +0 -87
- package/lib/natural/parsers/CYK_Item.js +0 -159
- package/lib/natural/parsers/Chart.js +0 -211
- package/lib/natural/parsers/ChartParser.js +0 -60
- package/lib/natural/parsers/DoubleDottedItem.js +0 -226
- package/lib/natural/parsers/EarleyItem.js +0 -155
- package/lib/natural/parsers/EarleyParser.js +0 -58
- package/lib/natural/parsers/FunctionWordTagger.js +0 -84
- package/lib/natural/parsers/GoalItem.js +0 -206
- package/lib/natural/parsers/GrammarParser.js +0 -1289
- package/lib/natural/parsers/HeadCornerParser.js +0 -101
- package/lib/natural/parsers/LeftCornerParser.js +0 -58
- package/lib/natural/parsers/PEG-grammar-for-unification-grammar.txt +0 -345
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Head-Corner 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('ERROR');
|
|
22
|
-
|
|
23
|
-
var DoubleDottedItem = require('./DoubleDottedItem');
|
|
24
|
-
var GoalItem = require('./GoalItem');
|
|
25
|
-
var CYK_Item = require('./CYK_Item');
|
|
26
|
-
var Chart = require('./Chart');
|
|
27
|
-
var Agenda = require('./Agenda');
|
|
28
|
-
|
|
29
|
-
HeadCornerChartParser.prototype.initialise = function(tagged_sentence) {
|
|
30
|
-
var that = this;
|
|
31
|
-
var new_item;
|
|
32
|
-
var nr_items_added = 0;
|
|
33
|
-
var i,j;
|
|
34
|
-
|
|
35
|
-
logger.debug("Enter HeadCornerChartParser.initialise");
|
|
36
|
-
this.tagged_sentence = tagged_sentence;
|
|
37
|
-
this.N = tagged_sentence.length;
|
|
38
|
-
// Initialise agenda
|
|
39
|
-
this.agenda = new Agenda();
|
|
40
|
-
// Initialise chart
|
|
41
|
-
this.chart = new Chart(this.N);
|
|
42
|
-
|
|
43
|
-
// Add goal items for the start symbol
|
|
44
|
-
for (i = 0; i <= this.N; i++) {
|
|
45
|
-
for (j = i; j <= this.N; j++) {
|
|
46
|
-
new_item = new GoalItem(i, j, this.grammar.get_start_symbol());
|
|
47
|
-
nr_items_added += this.agenda.add_item(new_item, this.chart);
|
|
48
|
-
logger.debug("HeadCornerChartParser.initialise: |- " + new_item.id);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Add items for the tagged sentence
|
|
53
|
-
for (i = 0; i < this.N; i++) {
|
|
54
|
-
// Add terminal item
|
|
55
|
-
var term_item = new CYK_Item({'lhs': this.tagged_sentence[i][0], 'rhs': ''}, i, i + 1);
|
|
56
|
-
// Add tag items
|
|
57
|
-
for (j = 1; j < tagged_sentence[i].length; j++) {
|
|
58
|
-
var tag_item = new CYK_Item({'lhs': this.tagged_sentence[i][j], 'rhs': [this.tagged_sentence[i][0]]}, i, i + 1);
|
|
59
|
-
tag_item.children.push(term_item);
|
|
60
|
-
nr_items_added += this.chart.add_item(tag_item);
|
|
61
|
-
logger.debug("HeadCornerChartParser.initialise: |- " + tag_item.id);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
logger.debug("Exit HeadCornerChartParser.initialise: number of items added: " + nr_items_added);
|
|
65
|
-
return(nr_items_added);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// Pseudo code of a chart parser with agenda (based on Sikkel's parsing schemata)
|
|
69
|
-
// create initial chart and agenda
|
|
70
|
-
// while agenda is not empty
|
|
71
|
-
// delete (arbitrarily chosen) item current from agenda
|
|
72
|
-
// if current is not on the chart then
|
|
73
|
-
// add current to chart
|
|
74
|
-
// add all items that can be deduced by combining current with
|
|
75
|
-
// the items already on the chart
|
|
76
|
-
// to the agenda if it is not already on chart or agenda
|
|
77
|
-
HeadCornerChartParser.prototype.parse = function (tagged_sentence) {
|
|
78
|
-
logger.debug("Enter HeadCornerChartParser.parse: sentence: " + tagged_sentence);
|
|
79
|
-
this.initialise(tagged_sentence);
|
|
80
|
-
var items_added = 0;
|
|
81
|
-
var current;
|
|
82
|
-
do {
|
|
83
|
-
current = this.agenda.get_item();
|
|
84
|
-
if (current) {
|
|
85
|
-
if (this.chart.add_item(current)) {
|
|
86
|
-
items_added += current.combine_with_chart(this.chart, this.agenda, this.grammar);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} while (current);
|
|
90
|
-
logger.debug("Exit HeadCornerChartParser.parse");
|
|
91
|
-
return this.chart;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// Constructor for the left-corner parser
|
|
95
|
-
function HeadCornerChartParser(grammar) {
|
|
96
|
-
this.grammar = grammar;
|
|
97
|
-
this.grammar.compute_hc_relation();
|
|
98
|
-
logger.debug("HeadCornerChartParser: " + JSON.stringify(grammar.hc));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
module.exports = HeadCornerChartParser;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Left Corner 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
|
-
// Algorithm based on the improved left-corner algorithm in
|
|
20
|
-
// Improved Left-Corner Chart Parsing for Large Context-Free Grammars, Robert C. Moore
|
|
21
|
-
// IWPT2000
|
|
22
|
-
|
|
23
|
-
var log4js = require('log4js');
|
|
24
|
-
var logger = log4js.getLogger();
|
|
25
|
-
logger.setLevel('DEBUG');
|
|
26
|
-
|
|
27
|
-
var EarleyItem = require('./EarleyItem');
|
|
28
|
-
var Chart = require('./Chart');
|
|
29
|
-
var ChartParser = require("./ChartParser");
|
|
30
|
-
|
|
31
|
-
// Constructor for the left-corner parser
|
|
32
|
-
function LeftCornerChartParser(grammar) {
|
|
33
|
-
this.grammar = grammar;
|
|
34
|
-
this.grammar.compute_lc_relation();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
LeftCornerChartParser.prototype = Object.create(ChartParser.prototype);
|
|
38
|
-
|
|
39
|
-
LeftCornerChartParser.prototype.parse = function(tagged_sentence) {
|
|
40
|
-
var that = this;
|
|
41
|
-
|
|
42
|
-
this.initialise(tagged_sentence);
|
|
43
|
-
var i;
|
|
44
|
-
for (i = 0; i <= this.N; i++) {
|
|
45
|
-
var items_added;
|
|
46
|
-
do {
|
|
47
|
-
items_added = 0;
|
|
48
|
-
var items = this.chart.get_items_to(i);
|
|
49
|
-
items.forEach(function(item) {
|
|
50
|
-
items_added += item.completer(that.chart, that.grammar);
|
|
51
|
-
items_added += item.lc_predictor(that.chart, that.grammar);
|
|
52
|
-
});
|
|
53
|
-
} while (items_added);
|
|
54
|
-
}
|
|
55
|
-
return this.chart;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
module.exports = LeftCornerChartParser;
|
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
PEG grammar unification grammars
|
|
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
|
-
// Created using http://pegjs.majda.cz/online
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
var is_CNF = true;
|
|
23
|
-
var nonterminals = {};
|
|
24
|
-
var symbols = {};
|
|
25
|
-
|
|
26
|
-
function Atom(val) {
|
|
27
|
-
this.atom = val;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function Path(ids) {
|
|
31
|
-
this.path = ids;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function Rule(lhs, rhs, head) {
|
|
35
|
-
this.lhs = lhs;
|
|
36
|
-
this.rhs = rhs;
|
|
37
|
-
this.head = head;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function Constraint(left_op, right_op) {
|
|
41
|
-
this.left = left_op;
|
|
42
|
-
this.right = right_op;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function Grammar() {
|
|
46
|
-
this.production_rules = [];
|
|
47
|
-
this.nonterminals = {};
|
|
48
|
-
this.symbols = {};
|
|
49
|
-
this.start_symbol = "";
|
|
50
|
-
this.is_CNF = true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//Checks if B is a nonterminal
|
|
54
|
-
Grammar.prototype.is_nonterminal = function(B) {
|
|
55
|
-
console.log("Checking if " + B + " is a nonterminal: " + this.nonterminals[B]);
|
|
56
|
-
return (this.nonterminals[B]);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
//Checks if B is a (pre)terminal
|
|
60
|
-
Grammar.prototype.is_terminal = function(B) {
|
|
61
|
-
console.log("Checking if " + B + " is a (pre)terminal: " + !this.nonterminals[B]);
|
|
62
|
-
return (!this.nonterminals[B]);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// Looks up all rules with lhs B
|
|
66
|
-
Grammar.prototype.rules_with_lhs = function(B) {
|
|
67
|
-
var rules = [];
|
|
68
|
-
|
|
69
|
-
this.production_rules.forEach(function(rule) {
|
|
70
|
-
if (rule.lhs === B) {
|
|
71
|
-
rules.push(rule);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return(rules);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// Returns the start production rule which is the first rule read from file
|
|
78
|
-
Grammar.prototype.start_rule = function() {
|
|
79
|
-
return(this.production_rules[0]);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Returns the start symbol
|
|
83
|
-
Grammar.prototype.get_start_symbol = function() {
|
|
84
|
-
return(this.start_symbol);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// Returns all rules that match right hand side nonterminals s and t
|
|
88
|
-
Grammar.prototype.get_rules_with_rhs = function(s, t) {
|
|
89
|
-
var res = [];
|
|
90
|
-
|
|
91
|
-
this.production_rules.forEach(function(rule) {
|
|
92
|
-
if ((rule.rhs.length === 2) && (rule.rhs[0] === s) && (rule.rhs[1] === t)) {
|
|
93
|
-
res.push(rule);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return res;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// Based on: http://folk.uio.no/plison/pdfs/lectures/compling2010/pdfs/compling2010-parsingcfg-solutions.pdf
|
|
100
|
-
Grammar.prototype.compute_lc_relation = function() {
|
|
101
|
-
that = this;
|
|
102
|
-
// Compute the first order lc relation
|
|
103
|
-
this.lc = {};
|
|
104
|
-
this.production_rules.forEach(function(rule) {
|
|
105
|
-
if (!that.lc[rule.lhs]) {
|
|
106
|
-
that.lc[rule.lhs] = {};
|
|
107
|
-
}
|
|
108
|
-
if (that.is_nonterminal(rule.rhs[0])) {
|
|
109
|
-
that.lc[rule.lhs][rule.rhs[0]] = true;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
// Reflexive closure
|
|
113
|
-
Object.keys(this.nonterminals).forEach(function(A){
|
|
114
|
-
if (!that.lc[A]) {
|
|
115
|
-
that.lc[A] = {};
|
|
116
|
-
}
|
|
117
|
-
that.lc[A][A] = true;
|
|
118
|
-
});
|
|
119
|
-
// Transitive closure
|
|
120
|
-
var changed;
|
|
121
|
-
do {
|
|
122
|
-
changed = false;
|
|
123
|
-
Object.keys(this.nonterminals).forEach(function(A) {
|
|
124
|
-
Object.keys(that.lc[A]).forEach(function(B) {
|
|
125
|
-
Object.keys(that.lc[B]).forEach(function(C) {
|
|
126
|
-
if (!that.lc[A][C]) {
|
|
127
|
-
// add all left corners of C to A
|
|
128
|
-
Object.keys(that.lc[C]).forEach(function(D){
|
|
129
|
-
that.lc[A][D] = true;
|
|
130
|
-
changed = true;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
} while (changed);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
Grammar.prototype.rules_with_leftmost_daughter = function (B) {
|
|
140
|
-
rules = [];
|
|
141
|
-
|
|
142
|
-
this.production_rules.forEach(function(rule) {
|
|
143
|
-
if (rule.rhs[0] === B) {
|
|
144
|
-
rules.push(rule);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
return(rules);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
Grammar.prototype.is_leftcorner_of = function(B, C) {
|
|
151
|
-
if (this.lc[C]) {
|
|
152
|
-
return(this.lc[C][B]);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
return(false);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// Check if nonterminal A is head-corner of nonterminal B
|
|
160
|
-
Grammar.prototype.is_headcorner_of = function(A, B) {
|
|
161
|
-
if (this.hc[B]) {
|
|
162
|
-
return(this.hc[B][A]);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
return(false);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Get rules with nonterminal H as head
|
|
170
|
-
Grammar.prototype.get_rules_with_head = function(H) {
|
|
171
|
-
var res = [];
|
|
172
|
-
|
|
173
|
-
this.production_rules.forEach(function(rule) {
|
|
174
|
-
if (rule.rhs[rule.head] === H) {
|
|
175
|
-
res.push(rule);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return(res);
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// Computation of the head-corner relation follows the pattern of the
|
|
182
|
-
// computation of the lef-corner relation
|
|
183
|
-
Grammar.prototype.compute_hc_relation = function() {
|
|
184
|
-
that = this;
|
|
185
|
-
// Compute the first order hc relation
|
|
186
|
-
this.hc = {};
|
|
187
|
-
this.production_rules.forEach(function(rule) {
|
|
188
|
-
if (!that.hc[rule.lhs]) {
|
|
189
|
-
that.hc[rule.lhs] = {};
|
|
190
|
-
}
|
|
191
|
-
that.hc[rule.lhs][rule.rhs[rule.head]] = true;
|
|
192
|
-
});
|
|
193
|
-
// Reflexive closure
|
|
194
|
-
Object.keys(this.symbols).forEach(function(A){
|
|
195
|
-
if (!that.hc[A]) {
|
|
196
|
-
that.hc[A] = {};
|
|
197
|
-
}
|
|
198
|
-
that.hc[A][A] = true;
|
|
199
|
-
});
|
|
200
|
-
// Transitive closure
|
|
201
|
-
var changed;
|
|
202
|
-
do {
|
|
203
|
-
changed = false;
|
|
204
|
-
Object.keys(this.symbols).forEach(function(A) {
|
|
205
|
-
Object.keys(that.hc[A]).forEach(function(B) {
|
|
206
|
-
Object.keys(that.hc[B]).forEach(function(C) {
|
|
207
|
-
if (!that.hc[A][C]) {
|
|
208
|
-
// add all head corners of C to A
|
|
209
|
-
Object.keys(that.hc[C]).forEach(function(D){
|
|
210
|
-
that.hc[A][D] = true;
|
|
211
|
-
changed = true;
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
} while (changed);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
grammar =
|
|
223
|
-
rules: (S production_rule S) +
|
|
224
|
-
{
|
|
225
|
-
grammar = new Grammar();
|
|
226
|
-
for (var i = 0; i < rules.length; i++) {
|
|
227
|
-
grammar.production_rules.push(rules[i][1]);
|
|
228
|
-
}
|
|
229
|
-
grammar.start_symbol = grammar.production_rules[0].lhs;
|
|
230
|
-
grammar.nonterminals = nonterminals;
|
|
231
|
-
grammar.is_CNF = is_CNF;
|
|
232
|
-
grammar.symbols = symbols;
|
|
233
|
-
return(grammar);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
production_rule =
|
|
237
|
-
rule: rule cseq: constraint*
|
|
238
|
-
{
|
|
239
|
-
if (cseq) {
|
|
240
|
-
rule.constraints = cseq;
|
|
241
|
-
}
|
|
242
|
-
return(rule);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// A production rule must be specified on one line
|
|
246
|
-
rule =
|
|
247
|
-
lhs: nonterminal Arrow rhs_1: identifier_no_eol* head: (HeadIndicator identifier_no_eol HeadIndicator)? rhs_2: identifier_no_eol* (EOL / EOI)
|
|
248
|
-
{
|
|
249
|
-
var rhs = [];
|
|
250
|
-
var head_pos = 0;
|
|
251
|
-
|
|
252
|
-
rhs = rhs_1;
|
|
253
|
-
if (head) {
|
|
254
|
-
head_pos = rhs_1.length;
|
|
255
|
-
rhs.push(head[1]);
|
|
256
|
-
}
|
|
257
|
-
rhs = rhs.concat(rhs_2);
|
|
258
|
-
rhs.forEach(function(symbol) {
|
|
259
|
-
symbols[symbol] = true;
|
|
260
|
-
});
|
|
261
|
-
var rule = new Rule(lhs, rhs, head_pos);
|
|
262
|
-
nonterminals[lhs] = true;
|
|
263
|
-
symbols[lhs] = true;
|
|
264
|
-
if ((rule.rhs.length > 2) || (rule.rhs.length === 0)) {
|
|
265
|
-
is_CNF = false;
|
|
266
|
-
}
|
|
267
|
-
return(rule);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
nonterminal =
|
|
271
|
-
nt:identifier S
|
|
272
|
-
{
|
|
273
|
-
return(nt);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
nonterminal_seq =
|
|
277
|
-
identifier_seq
|
|
278
|
-
|
|
279
|
-
constraint =
|
|
280
|
-
path: feature_path Equal atom: atom
|
|
281
|
-
{
|
|
282
|
-
var constraint = new Constraint(path, atom);
|
|
283
|
-
return(constraint);
|
|
284
|
-
}
|
|
285
|
-
/ path1: feature_path Equal path2: feature_path
|
|
286
|
-
{
|
|
287
|
-
var constraint = new Constraint(path1, path2);
|
|
288
|
-
return(constraint);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
feature_path =
|
|
292
|
-
PathOpen idseq:identifier_seq PathClose
|
|
293
|
-
{
|
|
294
|
-
return(idseq);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
atom =
|
|
298
|
-
identifier
|
|
299
|
-
|
|
300
|
-
identifier_seq =
|
|
301
|
-
identifier*
|
|
302
|
-
|
|
303
|
-
identifier =
|
|
304
|
-
characters: [a-zA-Z_0-9]+ S
|
|
305
|
-
{
|
|
306
|
-
var s = "";
|
|
307
|
-
for (var i = 0; i < characters.length; i++) {
|
|
308
|
-
s += characters[i];
|
|
309
|
-
}
|
|
310
|
-
return(s);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
identifier_no_eol =
|
|
314
|
-
characters: [a-zA-Z_0-9$]+ S_no_eol
|
|
315
|
-
{
|
|
316
|
-
var s = "";
|
|
317
|
-
for (var i = 0; i < characters.length; i++) {
|
|
318
|
-
s += characters[i];
|
|
319
|
-
}
|
|
320
|
-
return(s);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Terminals
|
|
324
|
-
Arrow =
|
|
325
|
-
"->" S_no_eol
|
|
326
|
-
PathOpen =
|
|
327
|
-
"<" S
|
|
328
|
-
PathClose =
|
|
329
|
-
">" S
|
|
330
|
-
Equal =
|
|
331
|
-
"=" S
|
|
332
|
-
HeadIndicator =
|
|
333
|
-
"*" S_no_eol
|
|
334
|
-
|
|
335
|
-
// Blanks
|
|
336
|
-
EOL =
|
|
337
|
-
'\r\n' / '\n' / '\r'
|
|
338
|
-
Comment =
|
|
339
|
-
"\/\/" (!EOL .)* (EOL/EOI)
|
|
340
|
-
S =
|
|
341
|
-
(' ' / '\t' / EOL / Comment)*
|
|
342
|
-
S_no_eol =
|
|
343
|
-
(' ' / '\t' / Comment)*
|
|
344
|
-
EOI=
|
|
345
|
-
!.
|