Browse Source

Support island input from libpostal

This includes an edge case for Hawaii to handle islands which are mostly
stored as counties in our data currently. See https://github.com/pelias/whosonfirst/issues/94.
county-fallback
Julian Simioni 8 years ago
parent
commit
09c45b5bed
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 18
      query/text_parser.js
  2. 31
      test/unit/query/text_parser.js

18
query/text_parser.js

@ -39,6 +39,12 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){
vs.var( 'input:postcode', parsed_text.postalcode );
}
// island
if( parsed_text.hasOwnProperty('island') ){
vs.var( 'input:island', parsed_text.island );
}
// ==== add parsed matches [admin components] ====
// city
@ -83,6 +89,11 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){
vs.unset( 'input:query' );
}
if (shouldTreatIslandAsCounty(vs)) {
vs.var( 'input:county', vs.var('input:island').toString());
vs.unset('input:island');
}
}
function shouldSetQueryIntoHouseNumber(vs) {
@ -91,4 +102,11 @@ function shouldSetQueryIntoHouseNumber(vs) {
/^[0-9]+$/.test(vs.var('input:query').toString());
}
function shouldTreatIslandAsCounty(vs) {
return vs.isset('input:island') &&
vs.isset('input:region') &&
!vs.isset('input:county') &&
vs.var('input:region').toString() === 'hawaii';
}
module.exports = addParsedVariablesToQueryVariables;

31
test/unit/query/text_parser.js

@ -154,6 +154,37 @@ module.exports.tests.housenumber_special_cases = function(test, common) {
};
module.exports.tests.islands = function(test, common) {
test('island normally left untouched', function(t) {
var parsed_text = {
island: 'an island',
state: 'somewhere'
};
var vs = new VariableStore();
text_parser(parsed_text, vs);
t.equals(vs.var('input:island').toString(), 'an island');
t.equals(vs.var('input:region').toString(), 'somewhere');
t.end();
});
test('islands in hawaii should have island changed to county', function(t) {
var parsed_text = {
island: 'maui',
state: 'hawaii'
};
var vs = new VariableStore();
text_parser(parsed_text, vs);
t.equals(vs.var('input:county').toString(), 'maui');
t.false(vs.isset('input:island'));
t.equals(vs.var('input:region').toString(), 'hawaii');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('text_parser ' + name, testFunction);

Loading…
Cancel
Save