@whiteslove/parsing-lexicon 0.2.3 → 0.2.4
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/housing-text.d.ts +2 -0
- package/src/housing-text.js +62 -0
package/package.json
CHANGED
package/src/housing-text.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare function parseHousingRoomsFromText(value: unknown): number | null;
|
|
2
2
|
export declare function parseHousingResidentialComplex(value: unknown): string | null;
|
|
3
|
+
export declare function parseHousingAreaFromText(value: unknown): number | null;
|
|
4
|
+
export declare function parseHousingFloorFromText(value: unknown): { floor: number | null; totalFloors: number | null };
|
package/src/housing-text.js
CHANGED
|
@@ -73,3 +73,65 @@ export function parseHousingResidentialComplex(value) {
|
|
|
73
73
|
const name = words.join(' ').trim();
|
|
74
74
|
return /[a-zA-Zа-яёіїґ]{2,}/i.test(name) ? name : null;
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
export function parseHousingAreaFromText(value) {
|
|
78
|
+
const text = String(value || '');
|
|
79
|
+
if (!text) return null;
|
|
80
|
+
const match =
|
|
81
|
+
text.match(/(\d{2,4})\s*(?:m2|m²|мкв|м2|м²|sq ?m|кв\.?\s*м|квадрат[а-яё]*)/i) ||
|
|
82
|
+
text.match(/(?:^|\n)[^\d\r\n]{0,8}[1-9]\s*[¹²³⁴⁵⁶⁷⁸⁹]?\s*\/\s*[0-9]{1,2}\s*\/\s*[0-9]{1,2}\s+(\d{2,4})\s*кв(?=\s|$)/im);
|
|
83
|
+
return match ? Number(match[1]) : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function parseHousingFloorFromText(value) {
|
|
87
|
+
const text = String(value || '');
|
|
88
|
+
if (!text) return { floor: null, totalFloors: null };
|
|
89
|
+
const t = text.toLowerCase();
|
|
90
|
+
const floorWord = '(?:этаж(?:да)?|поверх|qavat|қабат|қабатт|etaj|floor|эт\\.)';
|
|
91
|
+
const valid = (floor, total) => floor >= 0 && floor <= 200 && (total == null || (total >= floor && total <= 200));
|
|
92
|
+
|
|
93
|
+
if (/(?:^|\n)[^\d\r\n]{0,8}[1-9]\s*\/\s*0\s*\/\s*-1\s*(?:этаж|эт\.?)?[^\r\n]*(?:подвал|цоколь)/im.test(t)) return { floor: -1, totalFloors: null };
|
|
94
|
+
|
|
95
|
+
const compact = t.match(/(?:^|\n)[^\d\r\n]{0,8}[1-9]\s*[¹²³⁴⁵⁶⁷⁸⁹]?\s*\/\s*([0-9]{1,2})\s*\/\s*([0-9]{1,2})[.,;:]?(?=\s|$)/m);
|
|
96
|
+
if (compact) {
|
|
97
|
+
const floor = Number(compact[1]);
|
|
98
|
+
const total = Number(compact[2]);
|
|
99
|
+
if (floor >= 1 && floor <= 40 && total >= 2 && total <= 40 && floor <= total) return { floor, totalFloors: total };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const labelledPair = t.match(/([1-9]\d?)\s*-?\s*(?:qavat|этаж|поверх|қабат)\s*(?:\/|из|iz|of)\s*([1-9]\d?)\s*-?\s*(?:qavatli|qavat|этаж(?:ей|ный)?|поверх(?:ів|овий)?|қабатты?)/i);
|
|
103
|
+
if (labelledPair) {
|
|
104
|
+
const floor = Number(labelledPair[1]);
|
|
105
|
+
const total = Number(labelledPair[2]);
|
|
106
|
+
if (floor <= 40 && total <= 40 && floor <= total) return { floor, totalFloors: total };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const sep = '(?:\\/|из|iz|of)';
|
|
110
|
+
const pair = t.match(new RegExp(`${floorWord}\\D{0,4}(\\d{1,2})\\s*${sep}\\s*(\\d{1,2})`)) || t.match(new RegExp(`(\\d{1,2})\\s*${sep}\\s*(\\d{1,2})\\s*${floorWord}`));
|
|
111
|
+
if (pair) {
|
|
112
|
+
const floor = Number(pair[1]);
|
|
113
|
+
const total = Number(pair[2]);
|
|
114
|
+
if (valid(floor, total)) return { floor, totalFloors: total };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const notLetter = '(?!н|ей|ів|ност|ка|ки|s)';
|
|
118
|
+
const single = t.match(new RegExp(`(\\d{1,2})[^\\S\\r\\n]*-?[^\\S\\r\\n]*(?:го|ом|ым|ой|ий|nd|rd|th|st|й|м|е)?[^\\S\\r\\n]*${floorWord}${notLetter}`)) || t.match(new RegExp(`${floorWord}\\s*[:№#]?\\s*(\\d{1,2})\\b`));
|
|
119
|
+
if (single) {
|
|
120
|
+
const floor = Number(single[1]);
|
|
121
|
+
if (valid(floor, null)) {
|
|
122
|
+
const explicitTotal = t.match(/(?:этажность|этажей|поверхови|поверховість|qavatlar(?:\s*soni)?|qavatli|қабатты?)\D{0,6}(\d{1,2})/);
|
|
123
|
+
const leadingTotal = t.match(/([1-9]\d?)\s*-?\s*(?:этажн[а-яё]*|поверхов[а-яіїґ]*|qavatli|қабатты?)\s*(?:дом|здани|будин|uy|bino)?/i);
|
|
124
|
+
const total = explicitTotal ? Number(explicitTotal[1]) : leadingTotal ? Number(leadingTotal[1]) : null;
|
|
125
|
+
return { floor, totalFloors: total && total >= floor && total <= 200 ? total : null };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const bare = t.match(/(?<![\d/])([1-9]\d?)\s*\/\s*([1-9]\d?)(?![\d/])/);
|
|
130
|
+
if (bare) {
|
|
131
|
+
const floor = Number(bare[1]);
|
|
132
|
+
const total = Number(bare[2]);
|
|
133
|
+
if (floor >= 1 && floor <= 40 && total >= 2 && total <= 40 && floor <= total) return { floor, totalFloors: total };
|
|
134
|
+
}
|
|
135
|
+
return { floor: null, totalFloors: null };
|
|
136
|
+
}
|
|
137
|
+
|