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