Browse Source

Merge pull request #461 from pelias/modify-region-specific-label-generation

Modify region specific label generation
pull/470/head
Stephen K Hess 9 years ago
parent
commit
966b6a590e
  1. 6
      helper/geojsonify.js
  2. 19
      helper/labelGenerator.js
  3. 4
      helper/labelSchema.js
  4. 6
      middleware/renamePlacenames.js
  5. 24
      test/unit/helper/geojsonify.js
  6. 17
      test/unit/helper/labelGenerator_GBR.js
  7. 51
      test/unit/helper/labelGenerator_default.js

6
helper/geojsonify.js

@ -16,9 +16,15 @@ var DETAILS_PROPS = [
'country',
'country_id',
'country_a',
'macroregion',
'macroregion_id',
'macroregion_a',
'region',
'region_id',
'region_a',
'macrocounty',
'macrocounty_id',
'macrocounty_a',
'county',
'county_id',
'county_a',

19
helper/labelGenerator.js

@ -47,11 +47,28 @@ function getSchema(country_a) {
}
// helper function that sets a default label for non-US/CA regions
// this is a very special case
function getInitialLabel(record) {
if ('region' === record.layer && ('geonames' === record.source || 'whosonfirst' === record.source)) {
if (isRegion(record.layer) &&
isGeonamesOrWhosOnFirst(record.source) &&
isUSAOrCAN(record.country_a)) {
return [];
}
return [record.name];
}
function isRegion(layer) {
return 'region' === layer;
}
function isUSAOrCAN(country_a) {
return 'USA' === country_a || 'CAN' === country_a;
}
function isGeonamesOrWhosOnFirst(source) {
return 'geonames' === source || 'whosonfirst' === source;
}

4
helper/labelSchema.js

@ -8,7 +8,7 @@ module.exports = {
'country': getFirstProperty(['country_a'])
},
'GBR': {
'local': getFirstProperty(['neighbourhood', 'county', 'localadmin', 'locality', 'region']),
'local': getFirstProperty(['neighbourhood', 'county', 'localadmin', 'locality', 'macroregion', 'region']),
'regional': getFirstProperty(['county','country','region'])
},
'SGP': {
@ -20,7 +20,7 @@ module.exports = {
'regional': getFirstProperty(['country'])
},
'default': {
'local': getFirstProperty(['localadmin', 'locality', 'neighbourhood', 'county', 'region']),
'local': getFirstProperty(['localadmin', 'locality', 'neighbourhood', 'county', 'macroregion', 'region']),
'regional': getFirstProperty(['country'])
}
};

6
middleware/renamePlacenames.js

@ -22,9 +22,15 @@ var PARENT_PROPS = [
'country',
'country_id',
'country_a',
'macroregion',
'macroregion_id',
'macroregion_a',
'region',
'region_id',
'region_a',
'macrocounty',
'macrocounty_id',
'macrocounty_a',
'county',
'county_id',
'county_a',

24
test/unit/helper/geojsonify.js

@ -246,6 +246,15 @@ module.exports.tests.search = function(test, common) {
'country_a': [
'USA'
],
'macroregion': [
'MacroRegion Name'
],
'macroregion_id': [
'MacroRegion Id'
],
'macroregion_a': [
'MacroRegion Abbreviation'
],
'region': [
'New York'
],
@ -255,6 +264,15 @@ module.exports.tests.search = function(test, common) {
'region_a': [
'NY'
],
'macrocounty': [
'MacroCounty Name'
],
'macrocounty_id': [
'MacroCounty Id'
],
'macrocounty_a': [
'MacroCounty Abbreviation'
],
'county': [
'Kings County'
],
@ -300,9 +318,15 @@ module.exports.tests.search = function(test, common) {
'country': 'United States',
'country_id': '85633793',
'country_a': 'USA',
'macroregion': 'MacroRegion Name',
'macroregion_id': 'MacroRegion Id',
'macroregion_a': 'MacroRegion Abbreviation',
'region': 'New York',
'region_id': '85688543',
'region_a': 'NY',
'macrocounty': 'MacroCounty Name',
'macrocounty_id': 'MacroCounty Id',
'macrocounty_a': 'MacroCounty Abbreviation',
'county': 'Kings County',
'county_id': '102082361',
'localadmin': 'Brooklyn',

17
test/unit/helper/labelGenerator_GBR.js

@ -58,6 +58,23 @@ module.exports.tests.wales = function(test, common) {
});
};
// GBR macroregion
module.exports.tests.macroregion_trumps_region = function(test, common) {
test('macroregion should trump region when none of neighbourhood, county, localadmin, locality are available', function(t) {
var doc = {
'name': 'Name',
'country_a': 'GBR',
'country': 'Country Name',
'macroregion': 'Macroregion Name',
'region': 'Region Name'
};
t.equal(generator(doc), 'Name, Macroregion Name, Country Name');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

51
test/unit/helper/labelGenerator_default.js

@ -251,6 +251,57 @@ module.exports.tests.waiotapu = function(test, common) {
});
};
module.exports.tests.non_us_or_ca_region = function(test, common) {
test('geonames US', function(t) {
var doc = {
'name': 'Default Name',
'country_a': 'XYZ',
'country': 'Full Country Name',
'region': 'Full Region Name',
'layer': 'region',
'source': 'geonames'
};
t.equal(generator(doc), 'Default Name, Full Region Name, Full Country Name');
t.end();
});
test('whosonfirst US', function(t) {
var doc = {
'name': 'Default Name',
'country_a': 'XYZ',
'country': 'Full Country Name',
'region': 'Full Region Name',
'layer': 'region',
'source': 'whosonfirst'
};
t.equal(generator(doc), 'Default Name, Full Region Name, Full Country Name');
t.end();
});
};
// macroregion
module.exports.tests.macroregion_trumps_region = function(test, common) {
test('macroregion should trump region when none of localadmin, locality, neighbourhood, county are available', function(t) {
var doc = {
'name': 'Name',
'country_a': 'Country abbreviation',
'country': 'Country Name',
'macroregion': 'Macroregion Name',
'region': 'Region Name'
};
t.equal(generator(doc), 'Name, Macroregion Name, Country Name');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

Loading…
Cancel
Save