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,226 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
DoubleDottedItem 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
|
-
var _ = require('underscore');
|
|
20
|
-
var typeOf = require('typeof');
|
|
21
|
-
var log4js = require('log4js');
|
|
22
|
-
var logger = log4js.getLogger();
|
|
23
|
-
logger.setLevel('ERROR');
|
|
24
|
-
|
|
25
|
-
// Creates an item;
|
|
26
|
-
// left_dot is an index in the RHS of the rule as well as right_dot
|
|
27
|
-
// from is the starting point in the sentence
|
|
28
|
-
// Data structure is prepared for InfoVis
|
|
29
|
-
function DoubleDottedItem(rule, left_dot, right_dot, from, to) {
|
|
30
|
-
|
|
31
|
-
// An identifier is constructed from rule, dots, from and to
|
|
32
|
-
this.id = "DoubleDottedItem(" + rule.lhs + "->" + rule.rhs + ", " + left_dot + ", " + right_dot + ", " + from + ", " + to +")";
|
|
33
|
-
logger.debug("Enter DoubleDottedItem: " + this.id);
|
|
34
|
-
this.name = rule.lhs;
|
|
35
|
-
this.children = [];
|
|
36
|
-
|
|
37
|
-
this.data = {};
|
|
38
|
-
this.data.rule = rule;
|
|
39
|
-
this.data.left_dot = left_dot;
|
|
40
|
-
this.data.right_dot = right_dot;
|
|
41
|
-
this.data.from = from;
|
|
42
|
-
this.data.to = to;
|
|
43
|
-
logger.debug("Exit DoubleDottedItem: created item: " + this.id);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = DoubleDottedItem;
|
|
47
|
-
|
|
48
|
-
var GoalItem = require('./GoalItem');
|
|
49
|
-
var CYK_Item = require('./CYK_Item');
|
|
50
|
-
|
|
51
|
-
DoubleDottedItem.prototype.copy = function () {
|
|
52
|
-
logger.debug("Enter DoubleDottedItem.copy(): " + this.id);
|
|
53
|
-
var new_item = new DoubleDottedItem(this.data.rule, this.data.left_dot, this.data.right_dot, this.data.from, this.data.to);
|
|
54
|
-
new_item.children = this.children.slice();
|
|
55
|
-
logger.debug("Exit DoubleDottedItem.copy: " + new_item.id);
|
|
56
|
-
return(new_item);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
DoubleDottedItem.prototype.recognise_left = function(cyk_item) {
|
|
60
|
-
logger.debug("Enter " + this.id + ".recognise_left(" + cyk_item.id + ")");
|
|
61
|
-
this.data.left_dot--;
|
|
62
|
-
this.data.from = cyk_item.data.from;
|
|
63
|
-
this.children.unshift(cyk_item);
|
|
64
|
-
this.id = "DoubleDottedItem(" + this.data.rule.lhs + "->" + this.data.rule.rhs + ", " +
|
|
65
|
-
this.data.left_dot + ", " + this.data.right_dot + ", " + this.data.from + ", " + this.data.to +")";
|
|
66
|
-
logger.debug("Exit DoubleDottedItem.recognise_left: " + this.id);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
DoubleDottedItem.prototype.recognise_right = function(cyk_item) {
|
|
70
|
-
logger.debug("Enter " + this.id + ".recognise_right(" + cyk_item.id + ")");
|
|
71
|
-
this.data.right_dot++;
|
|
72
|
-
this.data.to = cyk_item.data.to;
|
|
73
|
-
this.children.push(cyk_item);
|
|
74
|
-
this.id = "DoubleDottedItem(" + this.data.rule.lhs + "->" + this.data.rule.rhs + ", " +
|
|
75
|
-
this.data.left_dot + ", " + this.data.right_dot + ", " + this.data.from + ", " + this.data.to +")";
|
|
76
|
-
logger.debug("Exit DoubleDottedItem.recognise_right: " + this.id);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// Checks if an item is incomplete
|
|
80
|
-
DoubleDottedItem.prototype.is_incomplete = function () {
|
|
81
|
-
return(!this.is_complete());
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// Checks if an item is complete
|
|
85
|
-
DoubleDottedItem.prototype.is_complete = function () {
|
|
86
|
-
return((this.data.left_dot === 0) && (this.data.right_dot === this.data.rule.rhs.length));
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
DoubleDottedItem.prototype.combine_with_chart = function(chart, agenda, grammar) {
|
|
90
|
-
var nr_items_added = 0;
|
|
91
|
-
|
|
92
|
-
logger.debug("Enter DoubleDottedItem.combine_with_chart:" + this.id);
|
|
93
|
-
nr_items_added += this.pre_complete(chart, agenda, grammar);
|
|
94
|
-
nr_items_added += this.left_predict(chart, agenda, grammar);
|
|
95
|
-
nr_items_added += this.right_predict(chart, agenda, grammar);
|
|
96
|
-
nr_items_added += this.left_complete(chart, agenda, grammar);
|
|
97
|
-
nr_items_added += this.right_complete(chart, agenda, grammar);
|
|
98
|
-
logger.debug("Exit DoubleDottedItem.combine_with_chart: number of items added: " + nr_items_added);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
DoubleDottedItem.prototype.pre_complete = function (chart, agenda, grammar) {
|
|
102
|
-
var nr_items_added = 0;
|
|
103
|
-
|
|
104
|
-
logger.debug("Enter DoubleDottedItem.pre_complete:" + this.id);
|
|
105
|
-
if (this.is_complete()) {
|
|
106
|
-
var new_item = new CYK_Item(this.data.rule, this.data.from, this.data.to);
|
|
107
|
-
new_item.children = this.children.slice();
|
|
108
|
-
nr_items_added += agenda.add_item(new_item, chart);
|
|
109
|
-
logger.debug("DoubleDottedItem.pre_complete: " + this.id + " |- " + new_item.id);
|
|
110
|
-
}
|
|
111
|
-
logger.debug("Exit DoubleDottedItem.pre_complete: number of items added: " + nr_items_added);
|
|
112
|
-
return(nr_items_added);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
DoubleDottedItem.prototype.left_predict = function (chart, agenda, grammar) {
|
|
116
|
-
var that = this;
|
|
117
|
-
var nr_items_added = 0;
|
|
118
|
-
|
|
119
|
-
logger.debug("Enter DoubleDottedItem.left_predict:" + this.id);
|
|
120
|
-
if (this.data.left_dot > 0) {
|
|
121
|
-
// Get goal items that end at the "to" of the current item
|
|
122
|
-
var items = chart.get_items_to(this.data.to);
|
|
123
|
-
items.forEach(function(item) {
|
|
124
|
-
if (typeOf(item) === "goalitem") { // try to combine with the current item
|
|
125
|
-
if (grammar.is_headcorner_of(that.data.rule.lhs, item.nonterminal)) {
|
|
126
|
-
for (var i = item.data.from; i <= that.data.from; i++) {
|
|
127
|
-
for (var j = i; j <= that.data.from; j++) {
|
|
128
|
-
var new_goal = new GoalItem(i, j, that.data.rule.rhs[that.data.left_dot-1]);
|
|
129
|
-
nr_items_added += agenda.add_item(new_goal, chart);
|
|
130
|
-
logger.debug("DoubleDottedItem.left_predict: " + item.id + ", " + that.id + " |- " + new_goal.id);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
logger.debug("Exit DoubleDottedItem.left_predict: number of items added: " + nr_items_added);
|
|
138
|
-
return(nr_items_added);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
DoubleDottedItem.prototype.right_predict = function (chart, agenda, grammar) {
|
|
142
|
-
var that = this;
|
|
143
|
-
var nr_items_added = 0;
|
|
144
|
-
|
|
145
|
-
logger.debug("Enter DoubleDottedItem.right_predict:" + this.id);
|
|
146
|
-
if (this.data.right_dot < this.data.rule.rhs.length) {
|
|
147
|
-
// Get goal items that start at the "from" of the current item
|
|
148
|
-
var items = chart.get_items_from(this.data.from);
|
|
149
|
-
items.forEach(function(item) {
|
|
150
|
-
if (typeOf(item) === "goalitem") { // try to combine with the current item
|
|
151
|
-
if (grammar.is_headcorner_of(that.data.rule.lhs, item.data.nonterminal)) {
|
|
152
|
-
for (var j = that.data.to; j <= item.data.to; j++) {
|
|
153
|
-
for (var k = j; k <= item.data.to; k++) {
|
|
154
|
-
var new_goal = new GoalItem(j, k, that.data.rule.rhs[that.data.right_dot]);
|
|
155
|
-
nr_items_added += agenda.add_item(new_goal, chart);
|
|
156
|
-
logger.debug("DoubleDottedItem.right_predict: " + item.id + ", " + that.id + " |- " + new_goal.id);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
logger.debug("Exit DoubleDottedItem.right_predict: number of items added: " + nr_items_added);
|
|
164
|
-
return(nr_items_added);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
DoubleDottedItem.prototype.left_complete = function (chart, agenda, grammar) {
|
|
168
|
-
var that = this;
|
|
169
|
-
var nr_items_added = 0;
|
|
170
|
-
|
|
171
|
-
logger.debug("Enter DoubleDottedItem.left_complete:" + this.id);
|
|
172
|
-
if (this.data.left_dot > 0) {
|
|
173
|
-
// Get goal items that end at the "to" of the current item
|
|
174
|
-
var items1 = chart.get_items_to(this.data.to);
|
|
175
|
-
items1.forEach(function(item1) {
|
|
176
|
-
if (typeOf(item1) === "goalitem") {
|
|
177
|
-
// find completed items to combine with
|
|
178
|
-
var items2 = chart.get_items_from_to(item1.data.from, that.data.from);
|
|
179
|
-
items2.forEach(function(item2) {
|
|
180
|
-
if ((typeOf(item2) === "cyk_item") &&
|
|
181
|
-
(that.data.rule.rhs[that.data.left_dot-1] === item2.data.rule.lhs) &&
|
|
182
|
-
grammar.is_headcorner_of(that.data.rule.lhs, item1.data.nonterminal)) {
|
|
183
|
-
var new_item = that.copy();
|
|
184
|
-
new_item.recognise_left(item2);
|
|
185
|
-
nr_items_added += agenda.add_item(new_item, chart);
|
|
186
|
-
logger.debug("DoubleDottedItem.left_complete: " + item1.id +", " + item2.id + ", " + that.id + " |- " + new_item.id);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
logger.debug("Exit DoubleDottedItem.left_complete: number of items added: " + nr_items_added);
|
|
193
|
-
return(nr_items_added);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
DoubleDottedItem.prototype.right_complete = function (chart, agenda, grammar) {
|
|
197
|
-
var that = this;
|
|
198
|
-
var nr_items_added = 0;
|
|
199
|
-
|
|
200
|
-
logger.debug("Enter DoubleDottedItem.right_complete:" + this.id);
|
|
201
|
-
if (this.data.right_dot < this.data.rule.rhs.length) {
|
|
202
|
-
// Get goal items that start at the "from" of the current item
|
|
203
|
-
var items1 = chart.get_items_from(this.data.from);
|
|
204
|
-
items1.forEach(function(item1) {
|
|
205
|
-
if (typeOf(item1) === "goalitem") {
|
|
206
|
-
// find completed items to combine with
|
|
207
|
-
var items2 = chart.get_items_from_to(that.data.to, item1.data.to);
|
|
208
|
-
items2.forEach(function(item2) {
|
|
209
|
-
if (typeOf(item2) === "cyk_item") {
|
|
210
|
-
if ((that.data.rule.rhs[that.data.right_dot] === item2.data.rule.lhs) &&
|
|
211
|
-
grammar.is_headcorner_of(that.data.rule.lhs, item1.data.nonterminal)) {
|
|
212
|
-
new_item = that.copy();
|
|
213
|
-
new_item.recognise_right(item2);
|
|
214
|
-
nr_items_added += agenda.add_item(new_item, chart);
|
|
215
|
-
logger.debug("DoubleDottedItem.right_complete: " + item1.id +", " + that.id + ", " + item2.id + " |- " + new_item.id);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
logger.debug("Exit DoubleDottedItem.right_complete: number of items added: " + nr_items_added);
|
|
223
|
-
return(nr_items_added);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
module.exports = DoubleDottedItem;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Single dotted items for Earley and Left-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
|
-
var _ = require('underscore');
|
|
20
|
-
var log4js = require('log4js');
|
|
21
|
-
var logger = log4js.getLogger();
|
|
22
|
-
logger.setLevel('DEBUG');
|
|
23
|
-
|
|
24
|
-
// Creates an item; dot is an index in the RHS of the rule,
|
|
25
|
-
// from is the starting point in the sentence
|
|
26
|
-
// Data structure is prepared for InfoVis
|
|
27
|
-
function EarleyItem(rule, dot, from, to) {
|
|
28
|
-
// A unique identifier is constructed from rule, dot and from
|
|
29
|
-
this.id = "(" + rule.lhs + "->" + rule.rhs + ", " + dot + ", " + from + ", " + to +")";
|
|
30
|
-
logger.debug("EarleyItem: " + this.id);
|
|
31
|
-
this.name = rule.lhs;
|
|
32
|
-
this.children = [];
|
|
33
|
-
|
|
34
|
-
this.data = {};
|
|
35
|
-
this.data.rule = rule;
|
|
36
|
-
this.data.dot = dot;
|
|
37
|
-
this.data.from = from;
|
|
38
|
-
this.data.to = to;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
EarleyItem.prototype.set_children = function(children) {
|
|
42
|
-
logger.debug("Enter EarleyItem.set_children: " + children);
|
|
43
|
-
this.children = children;
|
|
44
|
-
logger.debug("Exit EarleyItem.set_children");
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
EarleyItem.prototype.append_child = function(child) {
|
|
48
|
-
logger.debug("Enter EarleyItem.append_child: " + child);
|
|
49
|
-
this.children.push(child);
|
|
50
|
-
logger.debug("Exit EarleyItem.append_child");
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// Checks if an item is incomplete
|
|
54
|
-
EarleyItem.prototype.is_incomplete = function () {
|
|
55
|
-
logger.debug("EarleyItem.is_incomplete: " + this.id + (this.data.dot < this.data.rule.rhs.length));
|
|
56
|
-
return(this.data.dot < this.data.rule.rhs.length);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Checks if an item is complete
|
|
60
|
-
EarleyItem.prototype.is_complete = function () {
|
|
61
|
-
logger.debug("EarleyItem.is complete: " + this.id + (this.data.dot === this.data.rule.rhs.length));
|
|
62
|
-
return(this.data.dot === this.data.rule.rhs.length);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// Introduces new items for the next nonterminal to be recognised
|
|
66
|
-
EarleyItem.prototype.predictor = function(chart, grammar) {
|
|
67
|
-
var that = this;
|
|
68
|
-
var nr_items_added = 0;
|
|
69
|
-
|
|
70
|
-
logger.debug("EarleyItem.predictor: " + that.id);
|
|
71
|
-
if (this.is_incomplete() && grammar.is_nonterminal(this.data.rule.rhs[this.data.dot])) {
|
|
72
|
-
// Get all rules with lhs B
|
|
73
|
-
var rules_with_lhs_B = grammar.rules_with_lhs(this.data.rule.rhs[this.data.dot]);
|
|
74
|
-
// for each rule with LHS B create an item
|
|
75
|
-
rules_with_lhs_B.forEach(function(rule) {
|
|
76
|
-
var newitem = new EarleyItem(rule, 0, that.data.to, that.data.to);
|
|
77
|
-
nr_items_added += chart.add_item(newitem);
|
|
78
|
-
logger.debug("EarleyItem.predictor: " + JSON.stringify(rule) + ", " + that.id + " |- " + newitem.id);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
logger.debug("EarleyItem.predictor: added " + nr_items_added + " items");
|
|
82
|
-
// Return number of items added
|
|
83
|
-
return(nr_items_added);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// LC method is based on the improved left-corner algorithm in
|
|
87
|
-
// Improved Left-Corner Chart Parsing for Large Context-Free Grammars, Robert C. Moore
|
|
88
|
-
// IWPT2000
|
|
89
|
-
// Predictor based on rule 4a on page 5
|
|
90
|
-
EarleyItem.prototype.lc_predictor = function(chart, grammar) {
|
|
91
|
-
that = this;
|
|
92
|
-
var nr_items_added = 0;
|
|
93
|
-
|
|
94
|
-
logger.debug("EarleyItem.lc_predictor: " + this.id);
|
|
95
|
-
if (this.is_complete()) {
|
|
96
|
-
// Get the productions rules that have the LHS of item as left-most daughter
|
|
97
|
-
grammar.rules_with_leftmost_daughter(this.data.rule.lhs).forEach(function(rule) {
|
|
98
|
-
// Get the items that end at the given item
|
|
99
|
-
chart.get_items_to(that.data.from).forEach(function(item2) {
|
|
100
|
-
if (item2.is_incomplete() && grammar.is_leftcorner_of(rule.lhs, item2.data.rule.rhs[item2.data.dot])) {
|
|
101
|
-
var newitem = new EarleyItem(rule, 1, that.data.from, that.data.to);
|
|
102
|
-
newitem.append_child(that);
|
|
103
|
-
nr_items_added += chart.add_item(newitem);
|
|
104
|
-
logger.debug("EarleyItem.lc_predictor: " + JSON.stringify(rule) + ", " + that.id + ", " + item2.id + " |- " + newitem.id);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
logger.debug("EarleyItem.lc_predictor: added " + nr_items_added + " items");
|
|
110
|
-
return(nr_items_added);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// item is complete
|
|
114
|
-
// Shifts the dot to the right for items in chart[k]
|
|
115
|
-
EarleyItem.prototype.completer = function(chart, grammar) {
|
|
116
|
-
var that = this;
|
|
117
|
-
var nr_items_added = 0;
|
|
118
|
-
|
|
119
|
-
logger.debug("EarleyItem.completer: " + this.id);
|
|
120
|
-
if (this.is_complete()) {
|
|
121
|
-
var items = chart.get_items_to(this.data.from);
|
|
122
|
-
items.forEach(function(item2) {
|
|
123
|
-
if (item2.is_incomplete() && (that.data.rule.lhs === item2.data.rule.rhs[item2.data.dot])) {
|
|
124
|
-
var new_item = new EarleyItem(item2.data.rule, item2.data.dot + 1, item2.data.from, that.data.to);
|
|
125
|
-
// Make a copy of the children of item2, otherwise two items refer to the same set of children
|
|
126
|
-
new_item.children = item2.children.slice();
|
|
127
|
-
new_item.append_child(that);
|
|
128
|
-
nr_items_added += chart.add_item(new_item);
|
|
129
|
-
logger.debug("EarleyItem.completer: " + that.id + ", " + item2.id + " |- " + new_item.id);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
logger.debug("EarleyItem.completer: added " + nr_items_added + " items");
|
|
134
|
-
return(nr_items_added);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
EarleyItem.prototype.create_parse_tree = function() {
|
|
138
|
-
logger.debug("Enter EarleyItem.create_parse_tree: " + this.id);
|
|
139
|
-
var subtree = this.data.rule.lhs;
|
|
140
|
-
if (this.children.length === 0) {
|
|
141
|
-
subtree += "(" + this.data.rule.rhs + ")";
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
subtree += "(";
|
|
145
|
-
var i;
|
|
146
|
-
for (i = 0; i < this.children.length; i++) {
|
|
147
|
-
subtree += this.children[i].create_parse_tree() + (i < this.children.length - 1 ? "," : "");
|
|
148
|
-
}
|
|
149
|
-
subtree += ")";
|
|
150
|
-
}
|
|
151
|
-
logger.debug("Exit EarleyItem.create_parse_tree: " + subtree);
|
|
152
|
-
return(subtree);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
module.exports = EarleyItem;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Earley 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 EarleyItem = require('./EarleyItem');
|
|
24
|
-
var Chart = require('./Chart');
|
|
25
|
-
var ChartParser = require("./ChartParser");
|
|
26
|
-
|
|
27
|
-
function EarleyChartParser(grammar) {
|
|
28
|
-
logger.debug("EarleyChartParser");
|
|
29
|
-
this.grammar = grammar;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
EarleyChartParser.prototype = Object.create(ChartParser.prototype);
|
|
33
|
-
|
|
34
|
-
// The main algorithm of the chart parser. Sentence is an array of words
|
|
35
|
-
// Analyses the sentence from left to right
|
|
36
|
-
// If you need more methods to be called then override this method
|
|
37
|
-
EarleyChartParser.prototype.parse = function(tagged_sentence) {
|
|
38
|
-
that = this;
|
|
39
|
-
|
|
40
|
-
logger.debug("Enter EarleyChartParser.parse" + tagged_sentence);
|
|
41
|
-
this.initialise(tagged_sentence);
|
|
42
|
-
var i;
|
|
43
|
-
for (i = 0; i <= tagged_sentence.length; i++) {
|
|
44
|
-
var items_added;
|
|
45
|
-
do {
|
|
46
|
-
items_added = 0;
|
|
47
|
-
var items = this.chart.get_items_to(i);
|
|
48
|
-
items.forEach(function(item) {
|
|
49
|
-
items_added += item.completer(that.chart, that.grammar);
|
|
50
|
-
items_added += item.predictor(that.chart, that.grammar);
|
|
51
|
-
});
|
|
52
|
-
} while (items_added);
|
|
53
|
-
}
|
|
54
|
-
logger.debug("Enter EarleyChartParser.parse" + this.chart);
|
|
55
|
-
return this.chart;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
module.exports = EarleyChartParser;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
A part-of-speech tagger for English function words
|
|
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 fs = require('fs');
|
|
20
|
-
|
|
21
|
-
var log4js = require('log4js');
|
|
22
|
-
var logger = log4js.getLogger();
|
|
23
|
-
logger.setLevel('ERROR');
|
|
24
|
-
|
|
25
|
-
// Files that contain function words; files are located in ../data
|
|
26
|
-
files_with_function_words = [
|
|
27
|
-
"function_words_adverb.txt",
|
|
28
|
-
"function_words_indefinite_pronoun.txt",
|
|
29
|
-
"function_words_possessive_pronoun.txt",
|
|
30
|
-
"function_words_relative_pronoun.txt",
|
|
31
|
-
"function_words_conjunction.txt",
|
|
32
|
-
"function_words_interrogative_pronoun.txt",
|
|
33
|
-
"function_words_preposition.txt",
|
|
34
|
-
"function_words_demonstrative_pronoun.txt",
|
|
35
|
-
"function_words_particle.txt",
|
|
36
|
-
"function_words_reciprocal_pronoun.txt",
|
|
37
|
-
"function_words_determiner.txt",
|
|
38
|
-
"function_words_personal_pronoun.txt",
|
|
39
|
-
"function_words_reflexive_pronoun.txt"];
|
|
40
|
-
|
|
41
|
-
path_to_lexicon = "../data/";
|
|
42
|
-
|
|
43
|
-
// Returns an array of category for word
|
|
44
|
-
FunctionWordTagger.prototype.tag_word = function(word) {
|
|
45
|
-
return(this.lexicon[word]);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// Parses the list of words; first lines is the POS category
|
|
49
|
-
FunctionWordTagger.prototype.read_words = function(text) {
|
|
50
|
-
var words = text.split('\n');
|
|
51
|
-
var category = words.shift();
|
|
52
|
-
var that = this;
|
|
53
|
-
|
|
54
|
-
logger.debug("Enter FunctionWordTagger.read_words");
|
|
55
|
-
words.forEach(function(word) {
|
|
56
|
-
if (!that.lexicon[word]) {
|
|
57
|
-
that.lexicon[word] = [category];
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
that.lexicon[word].push(category);
|
|
61
|
-
}
|
|
62
|
-
logger.debug("FunctionWordTagger.read_words: lexicon entry " + word + " -> " + that.lexicon[word]);
|
|
63
|
-
});
|
|
64
|
-
logger.debug("Exit FunctionWordTagger.read_words");
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// Constructor: reads files with function words and calls the callback with itself
|
|
68
|
-
function FunctionWordTagger(callback) {
|
|
69
|
-
var that = this;
|
|
70
|
-
var nr_files = files_with_function_words.length;
|
|
71
|
-
|
|
72
|
-
this.lexicon = {};
|
|
73
|
-
files_with_function_words.forEach(function(filename){
|
|
74
|
-
fs.readFile(path_to_lexicon + filename, 'utf8', function (error, text) {
|
|
75
|
-
that.read_words(text);
|
|
76
|
-
nr_files--;
|
|
77
|
-
if (nr_files === 0) {
|
|
78
|
-
callback(that);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = FunctionWordTagger;
|