Skip to content

Commit

Permalink
Merge pull request #36 from pelias/osm_mandarin_labels
Browse files Browse the repository at this point in the history
analyze: remove common mandarin labels
  • Loading branch information
missinglink authored Dec 5, 2016
2 parents 5759839 + 89ef34a commit fa5e8ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ function housenumber( num ){
.replace(' 1/2', '½')
.replace(' 3/4', '¾');

// remove common labels
// remove common english labels
number = number.replace(/\s+(apartment|apt|lot|space|ste|suite|unit)\s+/gi, '');

// remove common mandarin labels
// see: https://eastasiastudent.net/china/mandarin/postal-address/
number = number.replace(/(||||)/g, '');

// remove spaces from housenumber. eg: '2 A' -> '2A'
number = number.replace(/\s+/g, '').toLowerCase();

Expand Down
11 changes: 8 additions & 3 deletions test/lib/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ module.exports.analyze.housenumber = function(test) {
t.false(isNaN(analyze.housenumber('326 1/2')), 'half suffix');
t.false(isNaN(analyze.housenumber('8¼')), 'quarter suffix');
t.false(isNaN(analyze.housenumber('4701 #B')), 'hash delimited suffix');
t.false(isNaN(analyze.housenumber('1434 UNIT #B')), 'remove common label "unit"');
t.false(isNaN(analyze.housenumber('1434 SUITE #B')), 'remove common label "suite"');
t.false(isNaN(analyze.housenumber('1434 UNIT #B')), 'remove common english label "unit"');
t.false(isNaN(analyze.housenumber('1434 SUITE #B')), 'remove common english label "suite"');
t.false(isNaN(analyze.housenumber('158號')), 'remove common mandarin label');
t.end();
});

Expand Down Expand Up @@ -161,13 +162,17 @@ module.exports.analyze.housenumber = function(test) {
// t.equal(float, 5285.03);
// t.end();
// });
test('housenumber: removes common labels', function(t) {
test('housenumber: removes common english labels', function(t) {
var float = analyze.housenumber('4701 UNIT #B');
t.equal(float, 4701.06);
var float2 = analyze.housenumber('1 APT A');
t.equal(float2, 1.03);
t.end();
});
test('housenumber: removes common mandarin labels', function(t) {
t.equal(analyze.housenumber('158號'), 158.00);
t.end();
});
};
module.exports.analyze.housenumberFloatToString = function(test) {
test('housenumberFloatToString: invalid', function(t) {
Expand Down

0 comments on commit fa5e8ac

Please sign in to comment.