Browse Source

feat(libpostal_patch): refactor code to use lodash methods for key checking

libpostal_aus_unit_numbers
Peter Johnson 6 years ago committed by Peter Johnson
parent
commit
c8d7776587
  1. 13
      controller/libpostal.js

13
controller/libpostal.js

@ -128,13 +128,12 @@ function patchBuggyResponses(response){
// replacements to only records with BOTH a matching 'value' and a matching 'label.from'. // replacements to only records with BOTH a matching 'value' and a matching 'label.from'.
if( response.length === 1 ){ if( response.length === 1 ){
let first = response[0]; let first = response[0];
for( var ii=0; ii<RECAST_LABELS.length; ii++ ){ RECAST_LABELS.forEach(recast => {
let recast = RECAST_LABELS[ii]; if( !_.has(recast, 'label') || !_.has(recast.label, 'to') ){ return; }
if( !recast.hasOwnProperty('label') || !recast.label.hasOwnProperty('to') ){ continue; } if( recast.value !== first.value ){ return; }
if( recast.value !== first.value ){ continue; } if( _.has(recast.label, 'from') && recast.label.from !== first.label ){ return; }
if( recast.label.hasOwnProperty('from') && recast.label.from !== first.label ){ continue; } first.label = recast.label.to;
response[0].label = recast.label.to; });
}
} }
// known bug where the street name is only a directional, in this case we will merge it // known bug where the street name is only a directional, in this case we will merge it

Loading…
Cancel
Save