-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(central_european_streets): add new CentralEuropeanStreetNameClas…
…sifier
- Loading branch information
1 parent
ca23c2e
commit 66484d8
Showing
7 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const _ = require('lodash') | ||
const SectionClassifier = require('./super/SectionClassifier') | ||
const StreetClassification = require('../classification/StreetClassification') | ||
|
||
/** | ||
* Classifier which attempts to classify street names with no suffix or prefix | ||
* when accompanied by a housenumber in the same section. | ||
* | ||
* see: https://github.com/pelias/parser/issues/83 | ||
*/ | ||
|
||
class CentralEuropeanStreetNameClassifier extends SectionClassifier { | ||
each (section) { | ||
// there must be excactly two childen in this section | ||
// note: we may wish to relax/expand on this later | ||
if (section.graph.length('child') !== 2) { return } | ||
|
||
// get first and last child | ||
let children = section.graph.findAll('child') | ||
let first = _.first(children) | ||
let last = _.last(children) | ||
|
||
// section must end with a HouseNumberClassification | ||
if (!last.classifications.hasOwnProperty('HouseNumberClassification')) { return } | ||
|
||
// other elements cannot contain any public classifications | ||
if (_.some(first.classifications, (c) => c.public)) { return } | ||
|
||
// assume the first token is a street name | ||
first.classify(new StreetClassification(0.5)) | ||
} | ||
} | ||
|
||
module.exports = CentralEuropeanStreetNameClassifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const _ = require('lodash') | ||
const CentralEuropeanStreetNameClassifier = require('./CentralEuropeanStreetNameClassifier') | ||
const HouseNumberClassification = require('../classification/HouseNumberClassification') | ||
const StreetClassification = require('../classification/StreetClassification') | ||
const Span = require('../tokenization/Span') | ||
const classifier = new CentralEuropeanStreetNameClassifier() | ||
|
||
module.exports.tests = {} | ||
module.exports.tests.classify = (test) => { | ||
let valid = [ | ||
new Span('Foo 1').setChildren([ | ||
new Span('Foo'), | ||
new Span('1').classify(new HouseNumberClassification(1.0)) | ||
]), | ||
new Span('Bar 2137').setChildren([ | ||
new Span('Bar'), | ||
new Span('2137').classify(new HouseNumberClassification(1.0)) | ||
]) | ||
] | ||
|
||
valid.forEach(s => { | ||
test(`classify: ${s.body}`, (t) => { | ||
// run classifier | ||
classifier.each(s, null, 1) | ||
|
||
// get children | ||
let children = s.graph.findAll('child') | ||
|
||
// first child should now be classified as a street | ||
t.deepEqual(_.first(children).classifications, { | ||
StreetClassification: new StreetClassification(0.5) | ||
}) | ||
|
||
// last child was unchanged | ||
t.deepEqual(_.last(children).classifications, { | ||
HouseNumberClassification: new HouseNumberClassification(1) | ||
}) | ||
|
||
t.end() | ||
}) | ||
}) | ||
} | ||
|
||
module.exports.all = (tape, common) => { | ||
function test (name, testFunction) { | ||
return tape(`CentralEuropeanStreetNameClassifier: ${name}`, testFunction) | ||
} | ||
|
||
for (var testCase in module.exports.tests) { | ||
module.exports.tests[testCase](test, common) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const testcase = (test, common) => { | ||
let assert = common.assert(test) | ||
|
||
assert('Korunní 810, Praha', [ | ||
{ street: 'Korunní' }, { housenumber: '810' }, | ||
{ locality: 'Praha' } | ||
]) | ||
|
||
assert('Kájovská 68, Český Krumlov', [ | ||
{ street: 'Kájovská' }, { housenumber: '68' }, | ||
{ locality: 'Český Krumlov' } | ||
]) | ||
|
||
assert('Beethovenova 641/9, Brno', [ | ||
{ street: 'Beethovenova' }, { housenumber: '641/9' }, | ||
{ locality: 'Brno' } | ||
]) | ||
} | ||
|
||
module.exports.all = (tape, common) => { | ||
function test (name, testFunction) { | ||
return tape(`address CZEs: ${name}`, testFunction) | ||
} | ||
|
||
testcase(test, common) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const testcase = (test, common) => { | ||
let assert = common.assert(test) | ||
|
||
assert('Zadarska 17, Pula', [ | ||
{ street: 'Zadarska' }, { housenumber: '17' }, | ||
{ locality: 'Pula' } | ||
]) | ||
} | ||
|
||
module.exports.all = (tape, common) => { | ||
function test (name, testFunction) { | ||
return tape(`address HRV: ${name}`, testFunction) | ||
} | ||
|
||
testcase(test, common) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const testcase = (test, common) => { | ||
let assert = common.assert(test) | ||
|
||
assert('Szewska 6, Kraków', [ | ||
{ street: 'Szewska' }, { housenumber: '6' }, | ||
{ locality: 'Kraków' } | ||
]) | ||
} | ||
|
||
module.exports.all = (tape, common) => { | ||
function test (name, testFunction) { | ||
return tape(`address POL: ${name}`, testFunction) | ||
} | ||
|
||
testcase(test, common) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const testcase = (test, common) => { | ||
let assert = common.assert(test) | ||
|
||
assert('Divadelná 41/3, Trnava', [ | ||
{ street: 'Divadelná' }, { housenumber: '41/3' }, | ||
{ locality: 'Trnava' } | ||
]) | ||
} | ||
|
||
module.exports.all = (tape, common) => { | ||
function test (name, testFunction) { | ||
return tape(`address SVK: ${name}`, testFunction) | ||
} | ||
|
||
testcase(test, common) | ||
} |