-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (62 loc) · 2.02 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var NaiveClassifier = require('./mymodule/NaiveClassifier');
const prompt = require('prompt');
var config = {
caseFolding : 0,
escapeCharacter : 0,
stopword : 0,
stem : 0
};
var schema = {
properties: {
caseFolding: {
message: 'Use case folding (use = 1, no = 0) : ',
required: true
},
escapeCharacter: {
message: 'Use escape character (use = 1, no = 0) : ',
required: true
},
stopword: {
message: 'Use Stopword (use = 1, no = 0) : ',
required: true
},
stem: {
message: 'Use stemming (use = 1, no =0) : ',
required: true
}
}
};
prompt.get(schema, function (err, result) {
config.caseFolding = parseInt(result.caseFolding);
config.escapeCharacter = parseInt(result.escapeCharacter);
config.stopword = parseInt(result.stopword);
config.stem = parseInt(result.stem);
var naive = new NaiveClassifier(config);
const readline = require('readline');
naive.splitSgml();
naive.on('splitEnd',function () {
naive.learnAll()
});
naive.on('learnEnd',function () {
naive.testAll();
});
naive.on('testAllEnd',function () {
});
naive.on('createXMLEnd',function () {
console.log('Classifying test file finished, please wait until output file written completely in to folder named \'output\' !!');
var inputText = '';
var rl = readline.createInterface(process.stdin, process.stdout);
rl.setPrompt(' \n you can type your test data body text here (end it with \'end>\') in new line, \n or type \'exit1\' to quit > ');
rl.prompt();
rl.on('line', function(line) {
if (line === "exit1") rl.close();
inputText += line;
if (line === "end>"){
console.log('Topic : '+naive.testOne(inputText));
rl.prompt();
}
}).on('close',function(){
process.exit(0);
});
});
})