Browse Source

change admin property names to <place_type>_gid from <place_type>_id

pull/488/head
Diana Shkolnikov 9 years ago
parent
commit
147c849b58
  1. 21
      helper/geojsonify.js
  2. 11
      helper/placeTypes.js
  3. 14
      middleware/normalizeParentIds.js
  4. 40
      middleware/renamePlacenames.js
  5. 38
      test/unit/helper/geojsonify.js
  6. 32
      test/unit/middleware/normalizeParentIds.js

21
helper/geojsonify.js

@ -4,6 +4,7 @@ var GeoJSON = require('geojson'),
labelGenerator = require('./labelGenerator'), labelGenerator = require('./labelGenerator'),
logger = require('pelias-logger').get('api'), logger = require('pelias-logger').get('api'),
type_mapping = require('./type_mapping'), type_mapping = require('./type_mapping'),
Document = require('pelias-model').Document,
_ = require('lodash'); _ = require('lodash');
// Properties to be copied // Properties to be copied
@ -14,28 +15,29 @@ var DETAILS_PROPS = [
'confidence', 'confidence',
'distance', 'distance',
'country', 'country',
'country_id', 'country_gid',
'country_a', 'country_a',
'macroregion', 'macroregion',
'macroregion_id', 'macroregion_gid',
'macroregion_a', 'macroregion_a',
'region', 'region',
'region_id', 'region_gid',
'region_a', 'region_a',
'macrocounty', 'macrocounty',
'macrocounty_id', 'macrocounty_gid',
'macrocounty_a', 'macrocounty_a',
'county', 'county',
'county_id', 'county_gid',
'county_a', 'county_a',
'localadmin', 'localadmin',
'localadmin_id', 'localadmin_gid',
'localadmin_a', 'localadmin_a',
'locality', 'locality',
'locality_id', 'locality_gid',
'locality_a', 'locality_a',
'neighbourhood', 'neighbourhood',
'neighbourhood_id' 'neighbourhood_gid',
'bounding_box'
]; ];
@ -235,7 +237,8 @@ function copyProperties( source, props, dst ) {
* @param {object} src * @param {object} src
*/ */
function makeGid(src) { function makeGid(src) {
return lookupSource(src) + ':' + lookupLayer(src) + ':' + src._id; var doc = new Document(lookupSource(src), lookupLayer(src), src._id);
return doc.getGid();
} }
/** /**

11
helper/placeTypes.js

@ -0,0 +1,11 @@
module.exports = [
'country',
'macroregion',
'region',
'macrocounty',
'county',
'localadmin',
'locality',
'borough',
'neighbourhood'
];

14
middleware/normalizeParentIds.js

@ -1,17 +1,7 @@
var logger = require('pelias-logger').get('api'); var logger = require('pelias-logger').get('api');
var Document = require('pelias-model').Document; var Document = require('pelias-model').Document;
var placeTypes = [ var placeTypes = require('../helper/placeTypes');
'country',
'macroregion',
'region',
'macrocounty',
'county',
'localadmin',
'locality',
'neighbourhood',
'borough'
];
/** /**
* Convert WOF integer ids to Pelias formatted ids that can be used by the /place endpoint. * Convert WOF integer ids to Pelias formatted ids that can be used by the /place endpoint.
@ -42,7 +32,7 @@ function normalizeParentIds(place) {
if (place) { if (place) {
placeTypes.forEach(function (placeType) { placeTypes.forEach(function (placeType) {
if (place[placeType] && place[placeType].length > 0 && place[placeType][0]) { if (place[placeType] && place[placeType].length > 0 && place[placeType][0]) {
place[placeType + '_id'] = [ makeNewId(placeType, place[placeType + '_id']) ]; place[placeType + '_gid'] = [ makeNewId(placeType, place[placeType + '_gid']) ];
} }
}); });
} }

40
middleware/renamePlacenames.js

@ -1,16 +1,6 @@
var _ = require('lodash'); var _ = require('lodash');
/** var PARENT_PROPS = require('../helper/placeTypes');
- P is a preferred English name
- Q is a preferred name (in other languages)
- V is a well-known (but unofficial) variant for the place
(e.g. "New York City" for New York)
- S is either a synonym or a colloquial name for the place
(e.g. "Big Apple" for New York), or a version of the name which
is stripped of accent characters.
- A is an abbreviation or code for the place (e.g. "NYC" for New
York)
*/
var ADDRESS_PROPS = { var ADDRESS_PROPS = {
'number': 'housenumber', 'number': 'housenumber',
@ -18,32 +8,6 @@ var ADDRESS_PROPS = {
'street': 'street' 'street': 'street'
}; };
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',
'localadmin',
'localadmin_id',
'localadmin_a',
'locality',
'locality_id',
'locality_a',
'neighbourhood',
'neighbourhood_id'
];
function setup() { function setup() {
return renamePlacenames; return renamePlacenames;
@ -74,6 +38,8 @@ function renameOneRecord(place) {
if (place.parent) { if (place.parent) {
PARENT_PROPS.forEach(function (prop) { PARENT_PROPS.forEach(function (prop) {
place[prop] = place.parent[prop]; place[prop] = place.parent[prop];
place[prop + '_a'] = place.parent[prop + '_a'];
place[prop + '_gid'] = place.parent[prop + '_id'];
}); });
} }

38
test/unit/helper/geojsonify.js

@ -17,6 +17,8 @@ module.exports.tests.earth = function(test, common) {
var earth = [{ var earth = [{
'_type': 'geoname', '_type': 'geoname',
'_id': '6295630', '_id': '6295630',
'source': 'whosonfirst',
'layer': 'continent',
'name': { 'name': {
'default': 'Earth' 'default': 'Earth'
}, },
@ -240,7 +242,7 @@ module.exports.tests.search = function(test, common) {
'country': [ 'country': [
'United States' 'United States'
], ],
'country_id': [ 'country_gid': [
'85633793' '85633793'
], ],
'country_a': [ 'country_a': [
@ -249,7 +251,7 @@ module.exports.tests.search = function(test, common) {
'macroregion': [ 'macroregion': [
'MacroRegion Name' 'MacroRegion Name'
], ],
'macroregion_id': [ 'macroregion_gid': [
'MacroRegion Id' 'MacroRegion Id'
], ],
'macroregion_a': [ 'macroregion_a': [
@ -258,7 +260,7 @@ module.exports.tests.search = function(test, common) {
'region': [ 'region': [
'New York' 'New York'
], ],
'region_id': [ 'region_gid': [
'85688543' '85688543'
], ],
'region_a': [ 'region_a': [
@ -267,7 +269,7 @@ module.exports.tests.search = function(test, common) {
'macrocounty': [ 'macrocounty': [
'MacroCounty Name' 'MacroCounty Name'
], ],
'macrocounty_id': [ 'macrocounty_gid': [
'MacroCounty Id' 'MacroCounty Id'
], ],
'macrocounty_a': [ 'macrocounty_a': [
@ -276,7 +278,7 @@ module.exports.tests.search = function(test, common) {
'county': [ 'county': [
'Kings County' 'Kings County'
], ],
'county_id': [ 'county_gid': [
'102082361' '102082361'
], ],
'county_a': [ 'county_a': [
@ -285,20 +287,20 @@ module.exports.tests.search = function(test, common) {
'localadmin': [ 'localadmin': [
'Brooklyn' 'Brooklyn'
], ],
'localadmin_id': [ 'localadmin_gid': [
'404521211' '404521211'
], ],
'localadmin_a': [ 'localadmin_a': [
null null
], ],
'locality_id': [ 'locality_gid': [
'85977539' '85977539'
], ],
'locality_a': [ 'locality_a': [
null null
], ],
'neighbourhood': [], 'neighbourhood': [],
'neighbourhood_id': [] 'neighbourhood_gid': []
} }
]; ];
@ -316,23 +318,29 @@ module.exports.tests.search = function(test, common) {
'name': 'East New York', 'name': 'East New York',
'confidence': 0.888, 'confidence': 0.888,
'country': 'United States', 'country': 'United States',
'country_id': '85633793', 'country_gid': '85633793',
'country_a': 'USA', 'country_a': 'USA',
'macroregion': 'MacroRegion Name', 'macroregion': 'MacroRegion Name',
'macroregion_id': 'MacroRegion Id', 'macroregion_gid': 'MacroRegion Id',
'macroregion_a': 'MacroRegion Abbreviation', 'macroregion_a': 'MacroRegion Abbreviation',
'region': 'New York', 'region': 'New York',
'region_id': '85688543', 'region_gid': '85688543',
'region_a': 'NY', 'region_a': 'NY',
'macrocounty': 'MacroCounty Name', 'macrocounty': 'MacroCounty Name',
'macrocounty_id': 'MacroCounty Id', 'macrocounty_gid': 'MacroCounty Id',
'macrocounty_a': 'MacroCounty Abbreviation', 'macrocounty_a': 'MacroCounty Abbreviation',
'county': 'Kings County', 'county': 'Kings County',
'county_id': '102082361', 'county_gid': '102082361',
'localadmin': 'Brooklyn', 'localadmin': 'Brooklyn',
'localadmin_id': '404521211', 'localadmin_gid': '404521211',
'locality': 'New York', 'locality': 'New York',
'locality_id': '85977539', 'locality_gid': '85977539',
'bounding_box': {
'min_lat': 40.6514712164,
'max_lat': 40.6737320588,
'min_lon': -73.8967895508,
'max_lon': -73.8665771484
},
'label': 'East New York, Brooklyn, NY, USA' 'label': 'East New York, Brooklyn, NY, USA'
}, },
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588], 'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588],

32
test/unit/middleware/normalizeParentIds.js

@ -13,28 +13,28 @@ module.exports.tests.interface = function(test, common) {
'country_a': ['USA'] 'country_a': ['USA']
}, },
'country': ['United States'], 'country': ['United States'],
'country_id': ['85633793'], 'country_gid': ['85633793'],
'country_a': ['USA'], 'country_a': ['USA'],
'macroregion': ['MacroRegion Name'], 'macroregion': ['MacroRegion Name'],
'macroregion_id': ['foobar'], 'macroregion_gid': ['foobar'],
'macroregion_a': ['MacroRegion Abbreviation'], 'macroregion_a': ['MacroRegion Abbreviation'],
'region': ['New York'], 'region': ['New York'],
'region_id': ['85688543'], 'region_gid': ['85688543'],
'region_a': ['NY'], 'region_a': ['NY'],
'macrocounty': ['MacroCounty Name'], 'macrocounty': ['MacroCounty Name'],
'macrocounty_id': ['~~~~~'], 'macrocounty_gid': ['~~~~~'],
'macrocounty_a': ['MacroCounty Abbreviation'], 'macrocounty_a': ['MacroCounty Abbreviation'],
'county': ['Kings County'], 'county': ['Kings County'],
'county_id': ['102082361'], 'county_gid': ['102082361'],
'county_a': [null], 'county_a': [null],
'localadmin': ['Brooklyn'], 'localadmin': ['Brooklyn'],
'localadmin_id': ['404521211'], 'localadmin_gid': ['404521211'],
'localadmin_a': [null], 'localadmin_a': [null],
'locality': ['Some Locality'], 'locality': ['Some Locality'],
'locality_id': ['85977539'], 'locality_gid': ['85977539'],
'locality_a': [null], 'locality_a': [null],
'neighbourhood': [], 'neighbourhood': [],
'neighbourhood_id': [] 'neighbourhood_gid': []
}] }]
}; };
@ -46,28 +46,28 @@ module.exports.tests.interface = function(test, common) {
'country_a': ['USA'] 'country_a': ['USA']
}, },
'country': ['United States'], 'country': ['United States'],
'country_id': ['whosonfirst:country:85633793'], 'country_gid': ['whosonfirst:country:85633793'],
'country_a': ['USA'], 'country_a': ['USA'],
'macroregion': ['MacroRegion Name'], 'macroregion': ['MacroRegion Name'],
'macroregion_id': ['whosonfirst:macroregion:foobar'], 'macroregion_gid': ['whosonfirst:macroregion:foobar'],
'macroregion_a': ['MacroRegion Abbreviation'], 'macroregion_a': ['MacroRegion Abbreviation'],
'region': ['New York'], 'region': ['New York'],
'region_id': ['whosonfirst:region:85688543'], 'region_gid': ['whosonfirst:region:85688543'],
'region_a': ['NY'], 'region_a': ['NY'],
'macrocounty': ['MacroCounty Name'], 'macrocounty': ['MacroCounty Name'],
'macrocounty_id': ['whosonfirst:macrocounty:~~~~~'], 'macrocounty_gid': ['whosonfirst:macrocounty:~~~~~'],
'macrocounty_a': ['MacroCounty Abbreviation'], 'macrocounty_a': ['MacroCounty Abbreviation'],
'county': ['Kings County'], 'county': ['Kings County'],
'county_id': ['whosonfirst:county:102082361'], 'county_gid': ['whosonfirst:county:102082361'],
'county_a': [null], 'county_a': [null],
'localadmin': ['Brooklyn'], 'localadmin': ['Brooklyn'],
'localadmin_id': ['whosonfirst:localadmin:404521211'], 'localadmin_gid': ['whosonfirst:localadmin:404521211'],
'localadmin_a': [null], 'localadmin_a': [null],
'locality': ['Some Locality'], 'locality': ['Some Locality'],
'locality_id': ['whosonfirst:locality:85977539'], 'locality_gid': ['whosonfirst:locality:85977539'],
'locality_a': [null], 'locality_a': [null],
'neighbourhood': [], 'neighbourhood': [],
'neighbourhood_id': [] 'neighbourhood_gid': []
}] }]
}; };

Loading…
Cancel
Save