Skip to content

Commit

Permalink
fix: Merge pull request #157 from pelias/remove-parent-id-hierarchy-s…
Browse files Browse the repository at this point in the history
…upport

Remove parent id hierarchy support
  • Loading branch information
trescube authored Oct 19, 2016
2 parents b42d2f4 + 7e0e59d commit 100dbe2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 164 deletions.
3 changes: 1 addition & 2 deletions import.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ if (peliasConfig.imports.whosonfirst.importVenues) {
var readStream = readStreamModule.create(directory, bundlesToImport, wofAdminRecords);

// how to convert WOF records to Pelias Documents
var documentGenerator = peliasDocGenerators.create(
hierarchyFinder.hierarchies_walker(wofAdminRecords));
var documentGenerator = peliasDocGenerators.create(hierarchyFinder(wofAdminRecords));

// the final destination of Pelias Documents
var dbClientStream = peliasDbclient();
Expand Down
1 change: 0 additions & 1 deletion src/components/extractFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ module.exports.create = function map_fields_stream() {
name: getName(json_object.properties),
abbreviation: json_object.properties['wof:abbreviation'],
place_type: json_object.properties['wof:placetype'],
parent_id: json_object.properties['wof:parent_id'],
lat: getLat(json_object.properties),
lon: getLon(json_object.properties),
bounding_box: getBoundingBox(json_object.properties),
Expand Down
27 changes: 1 addition & 26 deletions src/hierarchyFinder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var _ = require('lodash');

module.exports = {};

var hasName = function(r) {
Expand All @@ -10,29 +8,6 @@ var isDefined = function(r) {
return r;
};

/*
This function builds a hierarchy by starting with the current record and
walking up by parent_id until a parent can't be found, filtering out those
w/o name.
*/
module.exports.parent_id_walker = function(wofRecords) {
return function(wofRecord) {
// collect all the defined parents, starting with the current record
var parent;
var parents = [];
var parent_id = wofRecord.id;

while (!_.isUndefined(parent = wofRecords[parent_id])) {
parents.push(parent);
parent_id = parent.parent_id;
}

return [parents.filter(hasName)];

};

};

/*
This function finds all the WOF records associated with a hierarchy
Expand Down Expand Up @@ -64,7 +39,7 @@ function resolveHierarchy(wofRecords, hierarchy) {
wofRecord can have multiple hierarchies, so resolve them by looking up the
referenced wofRecord in the big collection of wofRecords.
*/
module.exports.hierarchies_walker = function(wofRecords) {
module.exports = function(wofRecords) {
return function(wofRecord) {
return wofRecord.hierarchies.reduce(function(resolvedHierarchies, hierarchy) {
resolvedHierarchies.push(resolveHierarchy(wofRecords, hierarchy));
Expand Down
63 changes: 23 additions & 40 deletions test/components/extractFieldsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
'wof:hierarchy': [
{
'parent_id': 12345
'country_id': 12345
},
{
'parent_id': 23456
'country_id': 23456
}
],
'iso:country': 'YZ',
Expand All @@ -49,10 +48,6 @@ tape('readStreamComponents', function(test) {
ignoreField3: 'ignoreField3',
ignoreField4: 'ignoreField4',
}
},
{
id: 23456,
properties: {}
}
];

Expand All @@ -61,7 +56,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -71,18 +65,35 @@ tape('readStreamComponents', function(test) {
bounding_box: '-13.691314,49.909613,1.771169,60.847886',
hierarchies: [
{
'parent_id': 12345
'country_id': 12345
},
{
'parent_id': 23456
'country_id': 23456
}
]
},
}
];

test_stream(input, extractFields.create(), function(err, actual) {
t.deepEqual(actual, expected, 'stream should contain only objects with id and properties');
t.end();
});

});

test.test('missing fields should return undefined and empty array for hierarchies', function(t) {
var input = [
{
id: 23456,
properties: {}
}
];

var expected = [
{
id: 23456,
name: undefined,
place_type: undefined,
parent_id: undefined,
lat: undefined,
lon: undefined,
iso2: undefined,
Expand All @@ -108,7 +119,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -125,7 +135,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -151,7 +160,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -167,7 +175,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -193,7 +200,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -209,7 +215,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -235,7 +240,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -251,7 +255,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -277,7 +280,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -293,7 +295,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -319,7 +320,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -334,7 +334,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -360,7 +359,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'name 1',
'wof:placetype': 'place type 1',
'wof:parent_id': 'parent id 1',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -375,7 +373,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'name 1',
place_type: 'place type 1',
parent_id: 'parent id 1',
lat: 12.121212,
lon: 21.212121,
iso2: 'YZ',
Expand All @@ -401,7 +398,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'iso:country': 'US',
Expand All @@ -415,7 +411,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'qs:a2_alt value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: 'US',
Expand All @@ -441,7 +436,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'iso:country': 'US'
Expand All @@ -454,7 +448,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'wof:name value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: 'US',
Expand All @@ -480,7 +473,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'iso:country': 'not US',
Expand All @@ -494,7 +486,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'wof:name value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: 'not US',
Expand All @@ -520,7 +511,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'lbl:latitude': 14.141414,
Expand All @@ -536,7 +526,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'wof:name value',
place_type: 'county',
parent_id: 'parent id',
lat: 14.141414,
lon: 23.232323,
iso2: 'not US',
Expand All @@ -561,7 +550,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -576,7 +564,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'wof:name value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: undefined,
Expand All @@ -601,7 +588,6 @@ tape('readStreamComponents', function(test) {
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
Expand All @@ -616,7 +602,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'wof:name value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: undefined,
Expand All @@ -642,7 +627,6 @@ tape('readStreamComponents', function(test) {
'wof:name': 'wof:name value',
'wof:label': 'wof:label value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'lbl:bbox': ''
Expand All @@ -655,7 +639,6 @@ tape('readStreamComponents', function(test) {
id: 12345,
name: 'wof:label value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: undefined,
Expand Down
Loading

0 comments on commit 100dbe2

Please sign in to comment.