natural 0.5.4 → 0.6.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/.dockerignore +2 -0
- package/.npmignore +1 -0
- package/.travis.yml +1 -1
- package/README.md +412 -89
- package/bayes_classifier.json +1 -1
- package/classifier.json +418 -0
- package/data/kata-dasar.txt +29933 -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/TF_Parser.js +83 -76
- package/lib/natural/brill_pos_tagger/lib/TF_Parser.pegjs +19 -4
- package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +10 -11
- package/lib/natural/classifiers/classifier.js +15 -8
- 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 +164 -11
- package/lib/natural/index.js +26 -5
- package/lib/natural/inflectors/noun_inflector.js +15 -13
- package/lib/natural/ngrams/ngrams.js +83 -25
- package/lib/natural/normalizers/normalizer_sv.js +41 -0
- 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/base_stemmer_id.js +86 -0
- package/lib/natural/stemmers/indonesian/prefix_rules.js +1027 -0
- package/lib/natural/stemmers/indonesian/removal.js +49 -0
- package/lib/natural/stemmers/indonesian/stemmer_id.js +307 -0
- package/lib/natural/stemmers/indonesian/suffix_rules.js +75 -0
- 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/porter_stemmer_sv.js +99 -0
- package/lib/natural/stemmers/stemmer_es.js +18 -12
- package/lib/natural/stemmers/stemmer_nl.js +64 -0
- package/lib/natural/stemmers/stemmer_sv.js +61 -0
- package/lib/natural/tfidf/tfidf.js +27 -4
- package/lib/natural/tokenizers/aggressive_tokenizer_id.js +44 -0
- package/lib/natural/tokenizers/aggressive_tokenizer_sv.js +40 -0
- 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 +23 -3
- package/lib/natural/tokenizers/sentence_tokenizer.js +1 -1
- package/lib/natural/util/stopwords_id.js +119 -0
- package/lib/natural/util/stopwords_no.js +1 -1
- package/lib/natural/util/stopwords_sv.js +70 -0
- package/lib/natural/wordnet/wordnet_file.js +7 -1
- package/lr_classifier.json +1 -1
- package/package-lock.json +378 -0
- package/package.json +29 -21
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Tools
|
|
2
|
+
This folder contains some tools for manipulating vocabularies for the sentiment analyzer.
|
|
3
|
+
|
|
4
|
+
## `sentimentXmlParser`
|
|
5
|
+
Transforms ML-Senticon XML files into JSON files. The JSON file contains a vocabulary that maps words to objects as follows:
|
|
6
|
+
```javascript
|
|
7
|
+
"admirable": {
|
|
8
|
+
"pos": "a",
|
|
9
|
+
"pol": "1.0",
|
|
10
|
+
"std": "0.0"
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
Property `pol` is the sentiment of the word.
|
|
14
|
+
|
|
15
|
+
## `XmlParser4PatternData`
|
|
16
|
+
Transforms vocabularies of the [Pattern project](https://www.clips.uantwerpen.be/pages/pattern) to JSON files. The JSON file contains a vocabulary that maps wordt to objects:
|
|
17
|
+
```javascript
|
|
18
|
+
"aanraden": {
|
|
19
|
+
"form": "aanraden",
|
|
20
|
+
"cornetto_id": "",
|
|
21
|
+
"cornetto_synset_id": "",
|
|
22
|
+
"wordnet_id": "",
|
|
23
|
+
"pos": "VB",
|
|
24
|
+
"sense": "",
|
|
25
|
+
"polarity": "0.2",
|
|
26
|
+
"subjectivity": "0.0",
|
|
27
|
+
"intensity": "1.0",
|
|
28
|
+
"confidence": "0.9"
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
Property `polarity` is the sentiment of the word.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
var parseString = require('xml2js').parseString;
|
|
4
|
+
|
|
5
|
+
var baseFolder = "/home/hugo/Workspace/pattern/pattern/text/";
|
|
6
|
+
//var inputFile = baseFolder + "nl/nl-sentiment.xml";
|
|
7
|
+
//var outputFile = baseFolder + "nl/nl-sentiment.json";
|
|
8
|
+
//var inputFile = baseFolder + "fr/fr-sentiment.xml";
|
|
9
|
+
//var outputFile = baseFolder + "fr/fr-sentiment.json";
|
|
10
|
+
//var inputFile = baseFolder + "en/en-sentiment.xml";
|
|
11
|
+
//var outputFile = baseFolder + "en/en-sentiment.json";
|
|
12
|
+
var inputFile = baseFolder + "it/it-sentiment.xml";
|
|
13
|
+
var outputFile = baseFolder + "it/pattern-sentiment-it.json";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var xml = fs.readFileSync(inputFile , 'utf8');
|
|
18
|
+
var list = {};
|
|
19
|
+
|
|
20
|
+
parseString(xml, function (err, result) {
|
|
21
|
+
//console.log(JSON.stringify(result, null, 2));
|
|
22
|
+
console.log(result.sentiment.word.length);
|
|
23
|
+
for(var i =0; i < result.sentiment.word.length; i++){
|
|
24
|
+
console.log(result.sentiment.word[i].$.form);
|
|
25
|
+
list[result.sentiment.word[i].$.form] = result.sentiment.word[i].$;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log(Object.keys(list).length);
|
|
30
|
+
|
|
31
|
+
fs.writeFileSync(outputFile, JSON.stringify(list, null, 2));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
var parseString = require('xml2js').parseString;
|
|
4
|
+
|
|
5
|
+
var xml = fs.readFileSync('senticon.ca.xml', 'utf8');
|
|
6
|
+
|
|
7
|
+
var list = {};
|
|
8
|
+
|
|
9
|
+
parseString(xml, function (err, result) {
|
|
10
|
+
for(var i =0; i < result.senticon.layer.length; i++){
|
|
11
|
+
for(var j = 0; j < result.senticon.layer[i].positive[0].lemma.length; j++){
|
|
12
|
+
//console.log(util.inspect(result.senticon.layer[i].negative[0].lemma[j], false, null))
|
|
13
|
+
list[result.senticon.layer[i].positive[0].lemma[j]._] = result.senticon.layer[i].positive[0].lemma[j].$;
|
|
14
|
+
}
|
|
15
|
+
for(var n = 0; n < result.senticon.layer[i].negative[0].lemma.length; n++){
|
|
16
|
+
list[result.senticon.layer[i].negative[0].lemma[n]._] = result.senticon.layer[i].negative[0].lemma[n].$;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
var listTrimmed = {};
|
|
22
|
+
|
|
23
|
+
for(var token in list){
|
|
24
|
+
listTrimmed[token.replace(/ /gi, "").replace(/_/gi, " ")] = list[token]
|
|
25
|
+
}
|
|
26
|
+
console.log(listTrimmed);
|
|
27
|
+
//console.log(util.inspect(list, false, null))
|
|
28
|
+
console.log(Object.keys(listTrimmed).length);
|
|
29
|
+
|
|
30
|
+
fs.writeFileSync('senticon_ca.json', JSON.stringify(listTrimmed, null, 2));
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2017, Alif Bhaskoro, Andy Librian, R. Kukuh (Reimplemented from https://github.com/sastrawi/sastrawi)
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
var stopwords = require('../../util/stopwords_id');
|
|
24
|
+
var Tokenizer = require('../../tokenizers/aggressive_tokenizer_id');
|
|
25
|
+
|
|
26
|
+
module.exports = function() {
|
|
27
|
+
var stemmer = this;
|
|
28
|
+
|
|
29
|
+
stemmer.stem = function(token) {
|
|
30
|
+
return token;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
stemmer.addStopWord = function(stopWord) {
|
|
34
|
+
stopwords.words.push(stopWord);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
stemmer.addStopWords = function(moreStopWords) {
|
|
38
|
+
stopwords.words = stopwords.words.concat(moreStopWords);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
stemmer.removeStopWord = function(stopWord) {
|
|
42
|
+
this.removeStopWords([stopWord])
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
stemmer.removeStopWords = function(moreStopWords) {
|
|
46
|
+
moreStopWords.forEach(function(stopWord){
|
|
47
|
+
var idx = stopwords.words.indexOf(stopWord);
|
|
48
|
+
if (idx >= 0) {
|
|
49
|
+
stopwords.words.splice(idx, 1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
stemmer.tokenizeAndStem = function(text, keepStops) {
|
|
57
|
+
var stemmedTokens = [];
|
|
58
|
+
var lowercaseText = text.toLowerCase();
|
|
59
|
+
var tokens = new Tokenizer().tokenize(lowercaseText);
|
|
60
|
+
|
|
61
|
+
if (keepStops) {
|
|
62
|
+
tokens.forEach(function(token) {
|
|
63
|
+
stemmedTokens.push(stemmer.stem(token));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
else {
|
|
68
|
+
tokens.forEach(function(token) {
|
|
69
|
+
if (stopwords.words.indexOf(token) == -1)
|
|
70
|
+
stemmedTokens.push(stemmer.stem(token));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return stemmedTokens;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
stemmer.attach = function() {
|
|
78
|
+
String.prototype.stem = function() {
|
|
79
|
+
return stemmer.stem(this);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
String.prototype.tokenizeAndStem = function(keepStops) {
|
|
83
|
+
return stemmer.tokenizeAndStem(this, keepStops);
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|