Skip to content

Commit

Permalink
feat(FillSolver): Add FillSolver, it will add unclassified tokens to …
Browse files Browse the repository at this point in the history
…the street

This will be used only when StreetPrefixClassification is used.

Remove Paris from regions and add cité in street_types.
Paris is always used as a locality
  • Loading branch information
Joxit committed Jul 8, 2019
1 parent cd87ea4 commit f7c155f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
18 changes: 18 additions & 0 deletions classifier/scheme/street_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ module.exports = [
}
]
},
{
// du 4 septembre
confidence: 0.5,
Class: StreetNameClassification,
scheme: [
{
is: ['StopWordClassification']
},
{
is: ['NumericClassification'],
not: ['PostcodeClassification']
},
{
is: ['AlphaClassification'],
not: ['StreetClassification', 'IntersectionClassification', 'LocalityClassification']
}
]
},
{
// dos Fiéis de Deus
confidence: 0.5,
Expand Down
4 changes: 3 additions & 1 deletion parser/AddressParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const TokenDistanceFilter = require('../solver/TokenDistanceFilter')
const MustNotPreceedFilter = require('../solver/MustNotPreceedFilter')
const MustNotFollowFilter = require('../solver/MustNotFollowFilter')
const SubsetFilter = require('../solver/SubsetFilter')
const FillSolver = require('../solver/FillSolver')

class AddressParser extends Parser {
constructor (options) {
Expand Down Expand Up @@ -108,7 +109,8 @@ class AddressParser extends Parser {
new MustNotFollowFilter('LocalityClassification', 'RegionClassification'),
new MustNotFollowFilter('LocalityClassification', 'CountryClassification'),
new TokenDistanceFilter(),
new SubsetFilter()
new SubsetFilter(),
new FillSolver()
],
options
)
Expand Down
23 changes: 23 additions & 0 deletions solver/FillSolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class FillSolver {
solve (tokenizer) {
tokenizer.solution.forEach(solution => {
// Get streets from this solution
const streets = solution.pair.filter(p => p.classification.constructor.name === 'StreetClassification')
// Get all nodes that are not in the solution
const missings = tokenizer.section[0].graph.edges.child.filter(c => !solution.pair.some(p => p.span.intersects(c)))

missings.forEach(missing => {
const street = streets.find(s => s.span.end === missing.start - 1)
const prefix = street && street.span.graph.findOne('child:first')
if (prefix && prefix.classifications.StreetPrefixClassification) {
street.span.setBody(`${street.span.body} ${missing.body}`)
street.span.graph.add('child', missing)
street.span.graph.remove('child:last', street.span.graph.findOne('child:last'))
street.span.graph.add('child:last', missing)
}
})
})
}
}

module.exports = FillSolver
8 changes: 8 additions & 0 deletions test/address.fra.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ const testcase = (test, common) => {
assert(`Rue de l'Adjudant Réau Paris`, [
{ street: `Rue de l'Adjudant Réau` }, { locality: 'Paris' }
])

assert('16 Rue Des Petits Carreaux', [
{ housenumber: '16' }, { street: 'Rue Des Petits Carreaux' }
])

assert('16 Rue Des Petits Carreaux Paris', [
{ housenumber: '16' }, { street: 'Rue Des Petits Carreaux' }, { locality: 'Paris' }
])
}

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

0 comments on commit f7c155f

Please sign in to comment.