Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(localNames): prefer local names in lookup #318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Who's On First Admin Lookup module recognizes the following top-level properties
{
"imports": {
"adminLookup": {
"enabled": true
"enabled": true,
"localizedAdminNames": false
},
"whosonfirst": {
"datapath": "/path/to/wof-data"
Expand Down Expand Up @@ -88,7 +89,7 @@ This is particularly helpful in places where the locality name returned by the p

#### Contributing

The mapping files are open-data, you can find more infomation about [how the data files are generated here](https://github.com/pelias/lastline).
The mapping files are open-data, you can find more information about [how the data files are generated here](https://github.com/pelias/lastline).

In the `src/data` directory of this repository you'll find the TSV (tab separated) files named after the corresponding 3-character country code (eg. `AUS.tsv`).

Expand Down Expand Up @@ -120,6 +121,8 @@ The `weight` field is used to determine which entry is the most important, this

To enable the postal cities functionality, set `imports.adminLookup.usePostalCities` to `true` in your `pelias.json` file.

To enable localized administration names, set the `imports.adminLookup.localizedAdminNames` to `true` in your `pelias.json` file.

#### Advanced Configuration

It's possible to use your own mapping files by setting `imports.adminLookup.postalCitiesDataPath` to point to a directory of your choice, if the corresponding TSV file is found in your path it will be used in place of the bundled data files. [more information](https://github.com/pelias/wof-admin-lookup/pull/296).
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function resolver(layers) {

function localResolver(layers) {
const datapath = peliasConfig.imports.whosonfirst.datapath;
return require('./src/localPipResolver')(datapath, layers);
const localizedAdminNames = peliasConfig.imports.adminLookup.localizedAdminNames;
return require('./src/localPipResolver')(datapath, layers, localizedAdminNames);
}

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = Joi.object().keys({
missingMetafilesAreFatal: Joi.boolean().default(false),
usePostalCities: Joi.boolean().default(false),
postalCitiesDataPath: Joi.string(),
useEndonyms: Joi.boolean().default(false)
useEndonyms: Joi.boolean().default(false),
localizedAdminNames: Joi.boolean().default(false),
}).unknown(true),
whosonfirst: Joi.object().keys({
datapath: Joi.string().required(),
Expand Down
17 changes: 10 additions & 7 deletions src/localPipResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const _ = require('lodash');
/**
* LocalPIPService class
*
* @param {object} [pipService] optional, primarily used for testing
* @param {string} datapath
* @param {Array} [layers]
* @param {boolean} [localizedAdminNames]
* @constructor
*/
function LocalPipService(datapath, layers) {
function LocalPipService(datapath, layers, localizedAdminNames) {
const self = this;

createPipService(datapath, _.defaultTo(layers, []), false, (err, service) => {
createPipService(datapath, _.defaultTo(layers, []), localizedAdminNames, (err, service) => {
if (err) {
throw err;
}
Expand Down Expand Up @@ -91,10 +93,11 @@ LocalPipService.prototype.end = function end() {
/**
* Factory function
*
* @param {object} [service]
* @param {string} [datapath]
* @param {string} datapath
* @param {Array} [layers]
* @param {boolean} [localizedAdminNames]
* @returns {LocalPIPService}
*/
module.exports = (datapath, layers) => {
return new LocalPipService(datapath, layers);
module.exports = (datapath, layers, localizedAdminNames) => {
return new LocalPipService(datapath, layers, localizedAdminNames);
};
2 changes: 1 addition & 1 deletion src/pip/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const path = require('path');

const layer = process.title = process.argv[2];
const datapath = process.argv[3];
const localizedAdminNames = process.argv[4];
const localizedAdminNames = process.argv[4] == "true";
const startTime = Date.now();

const results = {
Expand Down