46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
/**
|
|
* Created by WebStorm.
|
|
* User: martin
|
|
* Date: 28/07/2020
|
|
* Time: 10:51
|
|
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
|
|
var bayes = require('bayes');
|
|
|
|
var classifier = bayes({
|
|
'tokenizer': function (text) {
|
|
return text.split(',');
|
|
}
|
|
});
|
|
|
|
// teach it positive phrases
|
|
|
|
async function load() {
|
|
const goodWords = ['tsql', 'developer', 'contract', 'web', 'javascript', 'js', 'node', 'es', 'agile', 'nodejs', 'london', 'aws', 'sql', 'postgresql', 'mysql', 'docker', 'ecs', 'automation', 'jslint', 'jshint', 'vuejs', 'vue', 'nginx', 'remotely', 'mvc', 'remote', 'iot', 'mqtt', 'es6', 'es2016', 'es2017', 'es2018', 'freelance'];
|
|
const badWords = ['react', 'redux', 'graphql', 'java', 'reactjs', 'shopify'];
|
|
|
|
for(let i = 0;i < goodWords.length - 1;i++)
|
|
await classifier.learn(goodWords[i], 'good');
|
|
|
|
for(let i = 0;i < badWords.length - 1;i++)
|
|
await classifier.learn(badWords[i], 'bad');
|
|
|
|
// now ask it to categorize a document it has never seen before
|
|
|
|
console.log(await classifier.categorize(['ui', 'developer', 'london', 'react'].join(',')));
|
|
|
|
console.log(await classifier.categorize(['mysql', 'react', 'js', 'node', 'docker', 'kubernetes', 'google'].join(',')));
|
|
|
|
// serialize the classifier's state as a JSON string.
|
|
var stateJson = classifier.toJson();
|
|
|
|
console.log(stateJson);
|
|
|
|
fs.writeFileSync('brain.json', stateJson);
|
|
}
|
|
|
|
load();
|