text-to-map 1.1.17 → 1.1.19
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.
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { readFileSync, writeFileSync } from "fs";
|
|
11
|
-
import {
|
|
11
|
+
import { getNewMunicipalityByName, parseOrdinanceToAddressPoints, } from "../street-markdown/smd";
|
|
12
12
|
function main() {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
14
|
// take first node argument as a file name
|
|
@@ -35,10 +35,16 @@ function main() {
|
|
|
35
35
|
warningCount++;
|
|
36
36
|
};
|
|
37
37
|
console.time("downloadAndImportAllLatestAddressPoints");
|
|
38
|
-
const { municipality } = yield
|
|
39
|
-
const addressPoints = yield parseOrdinanceToAddressPoints(
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const { municipality } = yield getNewMunicipalityByName("Česká Lípa");
|
|
39
|
+
const addressPoints = yield parseOrdinanceToAddressPoints({
|
|
40
|
+
lines,
|
|
41
|
+
initialState: {
|
|
42
|
+
// currentMunicipality: municipality,
|
|
43
|
+
},
|
|
44
|
+
onError: reportErrors,
|
|
45
|
+
onWarning: reportWarnings,
|
|
46
|
+
includeUnmappedAddressPoints: true,
|
|
47
|
+
});
|
|
42
48
|
console.timeEnd("downloadAndImportAllLatestAddressPoints");
|
|
43
49
|
console.log(`Parsed ${lines.length} lines, ${errorCount} errors, ${warningCount} warnings.`);
|
|
44
50
|
if (errorCount > 0) {
|
package/dist/db/founders.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { DbMunicipalityResult, MunicipalityPartResult, SmdError } from "../street-markdown/types";
|
|
2
2
|
import { Founder, MunicipalityType } from "./types";
|
|
3
3
|
export declare const insertFounders: (founders: Founder[]) => Promise<number>;
|
|
4
|
+
export declare const getFounderById: (id: number) => Promise<{
|
|
5
|
+
founder: Founder;
|
|
6
|
+
errors: SmdError[];
|
|
7
|
+
}>;
|
|
4
8
|
export declare const findFounder: (nameWithHashtag: string) => Promise<{
|
|
5
9
|
founder: Founder;
|
|
6
10
|
errors: SmdError[];
|
package/dist/db/founders.js
CHANGED
|
@@ -223,14 +223,27 @@ const extractFounderName = (line) => {
|
|
|
223
223
|
return line.trim();
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const name = extractFounderName(nameWithHashtag);
|
|
229
|
-
const result = yield getKnexDb()
|
|
226
|
+
const getBaseFounderQuery = () => {
|
|
227
|
+
return getKnexDb()
|
|
230
228
|
.select("f.id", "f.name", "f.ico", "f.founder_type_code", "f.city_code", "f.city_district_code")
|
|
231
229
|
.from("founder as f")
|
|
232
230
|
.leftJoin("city as c", "c.code", "f.city_code")
|
|
233
|
-
.leftJoin("city_district as d", "d.code", "f.city_district_code")
|
|
231
|
+
.leftJoin("city_district as d", "d.code", "f.city_district_code");
|
|
232
|
+
};
|
|
233
|
+
export const getFounderById = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
234
|
+
const result = yield getBaseFounderQuery().where("f.id", id).first();
|
|
235
|
+
const founder = yield resultToFounder(result);
|
|
236
|
+
return {
|
|
237
|
+
founder: founder !== null && founder !== void 0 ? founder : null,
|
|
238
|
+
errors: founder
|
|
239
|
+
? []
|
|
240
|
+
: [wholeLineError(`Zřizovatel s id ${id} neexistuje.`, "")],
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
export const findFounder = (nameWithHashtag) => __awaiter(void 0, void 0, void 0, function* () {
|
|
244
|
+
const errors = [];
|
|
245
|
+
const name = extractFounderName(nameWithHashtag);
|
|
246
|
+
const result = yield getBaseFounderQuery()
|
|
234
247
|
.where("f.name", name)
|
|
235
248
|
.orWhere("c.name", name)
|
|
236
249
|
.orWhere("d.name", name)
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { Founder } from "../db/types";
|
|
2
|
-
import { ErrorCallbackParams, Municipality, MunicipalityWithFounder, ProcessLineCallbackParams, School, SmdError, SmdState } from "./types";
|
|
3
|
-
|
|
2
|
+
import { ErrorCallbackParams, Municipality, MunicipalityWithFounder, MunicipalityWithFounderResult, ProcessLineCallbackParams, School, SmdError, SmdState } from "./types";
|
|
3
|
+
interface ParseOrdinanceProps {
|
|
4
|
+
lines: string[];
|
|
5
|
+
initialState?: Partial<SmdState>;
|
|
6
|
+
onError?: (params: ErrorCallbackParams) => void;
|
|
7
|
+
onWarning?: (params: ErrorCallbackParams) => void;
|
|
8
|
+
onProcessedLine?: (params: ProcessLineCallbackParams) => void;
|
|
9
|
+
includeUnmappedAddressPoints: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const parseOrdinanceToAddressPoints: ({ lines, initialState, onError, onWarning, onProcessedLine, includeUnmappedAddressPoints, }: ParseOrdinanceProps) => Promise<Municipality[]>;
|
|
4
12
|
export declare const convertMunicipality: (municipality: MunicipalityWithFounder) => Municipality;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
errors: SmdError[];
|
|
8
|
-
}>;
|
|
13
|
+
export declare const getNewMunicipalityByName: (name: string) => Promise<MunicipalityWithFounderResult>;
|
|
14
|
+
export declare const getNewMunicipalityByFounderId: (founderId: number) => Promise<MunicipalityWithFounderResult>;
|
|
9
15
|
export declare const getNewSchool: (name: string, founder: Founder | null, lineNumber: number, onError: (params: ErrorCallbackParams) => void) => Promise<School>;
|
|
10
16
|
export declare const wholeLineError: (message: string, line: string) => SmdError;
|
|
17
|
+
export {};
|
|
@@ -9,18 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { checkStreetExists, findAddressPoints, getAddressPointById, } from "../db/address-points";
|
|
11
11
|
import { disconnectKnex } from "../db/db";
|
|
12
|
-
import { findFounder } from "../db/founders";
|
|
12
|
+
import { findFounder, getFounderById } from "../db/founders";
|
|
13
13
|
import { findSchool } from "../db/schools";
|
|
14
14
|
import { founderToMunicipality } from "../db/types";
|
|
15
15
|
import { getMunicipalityPartResult, getRestOfMunicipalityPart, getSwitchMunicipality, getWholeMunicipality, isMunicipalitySwitch, isRestOfMunicipalityLine, isRestOfMunicipalityPartLine, isRestWithNoStreetNameLine, isWholeMunicipality, } from "./municipality";
|
|
16
16
|
import { parseLine } from "./smd-line-parser";
|
|
17
17
|
import { isAddressPoint, } from "./types";
|
|
18
|
-
export const parseOrdinanceToAddressPoints = (lines, initialState = {}, onError = () => { }, onWarning = () => { }, onProcessedLine = () => { }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
export const parseOrdinanceToAddressPoints = ({ lines, initialState = {}, onError = () => { }, onWarning = () => { }, onProcessedLine = () => { }, includeUnmappedAddressPoints = false, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
try {
|
|
20
20
|
const state = Object.assign({ currentMunicipality: null, currentFilterMunicipality: null, currentSchool: null, rests: {
|
|
21
21
|
noStreetNameSchoolIzo: null,
|
|
22
22
|
municipalityParts: [],
|
|
23
23
|
wholeMunicipalitySchoolIzo: null,
|
|
24
|
+
includeUnmappedAddressPoints,
|
|
24
25
|
}, municipalities: [] }, initialState);
|
|
25
26
|
let lineNumber = 1;
|
|
26
27
|
for (const rawLine of lines) {
|
|
@@ -61,6 +62,7 @@ export const convertMunicipality = (municipality) => {
|
|
|
61
62
|
return {
|
|
62
63
|
municipalityName: municipality.municipalityName,
|
|
63
64
|
schools: municipality.schools,
|
|
65
|
+
unmappedPoints: municipality.unmappedPoints,
|
|
64
66
|
};
|
|
65
67
|
};
|
|
66
68
|
const processOneLine = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -115,7 +117,7 @@ const processMunicipalityLine = ({ line, lineNumber, state, onError, }) => __awa
|
|
|
115
117
|
state.currentSchool = null;
|
|
116
118
|
}
|
|
117
119
|
yield completeCurrentMunicipality(state);
|
|
118
|
-
const { municipality, errors } = yield
|
|
120
|
+
const { municipality, errors } = yield getNewMunicipalityByName(line);
|
|
119
121
|
if (errors.length > 0) {
|
|
120
122
|
onError({ lineNumber, line, errors });
|
|
121
123
|
}
|
|
@@ -210,14 +212,14 @@ const processAddressPointLine = ({ line, state, lineNumber, onError, onWarning,
|
|
|
210
212
|
}
|
|
211
213
|
}
|
|
212
214
|
});
|
|
213
|
-
const addRestToSchool = (restPoints, schoolIzo, state) =>
|
|
215
|
+
const addRestToSchool = (restPoints, schoolIzo, state) => {
|
|
214
216
|
const addressPoints = state.currentMunicipality.schools.flatMap((school) => school.addresses);
|
|
215
217
|
// filter out address points already present
|
|
216
218
|
const remainingPoints = restPoints.filter((point) => !addressPoints.some((ap) => ap.address === point.address));
|
|
217
219
|
// find the right school and add the remaining address points
|
|
218
220
|
const schoolIndex = state.currentMunicipality.schools.findIndex((school) => school.izo === schoolIzo);
|
|
219
221
|
state.currentMunicipality.schools[schoolIndex].addresses.push(...remainingPoints);
|
|
220
|
-
}
|
|
222
|
+
};
|
|
221
223
|
const addRests = (state) => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
224
|
if (state.rests.noStreetNameSchoolIzo) {
|
|
223
225
|
yield addRestWithNoStreetNameToSchool(state);
|
|
@@ -228,6 +230,9 @@ const addRests = (state) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
228
230
|
for (const rest of state.rests.municipalityParts) {
|
|
229
231
|
yield addRestOfMunicipalityPart(state, rest.municipalityPartCode, rest.schoolIzo);
|
|
230
232
|
}
|
|
233
|
+
if (state.rests.includeUnmappedAddressPoints) {
|
|
234
|
+
yield addRestOfMunicipalityToUnmappedPoints(state);
|
|
235
|
+
}
|
|
231
236
|
state.rests.noStreetNameSchoolIzo = null;
|
|
232
237
|
state.rests.wholeMunicipalitySchoolIzo = null;
|
|
233
238
|
state.rests.municipalityParts = [];
|
|
@@ -241,18 +246,23 @@ const addRestWithNoStreetNameToSchool = (state) => __awaiter(void 0, void 0, voi
|
|
|
241
246
|
type: state.currentMunicipality.founder.municipalityType,
|
|
242
247
|
},
|
|
243
248
|
});
|
|
244
|
-
|
|
249
|
+
addRestToSchool(pointsNoStreetName, state.rests.noStreetNameSchoolIzo, state);
|
|
245
250
|
});
|
|
246
251
|
const addRestOfMunicipality = (state) => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
|
+
addRestToSchool(yield getRestOfMunicipality(state), state.rests.wholeMunicipalitySchoolIzo, state);
|
|
253
|
+
});
|
|
254
|
+
const addRestOfMunicipalityToUnmappedPoints = (state) => __awaiter(void 0, void 0, void 0, function* () {
|
|
255
|
+
state.currentMunicipality.unmappedPoints = (yield getRestOfMunicipality(state)).map(mapAddressPointForExport);
|
|
256
|
+
});
|
|
257
|
+
const getRestOfMunicipality = (state) => __awaiter(void 0, void 0, void 0, function* () {
|
|
247
258
|
// get all address points for current municipality
|
|
248
|
-
|
|
259
|
+
return yield findAddressPoints({
|
|
249
260
|
type: "wholeMunicipality",
|
|
250
261
|
municipality: {
|
|
251
262
|
code: state.currentMunicipality.founder.cityOrDistrictCode,
|
|
252
263
|
type: state.currentMunicipality.founder.municipalityType,
|
|
253
264
|
},
|
|
254
265
|
});
|
|
255
|
-
yield addRestToSchool(allPoints, state.rests.wholeMunicipalitySchoolIzo, state);
|
|
256
266
|
});
|
|
257
267
|
const addRestOfMunicipalityPart = (state, municipalityPartCode, schoolIzo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
268
|
// get all address points for current municipality
|
|
@@ -260,18 +270,24 @@ const addRestOfMunicipalityPart = (state, municipalityPartCode, schoolIzo) => __
|
|
|
260
270
|
type: "wholeMunicipalityPart",
|
|
261
271
|
municipalityPartCode,
|
|
262
272
|
});
|
|
263
|
-
|
|
273
|
+
addRestToSchool(allPoints, schoolIzo, state);
|
|
264
274
|
});
|
|
265
|
-
export const
|
|
275
|
+
export const getNewMunicipalityByName = (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
266
276
|
const { founder, errors } = yield findFounder(name);
|
|
267
|
-
return
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
277
|
+
return getNewMunicipality(founder, errors);
|
|
278
|
+
});
|
|
279
|
+
export const getNewMunicipalityByFounderId = (founderId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
280
|
+
const { founder, errors } = yield getFounderById(founderId);
|
|
281
|
+
return getNewMunicipality(founder, errors);
|
|
282
|
+
});
|
|
283
|
+
const getNewMunicipality = (founder, errors) => ({
|
|
284
|
+
municipality: {
|
|
285
|
+
municipalityName: founder ? founder.name : "Neznámá obec",
|
|
286
|
+
founder,
|
|
287
|
+
schools: [],
|
|
288
|
+
unmappedPoints: [],
|
|
289
|
+
},
|
|
290
|
+
errors,
|
|
275
291
|
});
|
|
276
292
|
export const getNewSchool = (name, founder, lineNumber, onError) => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
293
|
let exportSchool = {
|
|
@@ -64,6 +64,7 @@ export interface School {
|
|
|
64
64
|
export interface Municipality {
|
|
65
65
|
municipalityName: string;
|
|
66
66
|
schools: School[];
|
|
67
|
+
unmappedPoints: ExportAddressPoint[];
|
|
67
68
|
}
|
|
68
69
|
export interface DbMunicipalityResult {
|
|
69
70
|
municipality: DbMunicipality;
|
|
@@ -76,6 +77,10 @@ export interface MunicipalityPartResult {
|
|
|
76
77
|
export interface MunicipalityWithFounder extends Municipality {
|
|
77
78
|
founder: Founder | null;
|
|
78
79
|
}
|
|
80
|
+
export interface MunicipalityWithFounderResult {
|
|
81
|
+
municipality: MunicipalityWithFounder;
|
|
82
|
+
errors: SmdError[];
|
|
83
|
+
}
|
|
79
84
|
export interface SmdState {
|
|
80
85
|
currentMunicipality: MunicipalityWithFounder;
|
|
81
86
|
currentFilterMunicipality: DbMunicipality;
|
|
@@ -87,6 +92,7 @@ export interface SmdState {
|
|
|
87
92
|
schoolIzo: string;
|
|
88
93
|
}[];
|
|
89
94
|
wholeMunicipalitySchoolIzo: string;
|
|
95
|
+
includeUnmappedAddressPoints: boolean;
|
|
90
96
|
};
|
|
91
97
|
municipalities: Municipality[];
|
|
92
98
|
}
|
package/package.json
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"name": "text-to-map",
|
|
59
59
|
"description": "Text To Map usiluje o lepší, strojově zpracovatelné využití částí vyhlášek s výčtem ulic a dalších lokací. Jde o rozšiřitelnou sadu konceptů a nástrojů, které zajistí hladký převod výčtu ulic a jejich rozsahů v lidsky srozumitelném jazyce do strojově zpracovatelného, uchopitelného formátu.",
|
|
60
|
-
"version": "1.1.
|
|
60
|
+
"version": "1.1.19",
|
|
61
61
|
"main": "dist/index.js",
|
|
62
62
|
"types": "dist/index.d.ts",
|
|
63
63
|
"files": [
|