Browse Source

feat(libpostal_patch): correctly parse australian-style unit numbers

pull/1216/head
Peter Johnson 6 years ago
parent
commit
69ddbaf3be
  1. 13
      controller/libpostal.js
  2. 126
      test/unit/controller/libpostal.js

13
controller/libpostal.js

@ -157,6 +157,19 @@ function patchBuggyResponses(response){
} }
} }
// known bug where Australian unit numbers are incorrectly included in the house_number label
// note: in the case where a 'unit' label already exists, do nothing.
// https://github.com/pelias/pelias/issues/753
let unit = _.get(idx, 'unit');
let house_number = _.get(idx, 'house_number');
if( _.isPlainObject(house_number) && !_.isPlainObject(unit) && _.isString(house_number.value) ){
let split = _.trim(_.trim(house_number.value),'/').split('/');
if( split.length === 2 ){
response[house_number._pos].value = split[1]; // second part (house number)
response.push({ label: 'unit', value: split[0] }); // first part (unit number)
}
}
return response; return response;
} }

126
test/unit/controller/libpostal.js

@ -359,7 +359,7 @@ module.exports.tests.bug_fixes = (test, common) => {
test('bug fix: recast label for "zoo" from borough/city_district to house', t => { test('bug fix: recast label for "zoo" from borough/city_district to house', t => {
const service = (req, callback) => { const service = (req, callback) => {
const response =[ const response = [
{ {
'label': 'city_district', 'label': 'city_district',
'value': 'zoo' 'value': 'zoo'
@ -396,6 +396,130 @@ module.exports.tests.bug_fixes = (test, common) => {
}); });
test('bug fix: correctly parse australian-style unit numbers', t => {
const service = (req, callback) => {
const response = [
{
'label': 'house_number',
'value': '11/1015'
},
{
'label': 'road',
'value': 'nudgee road'
},
{
'label': 'suburb',
'value': 'banyo'
},
{
'label': 'postcode',
'value': '4014'
},
{
'label': 'state',
'value': 'qld'
}
];
callback(null, response);
};
const controller = libpostal(service, () => true);
const req = {
clean: {
text: 'original query'
},
errors: []
};
controller(req, undefined, () => {
t.deepEquals(req, {
clean: {
text: 'original query',
parser: 'libpostal',
parsed_text: {
// unit: '11',
number: '1015',
street: 'nudgee road',
neighbourhood: 'banyo',
postalcode: '4014',
state: 'qld'
}
},
errors: []
}, 'req should not have been modified');
t.end();
});
});
test('bug fix: correctly parse australian-style unit numbers - no-op if "unit" already assigned', t => {
const service = (req, callback) => {
const response = [
{
'label': 'unit',
'value': '99'
},
{
'label': 'house_number',
'value': '11/1015'
},
{
'label': 'road',
'value': 'nudgee road'
},
{
'label': 'suburb',
'value': 'banyo'
},
{
'label': 'postcode',
'value': '4014'
},
{
'label': 'state',
'value': 'qld'
}
];
callback(null, response);
};
const controller = libpostal(service, () => true);
const req = {
clean: {
text: 'original query'
},
errors: []
};
controller(req, undefined, () => {
t.deepEquals(req, {
clean: {
text: 'original query',
parser: 'libpostal',
parsed_text: {
// unit: '999',
number: '11/1015',
street: 'nudgee road',
neighbourhood: 'banyo',
postalcode: '4014',
state: 'qld'
}
},
errors: []
}, 'req should not have been modified');
t.end();
});
});
}; };
module.exports.all = (tape, common) => { module.exports.all = (tape, common) => {

Loading…
Cancel
Save