Browse Source

Merge pull request #648 from pelias/master

Merge master into staging
pull/654/head
Julian Simioni 8 years ago committed by GitHub
parent
commit
2591a15c38
  1. 3
      helper/geojsonify_place_details.js
  2. 13
      helper/labelGenerator.js
  3. 21
      helper/labelSchema.js
  4. 1
      helper/placeTypes.js
  5. 2
      test/ciao/autocomplete/layers_invalid.coffee
  6. 2
      test/ciao/autocomplete/layers_mix_invalid_valid.coffee
  7. 14
      test/ciao/reverse/boundary_circle_invalid_radius.coffee
  8. 16
      test/ciao/reverse/boundary_circle_valid_radius.coffee
  9. 2
      test/ciao/reverse/layers_invalid.coffee
  10. 2
      test/ciao/reverse/layers_mix_invalid_valid.coffee
  11. 6
      test/ciao/search/boundary_rect_valid.coffee
  12. 2
      test/ciao/search/layers_invalid.coffee
  13. 2
      test/ciao/search/layers_mix_invalid_valid.coffee
  14. 18
      test/unit/helper/geojsonify.js
  15. 201
      test/unit/helper/labelGenerator_AUS.js
  16. 8
      test/unit/helper/labelGenerator_default.js
  17. 4
      test/unit/helper/labelSchema.js
  18. 1
      test/unit/run.js

3
helper/geojsonify_place_details.js

@ -12,6 +12,9 @@ var DETAILS_PROPS = [
{ name: 'country', type: 'string' },
{ name: 'country_gid', type: 'string' },
{ name: 'country_a', type: 'string' },
{ name: 'dependency', type: 'string' },
{ name: 'dependency_gid', type: 'string' },
{ name: 'dependency_a', type: 'string' },
{ name: 'macroregion', type: 'string' },
{ name: 'macroregion_gid', type: 'string' },
{ name: 'macroregion_a', type: 'string' },

13
helper/labelGenerator.js

@ -47,8 +47,7 @@ function getSchema(country_a) {
}
// helper function that sets a default label for non-US/CA regions
// this is a very special case
// helper function that sets a default label for non-US/CA regions and countries
function getInitialLabel(record) {
if (isRegion(record.layer) &&
isGeonamesOrWhosOnFirst(record.source) &&
@ -56,10 +55,20 @@ function getInitialLabel(record) {
return [];
}
if (isCountry(record.layer)) {
return [];
}
return [record.name];
}
// this can go away once geonames is no longer supported
// https://github.com/pelias/wof-admin-lookup/issues/49
function isCountry(layer) {
return 'country' === layer;
}
function isRegion(layer) {
return 'region' === layer;
}

21
helper/labelSchema.js

@ -13,12 +13,17 @@ module.exports = {
'USA': {
'borough': getFirstProperty(['borough']),
'local': getFirstProperty(['locality', 'localadmin', 'county']),
'regional': getUsOrCaState,
'regional': getRegionalValue,
'country': getUSACountryValue
},
'AUS': {
'local' : getFirstProperty(['locality', 'localadmin']),
'regional' : getRegionalValue,
'country': getFirstProperty(['country'])
},
'CAN': {
'local': getFirstProperty(['locality']), // no localadmins in CAN
'regional': getUsOrCaState,
'regional': getRegionalValue,
'country': getFirstProperty(['country'])
}
};
@ -39,12 +44,12 @@ function getFirstProperty(fields) {
}
// this function is exclusively used for figuring out which field to use for US/CA States
// 1. if a US/CA state is the most granular bit of info entered, the label should contain
// the full state name, eg: Pennsylvania, USA and Ontario, CA
// 2. otherwise, the state abbreviation should be used, eg: Lancaster, PA, USA and Bruce, ON, CA
// 3. if for some reason the abbreviation isn't available, use the full state name
function getUsOrCaState(record) {
// this function is exclusively used for figuring out which field to use for states/provinces
// 1. if a state/province is the most granular bit of info entered, the label should contain
// the full state/province name, eg: Pennsylvania, USA and Ontario, CA
// 2. otherwise, the state/province abbreviation should be used, eg: Lancaster, PA, USA and Bruce, ON, CA
// 3. if the abbreviation isn't available, use the full state/province name
function getRegionalValue(record) {
if ('region' === record.layer && record.region) {
// return full state name when state is the most granular piece of info
return record.region;

1
helper/placeTypes.js

@ -1,5 +1,6 @@
module.exports = [
'country',
'dependency',
'macroregion',
'region',
'macrocounty',

2
test/ciao/autocomplete/layers_invalid.coffee

@ -24,7 +24,7 @@ json.features.should.be.instanceof Array
#? expected errors
should.exist json.geocoding.errors
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,dependency,macroregion,localadmin,macrocounty,macrohood,borough,neighbourhood,microhood,disputed' ]
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,localadmin,locality,borough,neighbourhood,continent,dependency,macrocounty,macrohood,microhood,disputed' ]
#? expected warnings
should.not.exist json.geocoding.warnings

2
test/ciao/autocomplete/layers_mix_invalid_valid.coffee

@ -24,7 +24,7 @@ json.features.should.be.instanceof Array
#? expected errors
should.exist json.geocoding.errors
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,dependency,macroregion,localadmin,macrocounty,macrohood,borough,neighbourhood,microhood,disputed' ]
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,localadmin,locality,borough,neighbourhood,continent,dependency,macrocounty,macrohood,microhood,disputed' ]
#? expected warnings
should.not.exist json.geocoding.warnings

14
test/ciao/reverse/boundary_circle_invalid_radius.coffee

@ -26,14 +26,10 @@ json.features.should.be.instanceof Array
should.exist json.geocoding.errors
json.geocoding.errors.should.eql [ 'missing param \'boundary.circle.radius\'' ]
#? expected warnings
should.exist json.geocoding.warnings
json.geocoding.warnings.should.eql [ 'boundary.circle is currently unsupported' ]
#? inputs
# json.geocoding.query['size'].should.eql 10
# json.geocoding.query['point.lat'].should.eql 40.744243
# json.geocoding.query['point.lon'].should.eql -73.990342
# json.geocoding.query['boundary.circle.lat'].should.eql 40.744243
# json.geocoding.query['boundary.circle.lon'].should.eql -73.990342
# should.not.exist json.geocoding.query['boundary.circle.radius']
json.geocoding.query['point.lat'].should.eql 40.744243
json.geocoding.query['point.lon'].should.eql -73.990342
should.not.exist json.geocoding.query['boundary.circle.radius']
should.not.exist json.geocoding.query['boundary.circle.lat']
should.not.exist json.geocoding.query['boundary.circle.lon']

16
test/ciao/reverse/boundary_circle_valid_radius.coffee

@ -25,14 +25,10 @@ json.features.should.be.instanceof Array
#? expected errors
should.not.exist json.geocoding.errors
#? expected warnings
should.exist json.geocoding.warnings
json.geocoding.warnings.should.eql [ 'boundary.circle is currently unsupported' ]
#? inputs
# json.geocoding.query['size'].should.eql 10
# json.geocoding.query['point.lat'].should.eql 40.744243
# json.geocoding.query['point.lon'].should.eql -73.990342
# json.geocoding.query['boundary.circle.lat'].should.eql 40.744243
# json.geocoding.query['boundary.circle.lon'].should.eql -73.990342
# json.geocoding.query['boundary.circle.radius'].should.eql 999.9
json.geocoding.query['size'].should.eql 10
json.geocoding.query['point.lat'].should.eql 40.744243
json.geocoding.query['point.lon'].should.eql -73.990342
json.geocoding.query['boundary.circle.lat'].should.eql 40.744243
json.geocoding.query['boundary.circle.lon'].should.eql -73.990342
json.geocoding.query['boundary.circle.radius'].should.eql 999.9

2
test/ciao/reverse/layers_invalid.coffee

@ -24,7 +24,7 @@ json.features.should.be.instanceof Array
#? expected errors
should.exist json.geocoding.errors
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,dependency,macroregion,localadmin,macrocounty,macrohood,borough,neighbourhood,microhood,disputed' ]
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,localadmin,locality,borough,neighbourhood,continent,dependency,macrocounty,macrohood,microhood,disputed' ]
#? expected warnings
should.not.exist json.geocoding.warnings

2
test/ciao/reverse/layers_mix_invalid_valid.coffee

@ -24,7 +24,7 @@ json.features.should.be.instanceof Array
#? expected errors
should.exist json.geocoding.errors
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,dependency,macroregion,localadmin,macrocounty,macrohood,borough,neighbourhood,microhood,disputed' ]
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,localadmin,locality,borough,neighbourhood,continent,dependency,macrocounty,macrohood,microhood,disputed' ]
#? expected warnings
should.not.exist json.geocoding.warnings

6
test/ciao/search/boundary_rect_valid.coffee

@ -1,6 +1,6 @@
#> bounding rectangle
path: '/v1/search?text=a&boundary.rect.min_lat=-40.659&boundary.rect.max_lat=-41.614&boundary.rect.min_lon=174.612&boundary.rect.max_lon=176.333'
path: '/v1/search?text=a&boundary.rect.max_lat=-40.659&boundary.rect.min_lat=-41.614&boundary.rect.min_lon=174.612&boundary.rect.max_lon=176.333'
#? 200 ok
response.statusCode.should.be.equal 200
@ -31,7 +31,7 @@ should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10
json.geocoding.query['boundary.rect.min_lat'].should.eql -40.659
json.geocoding.query['boundary.rect.max_lat'].should.eql -41.614
json.geocoding.query['boundary.rect.min_lat'].should.eql -41.614
json.geocoding.query['boundary.rect.max_lat'].should.eql -40.659
json.geocoding.query['boundary.rect.min_lon'].should.eql 174.612
json.geocoding.query['boundary.rect.max_lon'].should.eql 176.333

2
test/ciao/search/layers_invalid.coffee

@ -24,7 +24,7 @@ json.features.should.be.instanceof Array
#? expected errors
should.exist json.geocoding.errors
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,dependency,macroregion,localadmin,macrocounty,macrohood,borough,neighbourhood,microhood,disputed' ]
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,localadmin,locality,borough,neighbourhood,continent,dependency,macrocounty,macrohood,microhood,disputed' ]
#? expected warnings
should.not.exist json.geocoding.warnings

2
test/ciao/search/layers_mix_invalid_valid.coffee

@ -24,7 +24,7 @@ json.features.should.be.instanceof Array
#? expected errors
should.exist json.geocoding.errors
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,region,county,locality,continent,dependency,macroregion,localadmin,macrocounty,macrohood,borough,neighbourhood,microhood,disputed' ]
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,localadmin,locality,borough,neighbourhood,continent,dependency,macrocounty,macrohood,microhood,disputed' ]
#? expected warnings
should.not.exist json.geocoding.warnings

18
test/unit/helper/geojsonify.js

@ -58,6 +58,7 @@ module.exports.tests.geojsonify = function(test, common) {
'postalcode': 'N1 0RW',
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'region': 'Islington',
'region_a': 'ISL',
'macroregion': 'England',
@ -85,6 +86,7 @@ module.exports.tests.geojsonify = function(test, common) {
},
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'region': 'City And County Of The City Of London',
'region_a': 'COL',
'macroregion': 'England',
@ -108,6 +110,7 @@ module.exports.tests.geojsonify = function(test, common) {
},
'country_a': 'USA',
'country': 'United States',
'dependency': 'dependency name',
'region': 'New York',
'region_a': 'NY',
'county': 'New York',
@ -144,6 +147,7 @@ module.exports.tests.geojsonify = function(test, common) {
'name': '\'Round Midnight Jazz and Blues Bar',
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'macroregion': 'England',
'region': 'Islington',
'region_a': 'ISL',
@ -179,6 +183,7 @@ module.exports.tests.geojsonify = function(test, common) {
'name': 'Blues Cafe',
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'macroregion': 'England',
'region': 'City And County Of The City Of London',
'region_a': 'COL',
@ -207,6 +212,7 @@ module.exports.tests.geojsonify = function(test, common) {
'name': 'Empire State Building',
'country_a': 'USA',
'country': 'United States',
'dependency': 'dependency name',
'region': 'New York',
'region_a': 'NY',
'county': 'New York',
@ -267,6 +273,15 @@ module.exports.tests.geojsonify = function(test, common) {
'country_a': [
'USA'
],
'dependency': [
'dependency name'
],
'dependency_gid': [
'dependency id'
],
'dependency_a': [
'dependency abbrevation'
],
'macroregion': [
'MacroRegion Name'
],
@ -341,6 +356,9 @@ module.exports.tests.geojsonify = function(test, common) {
'country': 'United States',
'country_gid': '85633793',
'country_a': 'USA',
'dependency': 'dependency name',
'dependency_gid': 'dependency id',
'dependency_a': 'dependency abbrevation',
'macroregion': 'MacroRegion Name',
'macroregion_gid': 'MacroRegion Id',
'macroregion_a': 'MacroRegion Abbreviation',

201
test/unit/helper/labelGenerator_AUS.js

@ -0,0 +1,201 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.australia = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'venue name, locality name, region name, Australia');
t.end();
});
test('localadmin value should be used when locality is not available', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'venue name, localadmin name, region name, Australia');
t.end();
});
test('street', function(t) {
var doc = {
'name': 'house number street name',
'layer': 'address',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'house number street name, locality name, region name, Australia');
t.end();
});
test('neighbourhood', function(t) {
var doc = {
'name': 'neighbourhood name',
'layer': 'neighbourhood',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'neighbourhood name, locality name, region name, Australia');
t.end();
});
test('locality', function(t) {
var doc = {
'name': 'locality name',
'layer': 'locality',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'locality name, region name, Australia');
t.end();
});
test('localadmin', function(t) {
var doc = {
'name': 'localadmin name',
'layer': 'localadmin',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'localadmin name, region name, Australia');
t.end();
});
test('county', function(t) {
var doc = {
'name': 'county name',
'layer': 'county',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'county name, region name, Australia');
t.end();
});
test('macrocounty', function(t) {
var doc = {
'name': 'macrocounty name',
'layer': 'macrocounty',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'macrocounty name, region name, Australia');
t.end();
});
test('region', function(t) {
var doc = {
'name': 'region name',
'layer': 'region',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'region name, Australia');
t.end();
});
test('macroregion', function(t) {
var doc = {
'name': 'macroregion name',
'layer': 'macroregion',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'macroregion name, Australia');
t.end();
});
test('country', function(t) {
var doc = {
'name': 'Australia',
'layer': 'country',
'postalcode': 'postalcode',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'Australia');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator (AUS): ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

8
test/unit/helper/labelGenerator_default.js

@ -175,14 +175,14 @@ module.exports.tests.default_country = function(test, common) {
t.end();
});
test('country', function(t) {
test('country layer labels should only use the `country` field and not the `name`', function(t) {
var doc = {
'name': 'country name',
'name': 'source country name',
'layer': 'country',
'country_a': 'country code',
'country': 'country name'
'country': 'hierarchy country name'
};
t.equal(generator(doc),'country name');
t.equal(generator(doc),'hierarchy country name');
t.end();
});

4
test/unit/helper/labelSchema.js

@ -18,12 +18,14 @@ module.exports.tests.supported_countries = function(test, common) {
t.notEquals(supported_countries.indexOf('USA'), -1);
t.notEquals(supported_countries.indexOf('CAN'), -1);
t.notEquals(supported_countries.indexOf('GBR'), -1);
t.notEquals(supported_countries.indexOf('AUS'), -1);
t.notEquals(supported_countries.indexOf('default'), -1);
t.equals(supported_countries.length, 4);
t.equals(supported_countries.length, 5);
t.equals(Object.keys(schemas.USA).length, 4);
t.equals(Object.keys(schemas.CAN).length, 3);
t.equals(Object.keys(schemas.GBR).length, 3);
t.equals(Object.keys(schemas.AUS).length, 3);
t.equals(Object.keys(schemas.default).length, 2);
t.end();

1
test/unit/run.js

@ -16,6 +16,7 @@ var tests = [
require('./helper/labelGenerator_examples'),
require('./helper/labelGenerator_default'),
require('./helper/labelGenerator_CAN'),
require('./helper/labelGenerator_AUS'),
require('./helper/labelGenerator_GBR'),
require('./helper/labelGenerator_USA'),
require('./helper/labelSchema'),

Loading…
Cancel
Save