mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 21:28:11 +02:00
@@ -110,21 +110,34 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
|
||||
|
||||
preset.matchScore = function(entityTags) {
|
||||
var tags = preset.tags;
|
||||
var seen = {};
|
||||
var score = 0;
|
||||
var k;
|
||||
|
||||
for (var t in tags) {
|
||||
if (entityTags[t] === tags[t]) {
|
||||
// match on tags
|
||||
for (k in tags) {
|
||||
seen[k] = true;
|
||||
if (entityTags[k] === tags[k]) {
|
||||
score += preset.originalScore;
|
||||
} else if (tags[t] === '*' && t in entityTags) {
|
||||
} else if (tags[k] === '*' && k in entityTags) {
|
||||
score += preset.originalScore / 2;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// boost score for additional matches in addTags - #6802
|
||||
var addTags = preset.addTags;
|
||||
for (k in addTags) {
|
||||
if (!seen[k] && entityTags[k] === addTags[k]) {
|
||||
score += preset.originalScore;
|
||||
}
|
||||
}
|
||||
|
||||
return score;
|
||||
};
|
||||
|
||||
|
||||
var _textCache = {};
|
||||
|
||||
preset.t = function(scope, options) {
|
||||
|
||||
@@ -44,6 +44,34 @@ describe('iD.presetPreset', function() {
|
||||
var entity = iD.osmWay({tags: {building: 'yep'}});
|
||||
expect(preset.matchScore(entity.tags)).to.equal(0.5);
|
||||
});
|
||||
|
||||
it('boosts matchScore for additional matches in addTags', function() {
|
||||
var presetSupercenter = iD.presetPreset('shop/supermarket/walmart_supercenter', {
|
||||
tags: { 'brand:wikidata': 'Q483551', 'shop': 'supermarket' },
|
||||
addTags: { 'name': 'Walmart Supercenter' }
|
||||
});
|
||||
var presetMarket = iD.presetPreset('shop/supermarket/walmart_market', {
|
||||
tags: { 'brand:wikidata': 'Q483551', 'shop': 'supermarket' },
|
||||
addTags: { 'name': 'Walmart Neighborhood Market' }
|
||||
});
|
||||
|
||||
var supercenter = iD.osmWay({ tags: {
|
||||
'brand:wikidata': 'Q483551',
|
||||
'shop': 'supermarket',
|
||||
'name': 'Walmart Supercenter'
|
||||
}});
|
||||
var market = iD.osmWay({ tags: {
|
||||
'brand:wikidata': 'Q483551',
|
||||
'shop': 'supermarket',
|
||||
'name': 'Walmart Neighborhood Market'
|
||||
}});
|
||||
|
||||
expect(presetSupercenter.matchScore(supercenter.tags))
|
||||
.to.be.greaterThan(presetMarket.matchScore(supercenter.tags));
|
||||
|
||||
expect(presetMarket.matchScore(market.tags))
|
||||
.to.be.greaterThan(presetSupercenter.matchScore(market.tags));
|
||||
});
|
||||
});
|
||||
|
||||
describe('isFallback', function() {
|
||||
|
||||
Reference in New Issue
Block a user