-
-
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(postcode): apply penalty to postcode solutions in certain patterns
- Loading branch information
1 parent
aedadd2
commit a4ed181
Showing
3 changed files
with
46 additions
and
0 deletions.
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
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,35 @@ | ||
const BaseSolver = require('./super/BaseSolver') | ||
const HouseNumberClassification = require('../classification/HouseNumberClassification') | ||
const PostcodeClassification = require('../classification/PostcodeClassification') | ||
const StreetClassification = require('../classification/StreetClassification') | ||
const basePenalty = 0.1 | ||
|
||
/** | ||
* PostcodePositionPenalty applies a penalty to solutions where the postcode | ||
* may have recieved a high score but doesn't commonly occur in this pattern. | ||
* | ||
* eg. rua godinho de faria 1200 | ||
*/ | ||
|
||
class PostcodePositionPenalty extends BaseSolver { | ||
solve (tokenizer) { | ||
tokenizer.solution.forEach(s => { | ||
// Do nothing if the solution doesn't have a postcode classification | ||
const postcode = s.pair.find(p => p.classification.constructor === PostcodeClassification) | ||
if (!postcode) { return } | ||
|
||
// Do nothing if the solution has a housenumber classification | ||
const housenumber = s.pair.find(p => p.classification.constructor === HouseNumberClassification) | ||
if (housenumber) { return } | ||
|
||
// Do nothing for solutions with either none or 2+ street classifications (intersections) | ||
const streetCount = s.pair.filter(p => p.classification.constructor === StreetClassification).length | ||
if (streetCount === 0 || streetCount >= 2) { return } | ||
|
||
// apply a small penalty | ||
s.penalty += basePenalty | ||
}) | ||
} | ||
} | ||
|
||
module.exports = PostcodePositionPenalty |
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