natural 0.5.6 → 0.6.3
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/.dockerignore +2 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/natural.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +511 -0
- package/.travis.yml +8 -1
- package/README.md +331 -40
- package/bayes_classifier.json +1 -1
- package/classifier.json +418 -0
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +8 -9
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tester.js +5 -5
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Trainer.js +10 -6
- package/lib/natural/brill_pos_tagger/lib/Corpus.js +21 -16
- package/lib/natural/brill_pos_tagger/lib/Lexicon.js +22 -13
- package/lib/natural/brill_pos_tagger/lib/Predicate.js +2 -2
- package/lib/natural/brill_pos_tagger/lib/RuleTemplate.js +2 -2
- package/lib/natural/brill_pos_tagger/lib/RuleTemplates.js +132 -146
- package/lib/natural/brill_pos_tagger/lib/Sentence.js +41 -0
- package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +10 -11
- package/lib/natural/classifiers/classifier.js +5 -3
- package/lib/natural/classifiers/maxent/Classifier.js +125 -0
- package/lib/natural/classifiers/maxent/Context.js +33 -0
- package/lib/natural/classifiers/maxent/Distribution.js +145 -0
- package/lib/natural/classifiers/maxent/Element.js +34 -0
- package/lib/natural/classifiers/maxent/Feature.js +88 -0
- package/lib/natural/classifiers/maxent/FeatureSet.js +67 -0
- package/lib/natural/classifiers/maxent/GISScaler.js +148 -0
- package/lib/natural/classifiers/maxent/POS/ME_Corpus.js +56 -0
- package/lib/natural/classifiers/maxent/POS/ME_Sentence.js +73 -0
- package/lib/natural/classifiers/maxent/POS/POS_Element.js +172 -0
- package/lib/natural/classifiers/maxent/Sample.js +141 -0
- package/lib/natural/classifiers/maxent/SimpleExample/SE_Element.js +49 -0
- package/lib/natural/distance/hamming_distance.js +52 -0
- package/lib/natural/distance/jaro-winkler_distance.js +16 -6
- package/lib/natural/distance/levenshtein_distance.js +2 -2
- package/lib/natural/index.js +21 -2
- package/lib/natural/inflectors/noun_inflector.js +5 -3
- package/lib/natural/ngrams/ngrams.js +83 -25
- package/lib/natural/sentiment/Basque/senticon_eu.json +21557 -0
- package/lib/natural/sentiment/Catalan/senticon_ca.json +36352 -0
- package/lib/natural/sentiment/Dutch/negations_du.json +3 -0
- package/lib/natural/sentiment/Dutch/pattern-sentiment-nl.json +39650 -0
- package/lib/natural/sentiment/English/negations_en.json +3 -0
- package/lib/natural/sentiment/English/pattern-sentiment-en.json +16024 -0
- package/lib/natural/sentiment/English/senticon_en.json +124197 -0
- package/lib/natural/sentiment/French/pattern-sentiment-fr.json +40906 -0
- package/lib/natural/sentiment/Galician/senticon_gl.json +24427 -0
- package/lib/natural/sentiment/Italian/pattern-sentiment-it.json +24522 -0
- package/lib/natural/sentiment/SentimentAnalyzer.js +116 -0
- package/lib/natural/sentiment/Spanish/afinnShortSortedSpanish.json +1655 -0
- package/lib/natural/sentiment/Spanish/negations_es.json +3 -0
- package/lib/natural/sentiment/Spanish/senticon_es.json +56722 -0
- package/lib/natural/sentiment/tools/README.md +31 -0
- package/lib/natural/sentiment/tools/XmlParser4PatternData.js +31 -0
- package/lib/natural/sentiment/tools/sentimentXmlParser.js +30 -0
- package/lib/natural/stemmers/indonesian/data/kata-dasar.json +29935 -0
- package/lib/natural/stemmers/indonesian/prefix_rules.js +10 -9
- package/lib/natural/stemmers/indonesian/stemmer_id.js +16 -15
- package/lib/natural/stemmers/indonesian/suffix_rules.js +2 -2
- package/lib/natural/stemmers/porter_stemmer_es.js +265 -199
- package/lib/natural/stemmers/porter_stemmer_fr.js +1 -1
- package/lib/natural/stemmers/porter_stemmer_nl.js +362 -0
- package/lib/natural/stemmers/stemmer_es.js +18 -12
- package/lib/natural/stemmers/stemmer_nl.js +64 -0
- package/lib/natural/tfidf/tfidf.js +27 -4
- package/lib/natural/tokenizers/aggressive_tokenizer_sv.js +1 -1
- package/lib/natural/tokenizers/aggressive_tokenizer_vi.js +37 -0
- package/lib/natural/tokenizers/orthography_matchers.js +33 -0
- package/lib/natural/tokenizers/regexp_tokenizer.js +24 -4
- package/lib/natural/tokenizers/sentence_tokenizer.js +1 -1
- package/lib/natural/wordnet/wordnet_file.js +7 -1
- package/lr_classifier.json +1 -1
- package/package.json +35 -23
- package/.npmignore +0 -4
- package/.vscode/temp.sql +0 -0
- package/Makefile +0 -38
- package/data/kata-dasar.txt +0 -29933
- package/package-lock.json +0 -79
- package/tests/stemmer_id_test.js +0 -361
|
@@ -20,7 +20,7 @@ var fs = require('fs');
|
|
|
20
20
|
|
|
21
21
|
// Parses a lexicon in JSON or text format
|
|
22
22
|
function Lexicon(filename, defaultCategory, defaultCategoryCapitalised) {
|
|
23
|
-
this.lexicon = {};
|
|
23
|
+
this.lexicon = {}; //Object.create(null);
|
|
24
24
|
|
|
25
25
|
if (filename) {
|
|
26
26
|
this.defaultCategory = defaultCategory;
|
|
@@ -35,7 +35,7 @@ function Lexicon(filename, defaultCategory, defaultCategoryCapitalised) {
|
|
|
35
35
|
// Lexicon is plain text
|
|
36
36
|
this.parseLexicon(data);
|
|
37
37
|
}
|
|
38
|
-
//
|
|
38
|
+
//console.log('Brill_POS_Tagger.read_lexicon: number of lexicon entries read: ' + Object.keys(this.lexicon).length);
|
|
39
39
|
}
|
|
40
40
|
catch (error) {
|
|
41
41
|
console.error(error);
|
|
@@ -53,7 +53,7 @@ function Lexicon(filename, defaultCategory, defaultCategoryCapitalised) {
|
|
|
53
53
|
Lexicon.prototype.parseLexicon = function(data) {
|
|
54
54
|
// Split into an array of non-empty lines
|
|
55
55
|
var arrayOfLines = data.match(/[^\r\n]+/g);
|
|
56
|
-
this.lexicon = {};
|
|
56
|
+
this.lexicon = {}; //Object.create(null);
|
|
57
57
|
var that = this;
|
|
58
58
|
arrayOfLines.forEach(function(line) {
|
|
59
59
|
// Split line by whitespace
|
|
@@ -64,21 +64,26 @@ Lexicon.prototype.parseLexicon = function(data) {
|
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
Lexicon.prototype.tagWordWithDefaults = function(word) {
|
|
68
|
+
if (/[A-Z]/.test(word[0]) && this.defaultCategoryCapitalised) {
|
|
69
|
+
// Capitalised
|
|
70
|
+
return this.defaultCategoryCapitalised;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// If not found assign default_category
|
|
74
|
+
return this.defaultCategory;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
67
78
|
// Returns a list of categories for word
|
|
68
79
|
Lexicon.prototype.tagWord = function(word) {
|
|
69
80
|
var categories = this.lexicon[word];
|
|
70
|
-
|
|
81
|
+
//console.log(categories);
|
|
82
|
+
if (!categories || (typeof categories == "function")) {
|
|
71
83
|
categories = this.lexicon[word.toLowerCase()];
|
|
72
84
|
}
|
|
73
|
-
if (!categories) {
|
|
74
|
-
|
|
75
|
-
// Capitalised
|
|
76
|
-
categories = [this.defaultCategoryCapitalised];
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// If not found assign default_category
|
|
80
|
-
categories = [this.defaultCategory];
|
|
81
|
-
}
|
|
85
|
+
if (!categories || (typeof categories == "function")) {
|
|
86
|
+
categories = [this.tagWordWithDefaults(word)];
|
|
82
87
|
}
|
|
83
88
|
return(categories);
|
|
84
89
|
};
|
|
@@ -105,6 +110,10 @@ Lexicon.prototype.nrEntries = function() {
|
|
|
105
110
|
return Object.keys(this.lexicon).length;
|
|
106
111
|
};
|
|
107
112
|
|
|
113
|
+
Lexicon.prototype.size = function() {
|
|
114
|
+
return this.nrEntries();
|
|
115
|
+
};
|
|
116
|
+
|
|
108
117
|
Lexicon.prototype.setDefaultCategories = function(category, categoryCapitalised) {
|
|
109
118
|
this.defaultCategory = category;
|
|
110
119
|
if (categoryCapitalised) {
|
|
@@ -38,10 +38,10 @@ function Predicate(name, parameter1, parameter2) {
|
|
|
38
38
|
//logger.debug('Predicate\n' + JSON.toString(this.meta, null, 2));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
Predicate.prototype.evaluate = function(
|
|
41
|
+
Predicate.prototype.evaluate = function(sentence, position) {
|
|
42
42
|
//logger.debug('Predicate.evalute ' + this.name);
|
|
43
43
|
var predicate = this.meta.function;
|
|
44
|
-
return (predicate(
|
|
44
|
+
return (predicate(sentence, position, this.parameter1, this.parameter2));
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
module.exports = Predicate;
|
|
@@ -23,9 +23,9 @@ function RuleTemplate(templateName, metadata) {
|
|
|
23
23
|
|
|
24
24
|
RuleTemplate.prototype.windowFitsSite = function(sentence, i) {
|
|
25
25
|
return ((i + this.meta.window[0] >= 0) &&
|
|
26
|
-
(i + this.meta.window[0] < sentence.length) &&
|
|
26
|
+
(i + this.meta.window[0] < sentence.taggedWords.length) &&
|
|
27
27
|
(i + this.meta.window[1] >= 0) &&
|
|
28
|
-
(i + this.meta.window[1] < sentence.length));
|
|
28
|
+
(i + this.meta.window[1] < sentence.taggedWords.length));
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
module.exports = RuleTemplate;
|