Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use "name:en" as a fallback for when no default name was found #498

Merged
merged 2 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ module.exports = function(){
}
}

// Handle the case where no default name was set but there were
// other names which we could use as the default.
if( !doc.getName('default') ){

var defaultName =
doc.getName('official') ||
doc.getName('international') ||
doc.getName('national') ||
doc.getName('regional') ||
doc.getName('en');

// use one of the preferred name tags listed above
if ( defaultName ){
doc.setName('default', defaultName);
}

// else try to use an available two-letter language name tag
else {
var keys = Object.keys(doc.name).filter(n => n.length === 2);

// unambiguous (there is only a single two-letter name tag)
if ( keys.length === 1 ){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pursuing this! Looks like the best solution.

doc.setName('default', doc.getName(keys[0]));
}

// note we do not handle ambiguous cases where the record contains >1
// two-letter name tags.
// see: https://github.com/pelias/openstreetmap/pull/498
}
}

// Import airport codes as aliases
if( tags.hasOwnProperty('aerodrome') || tags.hasOwnProperty('aeroway') ){
if( tags.hasOwnProperty('iata') ){
Expand Down
31 changes: 31 additions & 0 deletions test/fixtures/combined_vancouver_queens.json
Original file line number Diff line number Diff line change
Expand Up @@ -115938,6 +115938,37 @@
"source_id": "node/2900172775"
}
},
{
"_index": "pelias",
"_type": "venue",
"_id": "node/2900172775",
"data": {
"name": {
"en": "Soka Gakkai International (SGI) Vancouver Culture Centre",
"default": "Soka Gakkai International (SGI) Vancouver Culture Centre"
},
"phrase": {
"en": "Soka Gakkai International (SGI) Vancouver Culture Centre",
"default": "Soka Gakkai International (SGI) Vancouver Culture Centre"
},
"address_parts": {
"number": "8401",
"zip": "V6P 3J9",
"street": "Cambie Street"
},
"center_point": {
"lon": -123.117345,
"lat": 49.209697
},
"category": [
"education",
"entertainment"
],
"source": "openstreetmap",
"layer": "venue",
"source_id": "node/2900172775"
}
},
{
"_index": "pelias",
"_type": "address",
Expand Down
69 changes: 69 additions & 0 deletions test/stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,75 @@ module.exports.tests.accept_localized_keys = function(test, common) {
});
};

// Use 'name:official' in situations where no other default name was available
// https://github.com/pelias/openstreetmap/issues/497
module.exports.tests.use_official_as_fallback_default = function (test, common) {
var doc = new Document('a', 'b', 1);
doc.setMeta('tags', { 'name:ru': 'test1', 'name:en': 'test2', 'official_name': 'test3' });
test('maps - use name:official as fallback default', function (t) {
var stream = mapper();
stream.pipe(through.obj(function (doc, enc, next) {
t.equal(doc.getName('default'), 'test3', 'name:en used as fallback');
t.equal(doc.getName('ru'), 'test1', 'correctly mapped');
t.equal(doc.getName('en'), 'test2', 'correctly mapped');
t.equal(doc.getName('official'), 'test3', 'correctly mapped');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};

// Use 'name:en' in situations where no other default name was available
// https://github.com/pelias/openstreetmap/issues/497
module.exports.tests.use_en_as_fallback_default = function (test, common) {
var doc = new Document('a', 'b', 1);
doc.setMeta('tags', { 'name:ru': 'test1', 'name:pl': 'test2', 'name:en': 'test3' });
test('maps - use name:en as fallback default', function (t) {
var stream = mapper();
stream.pipe(through.obj(function (doc, enc, next) {
t.equal(doc.getName('default'), 'test3', 'name:en used as fallback');
t.equal(doc.getName('ru'), 'test1', 'correctly mapped');
t.equal(doc.getName('pl'), 'test2', 'correctly mapped');
t.equal(doc.getName('en'), 'test3', 'correctly mapped');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};

// Use the *only* available name:** tag as fallback
module.exports.tests.unambiguous_default_name_fallback = function (test, common) {
var doc = new Document('a', 'b', 1);
doc.setMeta('tags', { 'name:ru': 'test1' });
test('maps - unambiguous name:** used as default name fallback', function (t) {
var stream = mapper();
stream.pipe(through.obj(function (doc, enc, next) {
t.equal(doc.getName('default'), 'test1', 'only name:** tag used as fallback');
t.equal(doc.getName('ru'), 'test1', 'correctly mapped');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};

// In cases where there are multiple name:** tags, do not try to guess
module.exports.tests.ambiguous_default_name_fallback = function (test, common) {
var doc = new Document('a', 'b', 1);
doc.setMeta('tags', { 'name:ru': 'test1', 'name:pl': 'test2' });
test('maps - ambiguous name:** not used as default name fallback', function (t) {
var stream = mapper();
stream.pipe(through.obj(function (doc, enc, next) {
t.false(doc.getName('default'), 'do not try to guess');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};

module.exports.tests.lowercase_keys = function(test, common) {
var doc = new Document('a','b',1);
doc.setMeta('tags', { 'name:EN': 'test' });
Expand Down