-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (50 loc) · 1.97 KB
/
main.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
function printCorrect(inpText){
var natural = require('natural');
var soundEx = natural.SoundEx;
var lineReader = require('readline').createInterface({
//input: require('fs').createReadStream('/etc/dictionaries-common/words')
input: require('fs').createReadStream('dictionary.txt')
});
var MDistJWD = 0;
var MDistLeven = 99999999;
var MDistDamLeven = 99999999;
var MDistDice = 0;
var ansJWD = "";
var ansLeven = "";
var ansDamLeven = "";
var ansDice = "";
var ansArr = ["according to n-gram words can be : "];
lineReader.on('line', function (line) {
if(natural.JaroWinklerDistance(inpText,line) > MDistJWD){
MDistJWD = natural.JaroWinklerDistance(inpText,line);
ansJWD = line;
}
if(natural.LevenshteinDistance(inpText,line) != -1&&natural.LevenshteinDistance(inpText,line) < MDistLeven){
MDistLeven = natural.LevenshteinDistance(inpText,line);
ansLeven = line;
}
if(natural.DamerauLevenshteinDistance(inpText,line) != -1&&natural.DamerauLevenshteinDistance(inpText,line) < MDistDamLeven){
MDistDamLeven = natural.DamerauLevenshteinDistance(inpText,line);
ansDamLeven = line;
}
if(natural.DiceCoefficient(inpText,line) != -1&&natural.DiceCoefficient(inpText,line) > MDistDice){
MDistDice = natural.DiceCoefficient(inpText,line);
ansDice = line;
}
}
);
lineReader.on('close', function(){
console.log("correct words can be : " + ansJWD + " , " + ansLeven + " , " + ansDamLeven + " , " + ansDice );
});
}
var standard_input = process.stdin;
standard_input.setEncoding('utf-8');
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Enter Query Term: ", function(answer){
printCorrect(answer);
rl.close();
});