Permalink
Browse files

Custom cost table for more precise matching

Implementing a custom cost table which brings a better matching on commands. The apparently small improvement of these custom codes will make a big difference (I believe) in the step-by-step matching that will be implemented soon.
  • Loading branch information...
1 parent b0f90d1 commit 6b363a800b70a4cc084ec12cfafd35c4d1719831 @felipc committed Mar 24, 2009
Showing with 13 additions and 1 deletion.
  1. +13 −1 chrome/content/GestureEngine.js
@@ -250,6 +250,17 @@ FennecGestures.prototype = {
return movements;
},
+
+ _levCostTable: {
+ q: {q: 0, w: 1, e: 1, d: 2, c: 2, x: 2, z: 1, a: 1},
+ w: {q: 1, w: 0, e: 1, d: 2, c: 2, x: 2, z: 2, a: 2},
+ e: {q: 1, w: 1, e: 0, d: 1, c: 1, x: 2, z: 2, a: 2},
+ d: {q: 2, w: 2, e: 1, d: 0, c: 1, x: 2, z: 2, a: 2},
+ c: {q: 2, w: 2, e: 1, d: 1, c: 0, x: 1, z: 1, a: 2},
+ x: {q: 2, w: 2, e: 2, d: 2, c: 1, x: 0, z: 1, a: 2},
+ z: {q: 1, w: 2, e: 2, d: 2, c: 1, x: 1, z: 0, a: 1},
+ a: {q: 1, w: 2, e: 2, d: 2, c: 2, x: 2, z: 1, a: 0}
+ },
_levenshtein: function (str1, str2, maxThreshold) {
@@ -294,7 +305,8 @@ FennecGestures.prototype = {
for (j = 1; j < len; j++) {
- cost = ((str1[j-1] == str2[i-1]) ? 0 : 1);
+ //cost = ((str1[j-1] == str2[i-1]) ? 0 : 1);
+ cost = this._levCostTable[ str1[j-1] ][ str2[i-1] ];
localValue = Math.min( line1[j] + 1, line2[j-1] + 1, line1[j-1] + cost)
line2[j] = localValue;

0 comments on commit 6b363a8

Please sign in to comment.