Rename, titles, edit distance

This commit is contained in:
Tom MacWright
2013-01-30 17:41:06 -05:00
parent 2cb3e5849d
commit e63434f437
4 changed files with 29 additions and 1 deletions
+1 -1
View File
@@ -31,7 +31,7 @@
<script src='js/id/id.js'></script>
<script src='js/id/util.js'></script>
<script src='js/id/oauth.js'></script>
<script src='js/id/presets.js'></script>
<script src='js/id/presetdata.js'></script>
<script src='js/id/services/taginfo.js'></script>
<script src="js/id/geo.js"></script>
+6
View File
@@ -8,6 +8,12 @@ iD.presetData = function() {
return presets;
};
presets.search = function(str) {
var edits = _.sortBydata.map(function(d) {
return iD.util.editDistance(d.title, str);
});
};
presets.match = function(entity) {
return data.filter(function(d) {
return _.contains(d.match.type, entity.type);
+20
View File
@@ -74,3 +74,23 @@ iD.util.getStyle = function(selector) {
}
}
};
iD.util.editDistance = function(a, b) {
if (a.length === 0) return b.length;
if (b.length === 0) return a.length;
var matrix = [];
for (var i = 0; i <= b.length; i++) { matrix[i] = [i]; }
for (var j = 0; j <= a.length; j++) { matrix[0][j] = j; }
for (i = 1; i <= b.length; i++) {
for (j = 1; j <= a.length; j++) {
if (b.charAt(i-1) == a.charAt(j-1)) {
matrix[i][j] = matrix[i-1][j-1];
} else {
matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
}
}
return matrix[b.length][a.length];
};
+2
View File
@@ -1,5 +1,6 @@
[
{
"title": "Highway",
"name": "highway",
"match": {
"type": ["line"],
@@ -17,6 +18,7 @@
]
},
{
"title": "Cafe",
"name": "cafe",
"match": {
"type": ["node", "area"],