Skip to content

Commit

Permalink
feat(abbreviations): use wof:abbreviation for dependencies if available
Browse files Browse the repository at this point in the history
This is a backwards-compatible version of #273
which allows us to handle the upcoming switch from storing dependency
abbreviations in the `wof:country` field to `wof:abbreviation` (see
whosonfirst-data/whosonfirst-data#823)

It should be safe to merge now and will do the right thing once WOF data
is updated.

Supersedes #273
  • Loading branch information
dianashk authored and orangejulius committed Aug 5, 2018
1 parent 7e98cec commit 18a084d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/components/extractFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ function getName(properties) {
}
}

function isDependencyOrCountry(placetype) {
return placetype === 'dependency' || placetype === 'country';
}

function getAbbreviation(properties) {
if (isDependencyOrCountry(properties['wof:placetype']) && properties['wof:country']) {
if (properties['wof:placetype'] === 'country' && properties['wof:country']) {
return properties['wof:country'];
}

// TODO: remove this section once WOF no-longer puts dependency abbreviations in `wof:country`
if (properties['wof:placetype'] === 'dependency') {
return properties['wof:abbreviation'] || properties['wof:country'];
}

return properties['wof:abbreviation'];
}

Expand Down
45 changes: 41 additions & 4 deletions test/components/extractFieldsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ tape('readStreamComponents', function(test) {

});

test.test('wof:placetype=dependency should use wof:country value for abbreviation', function(t) {
test.test('wof:placetype=dependency should use wof:abbreviation value for abbreviation if present', function(t) {
var input = [
{
id: 12345,
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'dependency',
'wof:country': 'XY',
'wof:abbreviation': 'YZ'
'wof:country': 'value from wof:country',
'wof:abbreviation': 'value from wof:abbreviation'
}
}
];
Expand All @@ -556,7 +556,44 @@ tape('readStreamComponents', function(test) {
population: undefined,
popularity: undefined,
bounding_box: undefined,
abbreviation: 'XY',
abbreviation: 'value from wof:abbreviation',
hierarchies: [
{
'dependency_id': 12345
}
]
}
];

test_stream(input, extractFields.create(), function(err, actual) {
t.deepEqual(actual, expected, 'wof:country is used for abbreviation');
t.end();
});
});

test.test('wof:placetype=dependency should use wof:country value for abbreviation if wof:abbreviation not present', function(t) {
var input = [
{
id: 12345,
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'dependency',
'wof:country': 'value from wof:country',
}
}
];

var expected = [
{
id: 12345,
name: 'wof:name value',
place_type: 'dependency',
lat: undefined,
lon: undefined,
population: undefined,
popularity: undefined,
bounding_box: undefined,
abbreviation: 'value from wof:country',
hierarchies: [
{
'dependency_id': 12345
Expand Down

0 comments on commit 18a084d

Please sign in to comment.