Skip to content

Commit

Permalink
fix(CentralEuropeanStreetNameClassifier): avoid use of section.end (#103
Browse files Browse the repository at this point in the history
)
  • Loading branch information
missinglink authored Jun 3, 2020
1 parent 6afdd7b commit c0dc786
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion classifier/CentralEuropeanStreetNameClassifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class CentralEuropeanStreetNameClassifier extends SectionClassifier {
let next = first.graph.findOne('next')

// section must end with a HouseNumberClassification
if (!next || next.end !== section.end || !next.classifications.hasOwnProperty('HouseNumberClassification')) { return }
if (!next) { return } // no next span found
if (next.graph.findOne('next')) { return } // next span is NOT the final span in the section
if (!next.classifications.hasOwnProperty('HouseNumberClassification')) { return }

// other elements cannot contain any public classifications
if (_.some(first.classifications, (c) => c.public)) { return }
Expand Down
13 changes: 10 additions & 3 deletions classifier/CentralEuropeanStreetNameClassifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,31 @@ module.exports.tests.classify = (test) => {
baz.graph.add('next', bazHouseNum1)
bazHouseNum1.graph.add('next', bazHouseNum2)

// The Qux test case covers when the section has a greater length than
// the tokens it contains, such as when it ends with whitespace.
let qux = new Span('Qux')
let quxHouseNum = new Span('1', 4).classify(new HouseNumberClassification(1.0))
qux.graph.add('next', quxHouseNum)

let valid = [
new Span('Foo 1').setChildren([foo, fooHouseNum]),
new Span('Bar 2137').setChildren([bar, barHouseNum]),
new Span('Baz 152/160').setChildren([baz, bazHouseNum0, bazHouseNum1, bazHouseNum2])
new Span('Baz 152/160').setChildren([baz, bazHouseNum0, bazHouseNum1, bazHouseNum2]),
new Span('Qux 1 ').setChildren([qux, quxHouseNum])
]

valid.forEach(s => {
test(`classify: ${s.body}`, (t) => {
// run classifier
classifier.each(s, null, 1)
classifier.each(s)

// 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)
})
}, `'${s.body}'`)

// last child was unchanged
_.tail(children).forEach(c => {
Expand Down

0 comments on commit c0dc786

Please sign in to comment.