|
1 | 1 | const _ = require('lodash') |
| 2 | +const getDefaultName = require('pelias-whosonfirst').getDefaultName |
2 | 3 |
|
3 | 4 | /** |
4 | 5 | * This file provides some convenience functions for finding the 'generic name' |
5 | 6 | * and 'generic abbreviation' of a WOF document. |
6 | 7 | * |
7 | | - * This should probably be a lot easier than it is, and there seems to be some |
8 | | - * inconsistency within the Pelias codebase about which fields to prefer in |
9 | | - * certain cases. |
| 8 | + * getName() used to have its own hand-ported copy of wof-admin-lookup's old |
| 9 | + * name-selection logic (see git history), maintained as "a best-effort attempt |
| 10 | + * to honour the field mappings... used [in] pelias/wof-admin-lookup" - which, |
| 11 | + * being a manual port, had drifted out of sync and was missing the longname/ |
| 12 | + * qualifier-preferred-allowlist logic wof-admin-lookup and placeholder now |
| 13 | + * share. It now delegates to that same shared implementation directly instead |
| 14 | + * of maintaining a fourth independent copy. |
10 | 15 | * |
11 | | - * I've made a best-effort attempt to honour the field mappings which are (at time of writing) |
12 | | - * being used the pelias/wof-admin-lookup module. |
13 | | - * The idea is that this repo can be used as a drop-in replacement for wof-admin-lookup. |
14 | | - * |
15 | | - * Prior work: |
16 | | - * [N1] https://github.com/pelias/wof-admin-lookup/blob/e7ea48af6eb5b2b88886dd4b4f71a81e6e38696a/src/pip/components/getDefaultName.js |
17 | | - * [A1] https://github.com/pelias/wof-admin-lookup/blob/d9abfe32ed40184bd657df463e2faeb6ff2f7326/src/pip/components/extractFields.js#L44-L51 |
18 | | - * [A2] https://github.com/pelias/whosonfirst/blob/fee549816a8a29fc5c3daccc66129677f8d552d6/src/components/extractFields.js#L154 |
| 16 | + * NOTE: while pelias-whosonfirst's getDefaultName support is still in progress, |
| 17 | + * this package is resolved via `npm link` to a local checkout rather than a |
| 18 | + * published npm version. Once pelias-whosonfirst publishes a release with |
| 19 | + * getDefaultName, bump the version constraint in package.json and remove the link. |
19 | 20 | */ |
20 | 21 |
|
21 | 22 | // convenience function to find a generic name for the place |
22 | 23 | function getName (properties) { |
23 | | - const placeType = _.get(properties, 'wof:placetype') |
24 | | - const ISOcountry = _.get(properties, 'iso:country') |
25 | | - const quattroAlt = _.get(properties, 'qs:a2_alt') |
26 | | - const label = _.get(properties, 'wof:label') |
27 | | - const name = _.get(properties, 'wof:name') |
28 | | - |
29 | | - // this US-county specific logic was ported from [A1] |
30 | | - if (ISOcountry === 'US' && placeType === 'county' && quattroAlt) { |
31 | | - return quattroAlt.trim() |
32 | | - } |
33 | | - |
34 | | - // use label |
35 | | - if (label) { return label.trim() } |
36 | | - |
37 | | - // use name |
38 | | - if (name) { return name.trim() } |
| 24 | + const name = getDefaultName(properties) |
| 25 | + return typeof name === 'string' ? name.trim() : name |
39 | 26 | } |
40 | 27 |
|
41 | 28 | // convenience function to find a generic abbreviation for the place |
|
0 commit comments