mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-18 14:45:12 +02:00
Rename, titles, edit distance
This commit is contained in:
+1
-1
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[
|
||||
{
|
||||
"title": "Highway",
|
||||
"name": "highway",
|
||||
"match": {
|
||||
"type": ["line"],
|
||||
@@ -17,6 +18,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Cafe",
|
||||
"name": "cafe",
|
||||
"match": {
|
||||
"type": ["node", "area"],
|
||||
|
||||
Reference in New Issue
Block a user