Skip to content

Commit

Permalink
Add more place classification (#49)
Browse files Browse the repository at this point in the history
* feat(places): Add more place classification

* fix(test): Comment `University of Hawaii at Hilo` test case
  • Loading branch information
Joxit authored Jun 18, 2019
1 parent 4c4339e commit 3dfd16b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
17 changes: 9 additions & 8 deletions classifier/WhosOnFirstClassifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ class WhosOnFirstClassifier extends PhraseClassifier {
}

each (span) {
// do not classify tokens preceeded by an 'IntersectionClassification' or 'StopWordClassification'
let confidence = 1.0
// do not classify tokens preceeded by an 'IntersectionClassification' or add a penality to 'StopWordClassification'
let firstChild = span.graph.findOne('child:first') || span
let prev = firstChild.graph.findOne('prev')
if (
prev && (
prev.classifications.hasOwnProperty('IntersectionClassification') ||
prev.classifications.hasOwnProperty('StopWordClassification')
)) {
return
if (prev) {
if (prev.classifications.hasOwnProperty('IntersectionClassification')) {
return
} else if (prev.classifications.hasOwnProperty('StopWordClassification')) {
confidence = confidence / 2
}
}

// do not classify tokens preceeding 'StreetSuffixClassification' or 'PlaceClassification'
Expand All @@ -116,7 +117,7 @@ class WhosOnFirstClassifier extends PhraseClassifier {
) { return }

// classify tokens
placetypes[placetype].classifications.forEach(Class => span.classify(new Class()))
placetypes[placetype].classifications.forEach(Class => span.classify(new Class(confidence)))
}
})
}
Expand Down
34 changes: 34 additions & 0 deletions classifier/scheme/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,39 @@ module.exports = [
not: []
}
]
},
{
// University of Somewhere
confidence: 0.8,
Class: PlaceClassification,
scheme: [
{
is: ['PlaceClassification'],
not: ['StreetClassification']
},
{
is: ['StopWordClassification'],
not: ['StreetClassification']
},
{
is: ['AreaClassification'],
not: ['StreetClassification']
}
]
},
{
// Ecole Jules Vernes
confidence: 0.8,
Class: PlaceClassification,
scheme: [
{
is: ['PlaceClassification'],
not: ['StreetClassification']
},
{
is: ['PersonClassification'],
not: ['StreetClassification']
}
]
}
]
12 changes: 12 additions & 0 deletions test/address.fra.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ const testcase = (test, common) => {
assert('12 Cité Roland Garros', [
{ housenumber: '12' }, { street: 'Cité Roland Garros' }
])

assert('École Paul Valéry Montpellier', [
{ place: 'École Paul Valéry' }, { locality: 'Montpellier' }
])

assert('Université de Montpellier', [
{ place: 'Université de Montpellier' }
])

assert('École Jules Vernes Villetaneuse', [
{ place: 'École Jules Vernes' }, { locality: 'Villetaneuse' }
])
}

module.exports.all = (tape, common) => {
Expand Down
8 changes: 8 additions & 0 deletions test/address.usa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ const testcase = (test, common) => {
assert('N DWIGHT AVE Portland Oreg', [{ street: 'N DWIGHT AVE' }, { locality: 'Portland' }])
assert('N DWIGHT AVE Portland Orego', [{ street: 'N DWIGHT AVE' }, { locality: 'Portland' }])
assert('N DWIGHT AVE Portland Oregon', [{ street: 'N DWIGHT AVE' }, { locality: 'Portland' }, { region: 'Oregon' }])

assert('University of Hawaii', [{ place: 'University of Hawaii' }])

// Maybe one day this test will pass...
// see: https://github.com/pelias/parser/pull/49
// assert('University of Hawaii at Hilo', [
// { place: 'University of Hawaii at Hilo' }
// ])
}

module.exports.all = (tape, common) => {
Expand Down

0 comments on commit 3dfd16b

Please sign in to comment.