Boost matchScore if additional matches occur in addTags

(closes #6802)
This commit is contained in:
Bryan Housel
2019-08-26 12:53:03 -04:00
parent c8ef193512
commit 2fd6359505
2 changed files with 44 additions and 3 deletions
+16 -3
View File
@@ -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) {
+28
View File
@@ -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() {