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.
- package/.github/workflows/node.js.yml +1 -1
- package/.github/workflows/npm-publish.yml +4 -4
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +33 -31
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tester.js +33 -35
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Trainer.js +326 -324
- package/lib/natural/brill_pos_tagger/lib/Corpus.js +140 -138
- package/lib/natural/brill_pos_tagger/lib/Lexicon.js +78 -76
- package/lib/natural/brill_pos_tagger/lib/Predicate.js +19 -17
- package/lib/natural/brill_pos_tagger/lib/RuleSet.js +58 -56
- package/lib/natural/brill_pos_tagger/lib/RuleTemplate.js +11 -9
- package/lib/natural/brill_pos_tagger/lib/Sentence.js +21 -20
- package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +58 -58
- package/lib/natural/classifiers/bayes_classifier.js +24 -29
- package/lib/natural/classifiers/classifier.js +136 -121
- package/lib/natural/classifiers/logistic_regression_classifier.js +33 -37
- package/lib/natural/classifiers/maxent/Classifier.js +81 -79
- package/lib/natural/classifiers/maxent/Context.js +11 -9
- package/lib/natural/classifiers/maxent/Distribution.js +107 -105
- package/lib/natural/classifiers/maxent/Element.js +12 -10
- package/lib/natural/classifiers/maxent/Feature.js +56 -54
- package/lib/natural/classifiers/maxent/FeatureSet.js +40 -38
- package/lib/natural/classifiers/maxent/GISScaler.js +110 -109
- package/lib/natural/classifiers/maxent/POS/ME_Corpus.js +26 -31
- package/lib/natural/classifiers/maxent/POS/ME_Sentence.js +37 -42
- package/lib/natural/classifiers/maxent/POS/POS_Element.js +119 -124
- package/lib/natural/classifiers/maxent/Sample.js +96 -94
- package/lib/natural/classifiers/maxent/SimpleExample/SE_Element.js +14 -20
- package/lib/natural/inflectors/fr/count_inflector.js +1 -1
- package/lib/natural/inflectors/fr/noun_inflector.js +179 -196
- package/lib/natural/inflectors/ja/noun_inflector.js +67 -84
- package/lib/natural/inflectors/noun_inflector.js +124 -139
- package/lib/natural/inflectors/present_verb_inflector.js +34 -48
- package/lib/natural/inflectors/singular_plural_inflector.js +62 -61
- package/lib/natural/tfidf/tfidf.js +118 -114
- package/lib/natural/trie/trie.js +161 -159
- package/lib/natural/util/directed_edge.js +49 -0
- package/lib/natural/util/edge_weighted_digraph.js +54 -74
- package/lib/natural/util/index.js +1 -0
- package/lib/natural/util/longest_path_tree.js +54 -52
- package/lib/natural/util/shortest_path_tree.js +56 -54
- package/lib/natural/util/topological.js +17 -15
- package/package.json +1 -1
|
@@ -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@
|
|
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@
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
57
|
-
|
|
53
|
+
// Return percentage right
|
|
54
|
+
return [100 * correctTagsLexicon / totalWords, 100 * correctTagsAfterRules / totalWords]
|
|
55
|
+
}
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
module.exports = BrillPOSTester
|