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.
Files changed (80) hide show
  1. package/.dockerignore +2 -0
  2. package/.idea/misc.xml +6 -0
  3. package/.idea/modules.xml +8 -0
  4. package/.idea/natural.iml +12 -0
  5. package/.idea/vcs.xml +6 -0
  6. package/.idea/workspace.xml +511 -0
  7. package/.travis.yml +8 -1
  8. package/README.md +331 -40
  9. package/bayes_classifier.json +1 -1
  10. package/classifier.json +418 -0
  11. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +8 -9
  12. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tester.js +5 -5
  13. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Trainer.js +10 -6
  14. package/lib/natural/brill_pos_tagger/lib/Corpus.js +21 -16
  15. package/lib/natural/brill_pos_tagger/lib/Lexicon.js +22 -13
  16. package/lib/natural/brill_pos_tagger/lib/Predicate.js +2 -2
  17. package/lib/natural/brill_pos_tagger/lib/RuleTemplate.js +2 -2
  18. package/lib/natural/brill_pos_tagger/lib/RuleTemplates.js +132 -146
  19. package/lib/natural/brill_pos_tagger/lib/Sentence.js +41 -0
  20. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +10 -11
  21. package/lib/natural/classifiers/classifier.js +5 -3
  22. package/lib/natural/classifiers/maxent/Classifier.js +125 -0
  23. package/lib/natural/classifiers/maxent/Context.js +33 -0
  24. package/lib/natural/classifiers/maxent/Distribution.js +145 -0
  25. package/lib/natural/classifiers/maxent/Element.js +34 -0
  26. package/lib/natural/classifiers/maxent/Feature.js +88 -0
  27. package/lib/natural/classifiers/maxent/FeatureSet.js +67 -0
  28. package/lib/natural/classifiers/maxent/GISScaler.js +148 -0
  29. package/lib/natural/classifiers/maxent/POS/ME_Corpus.js +56 -0
  30. package/lib/natural/classifiers/maxent/POS/ME_Sentence.js +73 -0
  31. package/lib/natural/classifiers/maxent/POS/POS_Element.js +172 -0
  32. package/lib/natural/classifiers/maxent/Sample.js +141 -0
  33. package/lib/natural/classifiers/maxent/SimpleExample/SE_Element.js +49 -0
  34. package/lib/natural/distance/hamming_distance.js +52 -0
  35. package/lib/natural/distance/jaro-winkler_distance.js +16 -6
  36. package/lib/natural/distance/levenshtein_distance.js +2 -2
  37. package/lib/natural/index.js +21 -2
  38. package/lib/natural/inflectors/noun_inflector.js +5 -3
  39. package/lib/natural/ngrams/ngrams.js +83 -25
  40. package/lib/natural/sentiment/Basque/senticon_eu.json +21557 -0
  41. package/lib/natural/sentiment/Catalan/senticon_ca.json +36352 -0
  42. package/lib/natural/sentiment/Dutch/negations_du.json +3 -0
  43. package/lib/natural/sentiment/Dutch/pattern-sentiment-nl.json +39650 -0
  44. package/lib/natural/sentiment/English/negations_en.json +3 -0
  45. package/lib/natural/sentiment/English/pattern-sentiment-en.json +16024 -0
  46. package/lib/natural/sentiment/English/senticon_en.json +124197 -0
  47. package/lib/natural/sentiment/French/pattern-sentiment-fr.json +40906 -0
  48. package/lib/natural/sentiment/Galician/senticon_gl.json +24427 -0
  49. package/lib/natural/sentiment/Italian/pattern-sentiment-it.json +24522 -0
  50. package/lib/natural/sentiment/SentimentAnalyzer.js +116 -0
  51. package/lib/natural/sentiment/Spanish/afinnShortSortedSpanish.json +1655 -0
  52. package/lib/natural/sentiment/Spanish/negations_es.json +3 -0
  53. package/lib/natural/sentiment/Spanish/senticon_es.json +56722 -0
  54. package/lib/natural/sentiment/tools/README.md +31 -0
  55. package/lib/natural/sentiment/tools/XmlParser4PatternData.js +31 -0
  56. package/lib/natural/sentiment/tools/sentimentXmlParser.js +30 -0
  57. package/lib/natural/stemmers/indonesian/data/kata-dasar.json +29935 -0
  58. package/lib/natural/stemmers/indonesian/prefix_rules.js +10 -9
  59. package/lib/natural/stemmers/indonesian/stemmer_id.js +16 -15
  60. package/lib/natural/stemmers/indonesian/suffix_rules.js +2 -2
  61. package/lib/natural/stemmers/porter_stemmer_es.js +265 -199
  62. package/lib/natural/stemmers/porter_stemmer_fr.js +1 -1
  63. package/lib/natural/stemmers/porter_stemmer_nl.js +362 -0
  64. package/lib/natural/stemmers/stemmer_es.js +18 -12
  65. package/lib/natural/stemmers/stemmer_nl.js +64 -0
  66. package/lib/natural/tfidf/tfidf.js +27 -4
  67. package/lib/natural/tokenizers/aggressive_tokenizer_sv.js +1 -1
  68. package/lib/natural/tokenizers/aggressive_tokenizer_vi.js +37 -0
  69. package/lib/natural/tokenizers/orthography_matchers.js +33 -0
  70. package/lib/natural/tokenizers/regexp_tokenizer.js +24 -4
  71. package/lib/natural/tokenizers/sentence_tokenizer.js +1 -1
  72. package/lib/natural/wordnet/wordnet_file.js +7 -1
  73. package/lr_classifier.json +1 -1
  74. package/package.json +35 -23
  75. package/.npmignore +0 -4
  76. package/.vscode/temp.sql +0 -0
  77. package/Makefile +0 -38
  78. package/data/kata-dasar.txt +0 -29933
  79. package/package-lock.json +0 -79
  80. 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
- // console.log('Brill_POS_Tagger.read_lexicon: number of lexicon entries read: ' + Object.keys(that.lexicon).length);
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
- if (!categories) {
81
+ //console.log(categories);
82
+ if (!categories || (typeof categories == "function")) {
71
83
  categories = this.lexicon[word.toLowerCase()];
72
84
  }
73
- if (!categories) {
74
- if (/[A-Z]/.test(word[0]) && this.defaultCategoryCapitalised) {
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(tagged_sentence, position) {
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(tagged_sentence, position, this.parameter1, this.parameter2));
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;