natural 6.10.2 → 6.10.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 (42) hide show
  1. package/.github/workflows/node.js.yml +1 -1
  2. package/.github/workflows/npm-publish.yml +4 -4
  3. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +33 -31
  4. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tester.js +33 -35
  5. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Trainer.js +326 -324
  6. package/lib/natural/brill_pos_tagger/lib/Corpus.js +140 -138
  7. package/lib/natural/brill_pos_tagger/lib/Lexicon.js +78 -76
  8. package/lib/natural/brill_pos_tagger/lib/Predicate.js +19 -17
  9. package/lib/natural/brill_pos_tagger/lib/RuleSet.js +58 -56
  10. package/lib/natural/brill_pos_tagger/lib/RuleTemplate.js +11 -9
  11. package/lib/natural/brill_pos_tagger/lib/Sentence.js +21 -20
  12. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +58 -58
  13. package/lib/natural/classifiers/bayes_classifier.js +24 -29
  14. package/lib/natural/classifiers/classifier.js +136 -121
  15. package/lib/natural/classifiers/logistic_regression_classifier.js +33 -37
  16. package/lib/natural/classifiers/maxent/Classifier.js +81 -79
  17. package/lib/natural/classifiers/maxent/Context.js +11 -9
  18. package/lib/natural/classifiers/maxent/Distribution.js +107 -105
  19. package/lib/natural/classifiers/maxent/Element.js +12 -10
  20. package/lib/natural/classifiers/maxent/Feature.js +56 -54
  21. package/lib/natural/classifiers/maxent/FeatureSet.js +40 -38
  22. package/lib/natural/classifiers/maxent/GISScaler.js +110 -109
  23. package/lib/natural/classifiers/maxent/POS/ME_Corpus.js +26 -31
  24. package/lib/natural/classifiers/maxent/POS/ME_Sentence.js +37 -42
  25. package/lib/natural/classifiers/maxent/POS/POS_Element.js +119 -124
  26. package/lib/natural/classifiers/maxent/Sample.js +96 -94
  27. package/lib/natural/classifiers/maxent/SimpleExample/SE_Element.js +14 -20
  28. package/lib/natural/inflectors/fr/count_inflector.js +1 -1
  29. package/lib/natural/inflectors/fr/noun_inflector.js +179 -196
  30. package/lib/natural/inflectors/ja/noun_inflector.js +67 -84
  31. package/lib/natural/inflectors/noun_inflector.js +124 -139
  32. package/lib/natural/inflectors/present_verb_inflector.js +34 -48
  33. package/lib/natural/inflectors/singular_plural_inflector.js +62 -61
  34. package/lib/natural/tfidf/tfidf.js +118 -114
  35. package/lib/natural/trie/trie.js +161 -159
  36. package/lib/natural/util/directed_edge.js +49 -0
  37. package/lib/natural/util/edge_weighted_digraph.js +54 -74
  38. package/lib/natural/util/index.js +1 -0
  39. package/lib/natural/util/longest_path_tree.js +54 -52
  40. package/lib/natural/util/shortest_path_tree.js +56 -54
  41. package/lib/natural/util/topological.js +17 -15
  42. package/package.json +1 -1
@@ -22,7 +22,7 @@ jobs:
22
22
  steps:
23
23
  - uses: actions/checkout@v2
24
24
  - name: Use Node.js ${{ matrix.node-version }}
25
- uses: actions/setup-node@v1
25
+ uses: actions/setup-node@v4
26
26
  with:
27
27
  node-version: ${{ matrix.node-version }}
28
28
  - run: npm ci
@@ -1,6 +1,6 @@
1
1
  # This workflow will run tests using node and then publish a package to NPMjs when a release is created
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
-
3
+ ---
4
4
  name: Node.js Package
5
5
 
6
6
  on:
@@ -12,7 +12,7 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  steps:
14
14
  - uses: actions/checkout@v2
15
- - uses: actions/setup-node@v1
15
+ - uses: actions/setup-node@v4
16
16
  with:
17
17
  node-version: 12
18
18
  - run: npm ci
@@ -23,12 +23,12 @@ jobs:
23
23
  runs-on: ubuntu-latest
24
24
  steps:
25
25
  - uses: actions/checkout@v2
26
- - uses: actions/setup-node@v1
26
+ - uses: actions/setup-node@v4
27
27
  with:
28
28
  node-version: 14
29
29
  registry-url: https://registry.npmjs.org/
30
30
  - run: npm ci
31
- - run: git config user.name $GITHUB_ACTOR
31
+ - run: git config user.name "$GITHUB_ACTOR"
32
32
  - run: npm publish
33
33
  env:
34
34
  NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}}
@@ -22,42 +22,44 @@ const Sentence = require('./Sentence')
22
22
 
23
23
  const DEBUG = false
24
24
 
25
- function BrillPOSTagger (lexicon, ruleSet) {
26
- this.lexicon = lexicon
27
- this.ruleSet = ruleSet
28
- }
29
-
30
- // Tags a sentence, sentence is an array of words
31
- // Returns an array of tagged words; a tagged words is an array consisting of
32
- // the word itself followed by its lexical category
33
- BrillPOSTagger.prototype.tag = function (sentence) {
34
- const taggedSentence = this.tagWithLexicon(sentence)
35
- DEBUG && console.log(taggedSentence)
36
- return this.applyRules(taggedSentence)
37
- }
25
+ class BrillPOSTagger {
26
+ constructor (lexicon, ruleSet) {
27
+ this.lexicon = lexicon
28
+ this.ruleSet = ruleSet
29
+ }
38
30
 
39
- BrillPOSTagger.prototype.tagWithLexicon = function (sentence) {
40
- const taggedSentence = new Sentence()
31
+ // Tags a sentence, sentence is an array of words
32
+ // Returns an array of tagged words; a tagged words is an array consisting of
33
+ // the word itself followed by its lexical category
34
+ tag (sentence) {
35
+ const taggedSentence = this.tagWithLexicon(sentence)
36
+ DEBUG && console.log(taggedSentence)
37
+ return this.applyRules(taggedSentence)
38
+ }
41
39
 
42
- const that = this
43
- sentence.forEach(function (word, index) {
44
- const categories = that.lexicon.tagWord(word)
45
- taggedSentence.addTaggedWord(word, categories[0])
46
- })
47
- return (taggedSentence)
48
- }
40
+ tagWithLexicon (sentence) {
41
+ const taggedSentence = new Sentence()
49
42
 
50
- // Applies the transformation rules to an initially tagged sentence.
51
- // taggedSentence is an array of tagged words.
52
- // A tagged word is an array consisting of the word itself followed by its lexical category.
53
- // Returns an array of tagged words as well
54
- BrillPOSTagger.prototype.applyRules = function (sentence) {
55
- for (let i = 0, size = sentence.taggedWords.length; i < size; i++) {
56
- this.ruleSet.getRules().forEach(function (rule) {
57
- rule.apply(sentence, i)
43
+ const that = this
44
+ sentence.forEach(function (word, index) {
45
+ const categories = that.lexicon.tagWord(word)
46
+ taggedSentence.addTaggedWord(word, categories[0])
58
47
  })
48
+ return (taggedSentence)
49
+ }
50
+
51
+ // Applies the transformation rules to an initially tagged sentence.
52
+ // taggedSentence is an array of tagged words.
53
+ // A tagged word is an array consisting of the word itself followed by its lexical category.
54
+ // Returns an array of tagged words as well
55
+ applyRules (sentence) {
56
+ for (let i = 0, size = sentence.taggedWords.length; i < size; i++) {
57
+ this.ruleSet.getRules().forEach(function (rule) {
58
+ rule.apply(sentence, i)
59
+ })
60
+ }
61
+ return sentence
59
62
  }
60
- return sentence
61
63
  }
62
64
 
63
65
  module.exports = BrillPOSTagger
@@ -18,43 +18,41 @@
18
18
 
19
19
  'use strict'
20
20
 
21
- function BrillPOSTester () {
22
-
23
- }
24
-
25
- BrillPOSTester.prototype.test = function (corpus, tagger) {
26
- let totalWords = 0
27
- let correctTagsLexicon = 0
28
- let correctTagsAfterRules = 0
29
-
30
- // Tag the corpus using the tagger
31
- corpus.sentences.forEach(function (sentence) {
32
- const s = sentence.taggedWords.map(function (token) {
33
- return token.token
34
- })
35
-
36
- // Use the lexicon to tag the sentence
37
- const taggedSentence = tagger.tagWithLexicon(s)
38
- // Count the right tags
39
- sentence.taggedWords.forEach(function (token, i) {
40
- totalWords++
41
- if (token.tag === taggedSentence.taggedWords[i].tag) {
42
- correctTagsLexicon++
43
- }
44
- })
45
-
46
- // Use the rule set to tag the sentence
47
- const taggedSentenceAfterRules = tagger.applyRules(taggedSentence)
48
- // Count the right tags
49
- sentence.taggedWords.forEach(function (token, i) {
50
- if (token.tag === taggedSentenceAfterRules.taggedWords[i].tag) {
51
- correctTagsAfterRules++
52
- }
21
+ class BrillPOSTester {
22
+ test (corpus, tagger) {
23
+ let totalWords = 0
24
+ let correctTagsLexicon = 0
25
+ let correctTagsAfterRules = 0
26
+
27
+ // Tag the corpus using the tagger
28
+ corpus.sentences.forEach(function (sentence) {
29
+ const s = sentence.taggedWords.map(function (token) {
30
+ return token.token
31
+ })
32
+
33
+ // Use the lexicon to tag the sentence
34
+ const taggedSentence = tagger.tagWithLexicon(s)
35
+ // Count the right tags
36
+ sentence.taggedWords.forEach(function (token, i) {
37
+ totalWords++
38
+ if (token.tag === taggedSentence.taggedWords[i].tag) {
39
+ correctTagsLexicon++
40
+ }
41
+ })
42
+
43
+ // Use the rule set to tag the sentence
44
+ const taggedSentenceAfterRules = tagger.applyRules(taggedSentence)
45
+ // Count the right tags
46
+ sentence.taggedWords.forEach(function (token, i) {
47
+ if (token.tag === taggedSentenceAfterRules.taggedWords[i].tag) {
48
+ correctTagsAfterRules++
49
+ }
50
+ })
53
51
  })
54
- })
55
52
 
56
- // Return percentage right
57
- return [100 * correctTagsLexicon / totalWords, 100 * correctTagsAfterRules / totalWords]
53
+ // Return percentage right
54
+ return [100 * correctTagsLexicon / totalWords, 100 * correctTagsAfterRules / totalWords]
55
+ }
58
56
  }
59
57
 
60
58
  module.exports = BrillPOSTester