Skip to content

Commit

Permalink
feat(norway): classifying more addresses for norway (#171)
Browse files Browse the repository at this point in the history
* Activating the DirectionalClassifier and CompoundStreetClassifier for norway,
adding additional street_types and directionals for norway.

* Removing street types lien and land as it crashes with other countries addresses.

* Moving the custom tokens in separate file and adding unit tests.

---------

Co-authored-by: mansoor.sajjad <[email protected]>
  • Loading branch information
mansoor-sajjad and mansoor.sajjad authored Jan 30, 2023
1 parent 674a3ed commit ff961cc
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 3 deletions.
4 changes: 2 additions & 2 deletions classifier/CompoundStreetClassifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class CompoundStreetClassifier extends WordClassifier {
// load street suffixes
this.suffixes = {}

libpostal.load(this.suffixes, ['de', 'nl', 'sv'], 'concatenated_suffixes_separable.txt', {
libpostal.load(this.suffixes, ['de', 'nl', 'sv', 'nb'], 'concatenated_suffixes_separable.txt', {
// remove any suffixes which contain less than 3 characters (excluding a period)
// this removes suffixes such as 'r.' which can be ambiguous
minlength: 3
})

libpostal.load(this.suffixes, ['de', 'nl'], 'concatenated_suffixes_inseparable.txt', {
libpostal.load(this.suffixes, ['de', 'nl', 'nb'], 'concatenated_suffixes_inseparable.txt', {
// remove any suffixes which contain less than 3 characters (excluding a period)
// this removes suffixes such as 'r.' which can be ambiguous
minlength: 3
Expand Down
2 changes: 1 addition & 1 deletion classifier/DirectionalClassifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const libpostal = require('../resources/libpostal/libpostal')

// optionally control which languages are included
// note: reducing the languages will have a considerable performance benefit
const languages = ['en', 'es', 'de', 'fr', 'nl']
const languages = ['en', 'es', 'de', 'fr', 'nl', 'nb']

class DirectionalClassifier extends WordClassifier {
setup () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plass|pl.|p.
haugen
skogen|skog
gården|gård
åsen
haugen
skogen|skog
gården|gård
åsen
gård|gården
holm|holmen
haugen|Haugane
krysset
skogen|skog
grend|grenda
flat|flaten
våg|vågen
strand|stranda|stranden
vik|vika
platå
stad
terrasse
hage|hagen
øya
lund|lunden
holm|holmen
berg|berget
landa|lande|landet
dal|dalen
sund
bakke|bakken
høgda|høgde
borg|borgen
gard|garden|garda
mark|marka
voll|vollen
sjø|sjøen
lie
sti|stien
tangen
8 changes: 8 additions & 0 deletions resources/pelias/dictionaries/libpostal/nb/directionals.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
øvre|ovre
øvste|ovste
nedre
midtre
ytre
indre
sør|sor|s
sørre|sorre
36 changes: 36 additions & 0 deletions resources/pelias/dictionaries/libpostal/nb/street_types.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plass
haugen
skogen|skog
gården|gård
åsen
gård|gården
holm|holmen
haugen|Haugane
krysset
skogen|skog
grend|grenda
flat|flaten
våg|vågen
strand|stranda|stranden
vik|vika
platå
stad
terrasse
hage|hagen|hager
øya
lund|lunden
holm|holmen
berg|berget
landa|lande|landet
dal|dalen
sund
bakke|bakken
høgda|høgde
borg|borgen
gard|garden|garda
mark|marka
voll|vollen
sjø|sjøen
lie
sti|stien
tangen
47 changes: 47 additions & 0 deletions test/address.nor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const testcase = (test, common) => {
let assert = common.assert(test)

assert('Skredderplassen 20', [
{ street: 'Skredderplassen' }, { housenumber: '20' }
])

assert('Henrik Walters plass 3', [
{ street: 'Henrik Walters plass' }, { housenumber: '3' }
])

assert('Vestre Haugen 74', [
{ street: 'Vestre Haugen' }, { housenumber: '74' }
])

assert('Maria Dehlis vei 15', [
{ street: 'Maria Dehlis vei' }, { housenumber: '15' }
])

assert('Gamle Drammensvei 163', [
{ street: 'Gamle Drammensvei' }, { housenumber: '163' }
])

assert('Grense Jakobselv veien 311', [
{ street: 'Grense Jakobselv veien' }, { housenumber: '311' }
])

assert('Epleskogen 39A', [
{ street: 'Epleskogen' }, { housenumber: '39A' }
])

assert('Øvste Skogen 121', [
{ street: 'Øvste Skogen' }, { housenumber: '121' }
])

assert('Tindvegen nedre 44B', [
{ street: 'Tindvegen nedre' }, { housenumber: '44B' }
])
}

module.exports.all = (tape, common) => {
function test (name, testFunction) {
return tape(`address AUS: ${name}`, testFunction)
}

testcase(test, common)
}

0 comments on commit ff961cc

Please sign in to comment.