Repository navigation
Expand file tree
/
Copy pathcompareData.js
More file actions
112 lines (106 loc) · 2.53 KB
/
Copy pathcompareData.js
File metadata and controls
112 lines (106 loc) · 2.53 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function compareData(tiles, osmData)
{
// split per tile
var i = -1;
for (var d = 0; d < tiles.length; d++)
{
tiles[d].osmData = [];
while (!osmData[++i].count)
tiles[d].osmData.push(osmData[i]);
}
for (var d = 0; d < tiles.length; d++)
{
var data = tiledData[tiles[d].datasetName][tiles[d].tileName].data;
var settings = datasetSettings[tiles[d].datasetName];
var maxScore = 1;
for (var t = 0; t < settings.tagmatch.length; t++)
maxScore += settings.tagmatch[t].importance || 1;
for (var p = 0; p < data.length; p++)
{
var point = data[p];
point.maxScore = maxScore;
point.score = 0;
point.osmElement = {};
var bestScore = 0;
for (var i = 0; i < tiles[d].osmData.length; i++)
{
var element = tiles[d].osmData[i];
if (geoHelper.getDistance(element.center || element, point.coordinates) > settings.dist)
continue;
var score = 1;
for (var t = 0; t < settings.tagmatch.length; t++)
{
var tag = settings.tagmatch[t];
score += comparisonAlgorithms[tag.algorithm || "equality"](
point.properties[tag.key],
element.tags[tag.key]) * (tag.importance || 1);
}
if (score > bestScore)
{
point.osmElement = element;
point.score = score;
bestScore = score;
}
}
displayPoint(tiles[d].datasetName, tiles[d].tileName, p);
}
}
}
// every comparison algorithm returns a value between 0 and 1
// where 0 is non-matching and 1 is perfectly matching
// TODO alternative algorithms: levenshtein, opening hours equivalence, ...:
var comparisonAlgorithms = {
"equality": function(v1, v2)
{
if (!v1)
return 1;
if (v1 == v2)
return 1;
return 0;
},
/**
* Checks if all elements of the semicolumn separated list v1 are in v2
*/
"inList": function(v1, v2)
{
if (!v1)
return 1;
if (!v2)
return 0;
var l1 = v1.split(";");
var l2 = v2.split(";");
for (var i = 0; i < l1.length; i++)
if (l2.indexOf(l1[i]) == -1)
return 0;
return 1;
},
/**
* Checks if two lists contain the same elements (not neccesarily the same order)
*/
"equalList": function(v1, v2)
{
return comparisonAlgorithms.inList(v1, v2) && comparisonAlgorithms.inList(v2, v1);
},
"equalIgnoreCase": function(v1, v2)
{
if (!v1)
return 1;
if (!v2)
return 0;
return v1.toLowerCase() == v2.toLowerCase();
},
"substringIgnoreCase": function(v1, v2)
{
if (!v1)
return 1;
if (!v2)
return 0;
return v1.toLowerCase().indexOf(v2.toLowerCase()) != -1;
},
"presence": function(v1, v2)
{
if (!v1)
return 1;
return v2 ? 1 : 0;
},
};