-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClassifierDemo.js
46 lines (34 loc) · 1.61 KB
/
ClassifierDemo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
//The classifier depends on redis
const redis = require("redis");
//Import the classifier
const VocabularyClassifier = require("./Includes/VocabularyClassifier.js");
//Create a redis client
const client = redis.createClient();
//Wait until redis is connected
client.on('connect', function() {
client.select(1, function(err, res){
//Create a instance of the Classifier
classifier = new VocabularyClassifier(client, 1);
//Train the classifier with labeled data
classifier.trainLabel("german", "dies ist ein deutscher text text", function(){
//Train it again with different labeld data
classifier.trainLabel("english", "this is an english text", function(){
//Classify a new text
classifier.classifyText(["german", "english"], "dies ist text and some unknown words", function(result, reduced){
//Output the result for every word
console.log(JSON.stringify(result, null, 3));
//Output the result for the entire text
console.log(reduced);
//Output the trained labels
classifier.getLabels(function(result)
{
console.log(result);
//Remove the labels to free the redis database
classifier.removeLabel("german");
classifier.removeLabel("english");
})
});
});
});
});
});