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

Add more placetypes to download #280

Merged
merged 4 commits into from
Sep 21, 2017
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -31,12 +31,15 @@ Currently, the supported hierarchy types are:
- county
- dependency
- disputed
- [empire](https://www.youtube.com/watch?v=-bzWSJG93P8)
Copy link
Member

Choose a reason for hiding this comment

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

lol

- localadmin
- locality
- macrocounty
- macrohood
- macroregion
- marinearea
- neighbourhood
- ocean
- region
- postalcodes (optional, see configuration)

3 changes: 3 additions & 0 deletions src/bundleList.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,10 @@ const peliasConfig = require( 'pelias-config' ).generate(require('../schema'));
//
// downloading can be done in any order, but the same order might as well be used
const hierarchyRoles = [
'ocean',
'marinearea',
'continent',
'empire',
'country',
'dependency',
'disputed',
17 changes: 16 additions & 1 deletion src/components/extractFields.js
Original file line number Diff line number Diff line change
@@ -76,6 +76,21 @@ function getAbbreviation(properties) {
return properties['wof:abbreviation'];
}

function getHierarchies(id, properties) {
// if there are no hierarchies but there's a placetype, synthesize a hierarchy
if (_.isEmpty(_.get(properties, 'wof:hierarchy')) && _.has(properties, 'wof:placetype')) {
const hierarchy = {};
hierarchy[properties['wof:placetype'] + '_id'] = id;

return [hierarchy];

}

// otherwise just return the hierarchies as-is
return _.defaultTo(properties['wof:hierarchy'], []);

}

/*
This function extracts the fields from the json_object that we're interested
in for creating Pelias Document objects. If there is no hierarchy then a
@@ -94,7 +109,7 @@ module.exports.create = function map_fields_stream() {
bounding_box: getBoundingBox(json_object.properties),
population: getPopulation(json_object.properties),
popularity: json_object.properties['misc:photo_sum'],
hierarchies: _.get(json_object, 'properties.wof:hierarchy', [])
hierarchies: getHierarchies(json_object.id, json_object.properties)
};

// use the QS altname if US county and available
4 changes: 4 additions & 0 deletions src/peliasDocGenerators.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ function assignField(hierarchyElement, wofDoc) {
case 'county':
case 'macrocounty':
case 'macroregion':
case 'empire':
case 'continent':
case 'ocean':
case 'marinearea':
case 'postalcode':
// the above place_types don't have abbrevations (yet)
wofDoc.addParent(hierarchyElement.place_type, hierarchyElement.name, hierarchyElement.id.toString());
3 changes: 3 additions & 0 deletions test/bundleList.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,10 @@ proxyquire.noPreserveCache();
proxyquire.noCallThru();

const ADMIN = [
'ocean',
'marinearea',
'continent',
'empire',
'country',
'dependency',
'disputed',
173 changes: 141 additions & 32 deletions test/components/extractFieldsTest.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion test/peliasDocGeneratorsTest.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,9 @@ function test_stream(input, testedStream, callback) {
tape('create', function(test) {
test.test('non-country place_types should be returned as Document with that place_type', function(t) {
var place_types = ['neighbourhood', 'locality', 'borough', 'localadmin',
'county', 'macrocounty', 'region', 'macroregion', 'dependency', 'postalcode'];
'county', 'macrocounty', 'region', 'macroregion',
'dependency', 'postalcode', 'ocean', 'marinearea',
'continent', 'empire'];

place_types.forEach(function(place_type) {
var wofRecords = {
8 changes: 6 additions & 2 deletions test/readStreamTest.js
Original file line number Diff line number Diff line change
@@ -83,7 +83,9 @@ tape('readStream', (test) => {
bounding_box: '-13.691314,49.909613,1.771169,60.847886',
population: 98765,
popularity: 87654,
hierarchies: []
hierarchies: [
{ 'place type 1_id': 123 }
]
},
'456': {
id: 456,
@@ -95,7 +97,9 @@ tape('readStream', (test) => {
bounding_box: '-24.539906,34.815009,69.033946,81.85871',
population: undefined,
popularity: undefined,
hierarchies: []
hierarchies: [
{ 'place type 2_id': 456 }
]
}
});