Skip to content

Commit

Permalink
feat(resources): Add custom resources directory which is git ignored (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Joxit authored and missinglink committed May 22, 2019
1 parent 5872f3d commit 8c2d180
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ resources/whosonfirst/dictionaries/*/*.txt
!resources/whosonfirst/dictionaries/locality/name:eng_x_preferred.txt
!resources/whosonfirst/dictionaries/locality/name:fra_x_preferred.txt

# ignore all custom dictionaries
resources/custom/dictionaries

# ignore any openaddresses test cases
test/oa
20 changes: 20 additions & 0 deletions resources/custom/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs')
const path = require('path')
const dictPath = path.join(__dirname, `./dictionaries`)

function load (filename, add, remove) {
let filepath = path.join(dictPath, filename)
if (!fs.existsSync(filepath)) { return }
let dict = fs.readFileSync(filepath, 'utf8')
dict.split('\n').forEach(row => {
if (row.trim().startsWith('#')) {
// Do nothing, this is a comment
} else if (row.startsWith('!')) {
row.substring(1).split('|').forEach(remove)
} else {
row.split('|').forEach(add)
}
})
}

module.exports.load = load
5 changes: 5 additions & 0 deletions resources/libpostal/libpostal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs')
const path = require('path')
const pelias = require('../pelias/pelias')
const custom = require('../custom/custom')
const dictPath = path.join(__dirname, `./dictionaries`)
const allLanguages = fs.readdirSync(dictPath).filter(p => !p.includes('.'))

Expand All @@ -20,6 +21,10 @@ function load (index, langs, filename, options) {
langs.forEach(lang => {
pelias.load(path.join('libpostal', lang, filename), add, remove)
})

langs.forEach(lang => {
custom.load(path.join('libpostal', lang, filename), add, remove)
})
}

function _normalize (cell, options) {
Expand Down
7 changes: 7 additions & 0 deletions resources/whosonfirst/whosonfirst.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs')
const path = require('path')
const pelias = require('../pelias/pelias')
const custom = require('../custom/custom')
const dictPath = path.join(__dirname, `./dictionaries`)
const allPlacetypes = fs.readdirSync(dictPath).filter(p => !p.includes('.'))

Expand All @@ -24,6 +25,12 @@ function load (set, placetypes, filenames, options) {
pelias.load(path.join('whosonfirst', placetype, filename), add, remove)
})
})

placetypes.forEach(placetype => {
filenames.forEach(filename => {
custom.load(path.join('whosonfirst', placetype, filename), add, remove)
})
})
}

function _normalize (cell, options) {
Expand Down

0 comments on commit 8c2d180

Please sign in to comment.