Skip to content

Commit

Permalink
feat(tag_mapper): contract english diagonals for street addresses (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink authored Aug 20, 2021
1 parent d952ea4 commit b8d588c
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 73 deletions.
20 changes: 19 additions & 1 deletion stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ module.exports = function(){
else if( _.has(ADDRESS_SCHEMA, key) ){
var val3 = trim( value );
if( val3 ){
doc.setAddress( ADDRESS_SCHEMA[key], val3 );
let label = ADDRESS_SCHEMA[key];
doc.setAddress(label, normalizeAddressField(label, val3));
}
}
});
Expand Down Expand Up @@ -149,3 +150,20 @@ function getNameSuffix( tag ){

return suffix;
}

// apply some very basic normalization
// note: in the future we should consider doing something more advanced like:
// https://github.com/pelias/openaddresses/pull/477
function normalizeAddressField(key, value) {
if (key === 'street') {

// contract English diagonals
value = value
.replace(/\b(northwest)\b/i, 'NW')
.replace(/\b(northeast)\b/i, 'NE')
.replace(/\b(southwest)\b/i, 'SW')
.replace(/\b(southeast)\b/i, 'SE');
}

return value;
}
Loading

0 comments on commit b8d588c

Please sign in to comment.