-
-
Save butaji/28b04ed288d04380e335b85feb3b5d09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const natural = require('natural'); | |
const extract = require('article-parser').extract; | |
const run = (c, url) => { | |
natural.BayesClassifier.load('classifier.json', null, async(err, classifier) => { | |
if (err) { | |
console.log(err); | |
classifier = new natural.BayesClassifier(); | |
} | |
const article = (await extract(url)).content; | |
classifier.addDocument(article, c); | |
classifier.train(); | |
const classifications = classifier.getClassifications(article); | |
console.log(classifications); | |
const cls = classifications.reduce((acc, v) => { | |
acc[v.label] = v.value; | |
return acc; | |
}, {}); | |
await classifier.save('classifier.json'); | |
console.log('good:', cls['good'] > cls['bad'], 'as', (cls['good'] / cls['bad'])); | |
}); | |
} | |
run(process.argv[2], process.argv[3]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm i natural -s | |
npm i article-parser -s | |
node p.js [bad/good] [url] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment