@whiteslove/parsing-lexicon 0.5.8 → 0.5.9
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whiteslove/parsing-lexicon",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"description": "Shared deterministic multilingual parsing lexicon for WhitesLove housing and hiring services",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"./central-asia": "./src/central-asia.js",
|
|
39
39
|
"./ukraine": "./src/ukraine.js",
|
|
40
40
|
"./location-merge": "./src/location-merge.js",
|
|
41
|
-
"./locations": "./src/locations.js",
|
|
41
|
+
"./locations": "./src/locations-runtime.js",
|
|
42
|
+
"./kg-location-extensions": "./src/kg-location-extensions.js",
|
|
42
43
|
"./kz-location-extensions": "./src/kz-location-extensions.js",
|
|
43
44
|
"./uz-location-extensions": "./src/uz-location-extensions.js",
|
|
44
45
|
"./central-asia-locations": "./src/central-asia-locations.js",
|
|
@@ -22,11 +22,14 @@ const FIELD_EXTRA_ALIASES = Object.freeze({
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
const APPLICATION_MODAL_RE = /(?:отправить\s+резюме\s+)?пол\s+мужской\s+женский\s+образование[\s\S]{0,500}?выберите\s+вакансию[\s\S]*/iu;
|
|
25
|
-
const
|
|
25
|
+
const LEAKED_STYLESHEET_START_RE = /:root\s*\{\s*--[\w-]+\s*:/iu;
|
|
26
|
+
const LEAKED_CSS_RULE_RE = /\s*(?:[.#][\w\\-]+|:root)(?:[^{}\n]{0,300})\{\s*(?:(?:--)?[\w-]+\s*:\s*[^;{}]+;?\s*)+\}\s*/giu;
|
|
26
27
|
|
|
27
|
-
/** Remove source-page controls and stylesheet fragments copied into
|
|
28
|
+
/** Remove source-page controls and stylesheet fragments copied into hiring text. */
|
|
28
29
|
export function cleanHiringSourceText(value) {
|
|
29
|
-
|
|
30
|
+
const text = String(value || '');
|
|
31
|
+
const stylesheetStart = text.search(LEAKED_STYLESHEET_START_RE);
|
|
32
|
+
return (stylesheetStart >= 0 ? text.slice(0, stylesheetStart) : text)
|
|
30
33
|
.replace(APPLICATION_MODAL_RE, '')
|
|
31
34
|
.replace(LEAKED_CSS_RULE_RE, ' ')
|
|
32
35
|
.replace(/[ \t]+(?=\n)/g, '')
|
package/src/index.js
CHANGED
|
@@ -18,7 +18,8 @@ export * from './geography-detection.js';
|
|
|
18
18
|
export * from './central-asia.js';
|
|
19
19
|
export * from './ukraine.js';
|
|
20
20
|
export * from './location-merge.js';
|
|
21
|
-
export * from './locations.js';
|
|
21
|
+
export * from './locations-runtime.js';
|
|
22
|
+
export * from './kg-location-extensions.js';
|
|
22
23
|
export * from './kz-location-extensions.js';
|
|
23
24
|
export * from './uz-location-extensions.js';
|
|
24
25
|
export * from './central-asia-locations.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { aliasesToRegex } from './normalization.js';
|
|
2
|
+
|
|
3
|
+
const district = (name, aliases = []) => {
|
|
4
|
+
const all = Object.freeze([...new Set([name, ...aliases].filter(Boolean))]);
|
|
5
|
+
return Object.freeze({
|
|
6
|
+
canonical: name,
|
|
7
|
+
name,
|
|
8
|
+
type: 'district',
|
|
9
|
+
entityType: 'district',
|
|
10
|
+
country: 'KG',
|
|
11
|
+
aliases: all,
|
|
12
|
+
re: aliasesToRegex(all),
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const KG_LOCATION_EXTENSIONS = Object.freeze({
|
|
17
|
+
Bishkek: Object.freeze({
|
|
18
|
+
districts: Object.freeze([
|
|
19
|
+
district('Pervomaisky', ['Первомайский', 'Первомайский район', 'Биринчи Май', 'Биринчи Май району', 'Birinchi May', 'Birinchi May district']),
|
|
20
|
+
district('Leninsky', ['Ленинский', 'Ленинский район', 'Ленин району', 'Lenin district']),
|
|
21
|
+
district('Oktyabrsky', ['Октябрьский', 'Октябрьский район', 'Октябрь району', 'Oktyabr district']),
|
|
22
|
+
district('Sverdlovsky', ['Свердловский', 'Свердловский район', 'Свердлов району', 'Sverdlov district']),
|
|
23
|
+
]),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LOCATION_DICTIONARIES as BASE_LOCATION_DICTIONARIES,
|
|
3
|
+
UA_REGION_ENTRIES,
|
|
4
|
+
UA_SECONDARY_CITIES,
|
|
5
|
+
matchUkraineRegion,
|
|
6
|
+
matchUkraineSecondaryCity,
|
|
7
|
+
} from './locations.js';
|
|
8
|
+
import { LOCATION_LIST_KEYS, mergeLocationCountries } from './location-merge.js';
|
|
9
|
+
import { KG_LOCATION_EXTENSIONS } from './kg-location-extensions.js';
|
|
10
|
+
|
|
11
|
+
export { UA_REGION_ENTRIES, UA_SECONDARY_CITIES, matchUkraineRegion, matchUkraineSecondaryCity };
|
|
12
|
+
|
|
13
|
+
export const LOCATION_DICTIONARIES = Object.freeze({
|
|
14
|
+
...BASE_LOCATION_DICTIONARIES,
|
|
15
|
+
KG: mergeLocationCountries(
|
|
16
|
+
BASE_LOCATION_DICTIONARIES.KG || {},
|
|
17
|
+
KG_LOCATION_EXTENSIONS,
|
|
18
|
+
),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export function dictionaryFor(countryCode, city) {
|
|
22
|
+
return LOCATION_DICTIONARIES[countryCode]?.[city] || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function locationCities(countryCode) {
|
|
26
|
+
return LOCATION_DICTIONARIES[countryCode] || Object.freeze({});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function matchDictionaryLocation(text, countryCode, city = null) {
|
|
30
|
+
const country = locationCities(countryCode);
|
|
31
|
+
const cities = city && country[city] ? [[city, country[city]]] : Object.entries(country);
|
|
32
|
+
const value = String(text || '');
|
|
33
|
+
let best = null;
|
|
34
|
+
|
|
35
|
+
for (const [cityName, data] of cities) {
|
|
36
|
+
for (const type of LOCATION_LIST_KEYS) {
|
|
37
|
+
for (const entry of data[type] || []) {
|
|
38
|
+
const match = entry?.re?.exec(value);
|
|
39
|
+
if (!match) continue;
|
|
40
|
+
const start = match.index;
|
|
41
|
+
const end = start + match[0].length;
|
|
42
|
+
const containsBest = best && start <= best.start && end >= best.end && end - start > best.end - best.start;
|
|
43
|
+
if (best && !containsBest) continue;
|
|
44
|
+
best = { city: cityName, type, name: entry.name, aliases: entry.aliases, start, end };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!best) return null;
|
|
50
|
+
const { start: _start, end: _end, ...result } = best;
|
|
51
|
+
return result;
|
|
52
|
+
}
|