[SOLVED] Can someone demonstrate how Levenshtein distance can be translated into Construct 2?
What i want to achieve is the following:
1. I would like to have an array of sentences.
2. The user is supposed to enter one sentence, one at a time, and this sentence is meant to be compared with a correspoding model sentence stored in the array. No need to search through.
3. It is anticipated that the user will make some typos while entering the sentence. i want to allow such mistakes to happen like this:
Model sentence: "This text is awesome"
User input: "This next is awesome"
Result: comparison accepted.
It would be good if i could set the comparison threshold.
Taking all of the above into consideration, i have stumpled upon multiple times on this code below. I believe it could do what i want. Sadly i am not smart enough to translate it into construct 2. Can someone do it and help me achieve the goal described above?
// Compute the edit distance between the two given strings
exports.getEditDistance = function(a, b){
if(a.length == 0) return b.length;
if(b.length == 0) return a.length;
var matrix = [];
// increment along the first column of each row
var i;
for(i = 0; i <= b.length; i++){
matrix = ;
}
// increment each column in the first row
var j;
for(j = 0; j <= a.length; j++){
matrix[0][j] = j;
}
// Fill in the rest of the matrix
for(i = 1; i <= b.length; i++){
for(j = 1; j <= a.length; j++){
if(b.charAt(i-1) == a.charAt(j-1)){
matrix[j] = matrix[i-1][j-1];
} else {
matrix[j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
}
}
return matrix[b.length][a.length];
};
source page of the code: gist.github.com/andrei-m/982927