@whiteslove/parsing-lexicon 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/central-asia-locations.js +16 -4
- package/src/kg-map-data-location-extensions.js +3 -0
- package/src/kz-map-data-location-extensions.js +3 -0
- package/src/location-merge.js +42 -2
- package/src/locations-runtime.js +24 -4
- package/src/locations.js +73 -3
- package/src/ro-map-data-location-extensions.js +3 -0
- package/src/ua-map-data-location-extensions.js +3 -0
- package/src/uz-map-data-location-extensions.js +1 -74375
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LOCATION_DICTIONARIES } from './locations-runtime.js';
|
|
2
|
-
import { LOCATION_LIST_KEYS } from './location-merge.js';
|
|
2
|
+
import { isMapDataEntry, LOCATION_LIST_KEYS } from './location-merge.js';
|
|
3
3
|
import { CITIES_BY_COUNTRY, canonicalCity } from './geography.js';
|
|
4
4
|
import { aliasesOf, aliasesToRegex, normalizeForMatch } from './normalization.js';
|
|
5
5
|
import { KZ_AMBIGUOUS_LOCAL_NAMES, KZ_SEARCH_CLUSTERS } from './kz-location-extensions.js';
|
|
@@ -227,12 +227,24 @@ function publicMatch(candidate) {
|
|
|
227
227
|
return Object.freeze(result);
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
function
|
|
230
|
+
function mapDataMatch(value, normalizedValue, item) {
|
|
231
|
+
const paddedValue = ` ${normalizedValue} `;
|
|
232
|
+
for (const alias of item.aliases || []) {
|
|
233
|
+
const normalizedAlias = normalizeForMatch(alias);
|
|
234
|
+
const index = paddedValue.indexOf(` ${normalizedAlias} `);
|
|
235
|
+
if (normalizedAlias && index >= 0) return { 0: normalizedAlias, index };
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function findEntryMatches(text, cityName, data, { includeMapData = false } = {}) {
|
|
231
241
|
const value = String(text || '');
|
|
242
|
+
const normalizedValue = normalizeForMatch(value);
|
|
232
243
|
const raw = [];
|
|
233
244
|
for (const key of LOCATION_LIST_KEYS) {
|
|
234
245
|
for (const item of data?.[key] || []) {
|
|
235
|
-
|
|
246
|
+
if (isMapDataEntry(item) && !includeMapData) continue;
|
|
247
|
+
const match = (isMapDataEntry(item) ? mapDataMatch(value, normalizedValue, item) : value.match(item?.re))
|
|
236
248
|
|| (key === 'residentialComplexes' ? markedResidentialMatch(value, item) : null);
|
|
237
249
|
if (!match) continue;
|
|
238
250
|
const { start, end } = semanticBounds(value, match);
|
|
@@ -319,7 +331,7 @@ export function matchCentralAsiaLocationEntities(text, countryCode, preferredCit
|
|
|
319
331
|
const scopedCity = preferred && country[preferred] ? preferred : explicit && country[explicit] ? explicit : null;
|
|
320
332
|
|
|
321
333
|
if (scopedCity) {
|
|
322
|
-
const matches = findEntryMatches(text, scopedCity, country[scopedCity]);
|
|
334
|
+
const matches = findEntryMatches(text, scopedCity, country[scopedCity], { includeMapData: true });
|
|
323
335
|
const clusters = clusterMatches(matches, countryCode);
|
|
324
336
|
return Object.freeze({ city: scopedCity, matches: Object.freeze(matches), searchClusters: Object.freeze(clusters), candidates: Object.freeze([]) });
|
|
325
337
|
}
|