@tricoteuses/tisseuse 0.13.7 → 0.13.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/README.md +39 -35
- package/dist/{textes-BIJjrNwg.js → html-DhGw-Yqr.js} +3875 -5243
- package/dist/index.js +280 -147
- package/dist/resolver-DZS-DNp6.js +1848 -0
- package/dist/server-f-legi.js +532 -0
- package/dist/server.js +530 -2161
- package/dist/src/lib/extractors/links.d.ts +6 -4
- package/dist/src/lib/f_legi/resolver.d.ts +5 -7
- package/dist/src/lib/index.d.ts +2 -0
- package/dist/src/lib/legi/canutes_resolver.d.ts +5 -6
- package/dist/src/lib/legi/resolver.d.ts +15 -12
- package/dist/src/lib/legi/resolver.test.d.ts +1 -0
- package/dist/src/lib/legi/text_titles_infos.d.ts +26 -0
- package/dist/src/lib/linkers/html.d.ts +15 -4
- package/dist/src/lib/linkers/markdown.d.ts +4 -2
- package/dist/src/lib/server/databases/index.d.ts +1 -1
- package/dist/src/lib/server/f_legi/index.d.ts +1 -0
- package/dist/src/lib/server/index.d.ts +2 -1
- package/dist/src/lib/server/judilibre_search.d.ts +31 -0
- package/dist/src/lib/server/judilibre_search.test.d.ts +1 -0
- package/dist/src/lib/server/legi/resolvers.d.ts +2 -7
- package/dist/src/lib/server/linkers/html.d.ts +4 -2
- package/dist/src/scripts/enrich_senat_documents.d.ts +1 -0
- package/dist/src/scripts/index_postgres_judilibre.d.ts +1 -0
- package/package.json +8 -1
- package/dist/src/lib/f_legi/extractors/links.d.ts +0 -134
- package/dist/src/lib/f_legi/linkers/html.d.ts +0 -51
- package/dist/src/lib/server/f_legi/databases/index.d.ts +0 -2
- package/dist/src/lib/server/f_legi/linkers/html.d.ts +0 -20
- package/dist/src/scripts/f_legi/add_links_to_html_document.d.ts +0 -0
- /package/dist/src/{scripts/extract_texts_titles_infos.d.ts → lib/f_legi/resolver.test.d.ts} +0 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { n as e, r as t, t as n } from "./resolver-DZS-DNp6.js";
|
|
2
|
+
//#region src/lib/f_legi/resolver.ts
|
|
3
|
+
var r = [
|
|
4
|
+
"article_location_diffs",
|
|
5
|
+
"article_num_candidate_stats",
|
|
6
|
+
"article_num_candidates",
|
|
7
|
+
"jorfarti",
|
|
8
|
+
"jorftext",
|
|
9
|
+
"legiarti",
|
|
10
|
+
"legitext",
|
|
11
|
+
"scta",
|
|
12
|
+
"text_titles_infos"
|
|
13
|
+
], i;
|
|
14
|
+
async function a(e) {
|
|
15
|
+
let t = await e`
|
|
16
|
+
SELECT required.name
|
|
17
|
+
FROM unnest(${e.array([...r])}::text[]) AS required(name)
|
|
18
|
+
WHERE to_regclass(required.name) IS NULL
|
|
19
|
+
ORDER BY required.name
|
|
20
|
+
`;
|
|
21
|
+
if (t.length > 0) throw Error(`The f_legi database is missing required relations: ${t.map(({ name: e }) => e).join(", ")}`);
|
|
22
|
+
}
|
|
23
|
+
var o = class extends n {
|
|
24
|
+
flegiDb;
|
|
25
|
+
articleRowsByNumByTextAndDate = /* @__PURE__ */ new Map();
|
|
26
|
+
articleNumsLoadedByTextAndDate = /* @__PURE__ */ new Map();
|
|
27
|
+
articleRowsByContextTextId = /* @__PURE__ */ new Map();
|
|
28
|
+
directSectionChildrenByParentAndDate = /* @__PURE__ */ new Map();
|
|
29
|
+
globalArticleRowsByNumAndDate = /* @__PURE__ */ new Map();
|
|
30
|
+
rootTextIdsByTextId = /* @__PURE__ */ new Map();
|
|
31
|
+
contextTextIdsByTextId = /* @__PURE__ */ new Map();
|
|
32
|
+
textIdBySegmentId = /* @__PURE__ */ new Map();
|
|
33
|
+
schemaValidationPromise;
|
|
34
|
+
textTitlesInfosLoaded = !1;
|
|
35
|
+
constructor(e) {
|
|
36
|
+
super(), this.flegiDb = e;
|
|
37
|
+
}
|
|
38
|
+
async getActiveArticlesByTextAndNum({ date: e, num: t, textId: n }) {
|
|
39
|
+
return t === void 0 ? [] : (await this.getActiveArticleRowsByNum(n, e)).get(t) ?? [];
|
|
40
|
+
}
|
|
41
|
+
async getDirectSectionChildren({ date: e, parentPath: t }) {
|
|
42
|
+
let n = `${t}\0${e}`, r = this.directSectionChildrenByParentAndDate.get(n);
|
|
43
|
+
if (r === void 0) {
|
|
44
|
+
if (r = await this.getDirectSectionChildrenByExactParentPath({
|
|
45
|
+
date: e,
|
|
46
|
+
parentPath: t
|
|
47
|
+
}), r.length === 0 && !t.includes(".")) {
|
|
48
|
+
let n = await this.getRootTextIdsFromTextId(t);
|
|
49
|
+
n.length > 1 && (r = await this.flegiDb`
|
|
50
|
+
SELECT
|
|
51
|
+
dernier_segment AS id,
|
|
52
|
+
chemin::text AS path,
|
|
53
|
+
titre AS title,
|
|
54
|
+
date_debut::text AS "dateDebut",
|
|
55
|
+
date_fin::text AS "dateFin"
|
|
56
|
+
FROM scta
|
|
57
|
+
WHERE
|
|
58
|
+
subltree(chemin, 0, 1) = ANY(${this.flegiDb.array(n)}::ltree[])
|
|
59
|
+
AND nlevel(chemin) = 2
|
|
60
|
+
AND type_objet = 'scta'
|
|
61
|
+
AND date_debut <= ${e}::date
|
|
62
|
+
AND date_fin >= ${e}::date
|
|
63
|
+
ORDER BY tri_hierarchique
|
|
64
|
+
`);
|
|
65
|
+
}
|
|
66
|
+
this.directSectionChildrenByParentAndDate.set(n, r);
|
|
67
|
+
}
|
|
68
|
+
return r;
|
|
69
|
+
}
|
|
70
|
+
async getTextIdFromSegmentId(e) {
|
|
71
|
+
let t = this.textIdBySegmentId.get(e);
|
|
72
|
+
return t === void 0 && (t = await this.getTextIdFromSegmentIdUsingContextHeuristic(e) ?? await this.getTextIdFromSegmentIdUsingSctaHeuristic(e) ?? null, this.textIdBySegmentId.set(e, t)), t ?? void 0;
|
|
73
|
+
}
|
|
74
|
+
async preloadTextTitlesInfos(n = {}) {
|
|
75
|
+
let r = (e, t = {}) => {
|
|
76
|
+
n.onProgress?.({
|
|
77
|
+
...t,
|
|
78
|
+
phase: e,
|
|
79
|
+
resolver: "f_legi"
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
if (this.textTitlesInfosLoaded) {
|
|
83
|
+
r("already-loaded");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
let o = new e("f_legi.preloadTextTitlesInfos");
|
|
87
|
+
this.schemaValidationPromise ??= a(this.flegiDb).catch((e) => {
|
|
88
|
+
throw this.schemaValidationPromise = void 0, e;
|
|
89
|
+
}), await this.schemaValidationPromise, i === void 0 ? (r("queryTextTitlesInfos:start"), i = (async () => {
|
|
90
|
+
let e = await o.time("queryTextTitlesInfos", () => this.flegiDb`
|
|
91
|
+
SELECT
|
|
92
|
+
cid,
|
|
93
|
+
date_texte::text AS "dateTexte",
|
|
94
|
+
legi_id::text AS id,
|
|
95
|
+
nature,
|
|
96
|
+
num,
|
|
97
|
+
title
|
|
98
|
+
FROM text_titles_infos
|
|
99
|
+
ORDER BY legi_id
|
|
100
|
+
`);
|
|
101
|
+
r("queryTextTitlesInfos:done", { count: e.length }), r("buildTextTitlesInfos:start", { count: e.length });
|
|
102
|
+
let n = performance.now();
|
|
103
|
+
await t(e, { onProgress: ({ count: e, phase: t }) => r(`buildTextTitlesInfos:${t}`, { count: e }) }), o.add({
|
|
104
|
+
count: e.length,
|
|
105
|
+
durationMs: Math.round((performance.now() - n) * 10) / 10,
|
|
106
|
+
phase: "buildTextTitlesInfos"
|
|
107
|
+
}), r("buildTextTitlesInfos:done");
|
|
108
|
+
})().catch((e) => {
|
|
109
|
+
throw i = void 0, e;
|
|
110
|
+
})) : r("waiting-for-shared-preload"), await i, r("setTextTitlesInfos:done"), o.log(), this.textTitlesInfosLoaded = !0;
|
|
111
|
+
}
|
|
112
|
+
async getUniqueActiveArticlesByNum({ date: e, num: t }) {
|
|
113
|
+
if (t === void 0) return [];
|
|
114
|
+
let n = `${t}\0${e}`, r = this.globalArticleRowsByNumAndDate.get(n);
|
|
115
|
+
return r === void 0 && (r = await this.queryUniqueActiveArticlesByNumsUsingContextHeuristic([t]), this.globalArticleRowsByNumAndDate.set(n, r)), r;
|
|
116
|
+
}
|
|
117
|
+
async preloadUniqueActiveArticlesByNums({ date: t, nums: n }) {
|
|
118
|
+
let r = [];
|
|
119
|
+
for (let e of n) {
|
|
120
|
+
if (e === void 0) continue;
|
|
121
|
+
let n = `${e}\0${t}`;
|
|
122
|
+
this.globalArticleRowsByNumAndDate.has(n) || (this.globalArticleRowsByNumAndDate.set(n, []), r.push(e));
|
|
123
|
+
}
|
|
124
|
+
if (r.length === 0) return;
|
|
125
|
+
let i = new e("f_legi.preloadUniqueActiveArticlesByNums"), a = await i.time("queryGloballyUniqueArticleRowsByNums", () => this.queryGloballyUniqueArticleRowsByNums(r), { count: r.length }), o = new Set(a.map(({ num: e }) => e).filter((e) => e !== null)), s = r.filter((e) => !o.has(e)), c = await i.time("queryUniqueActiveArticlesByNumsUsingContextHeuristic", () => this.queryUniqueActiveArticlesByNumsUsingContextHeuristic(s), { count: s.length }), l = [...a, ...c].toSorted((e, t) => e.id < t.id ? -1 : +(e.id > t.id)), u = /* @__PURE__ */ new Map();
|
|
126
|
+
for (let e of l) {
|
|
127
|
+
if (e.num === null) continue;
|
|
128
|
+
let n = u.get(e.num) ?? 0;
|
|
129
|
+
if (u.set(e.num, n + 1), n >= 100) continue;
|
|
130
|
+
let r = `${e.num}\0${t}`;
|
|
131
|
+
this.globalArticleRowsByNumAndDate.get(r)?.push(e);
|
|
132
|
+
}
|
|
133
|
+
i.log({
|
|
134
|
+
articleRowCount: l.length,
|
|
135
|
+
globallyUniqueArticleRowCount: a.length,
|
|
136
|
+
heuristicArticleRowCount: c.length,
|
|
137
|
+
heuristicNumCount: s.length,
|
|
138
|
+
numCount: r.length
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async preloadActiveArticlesByTextIds({ date: t, nums: n, textIds: r }) {
|
|
142
|
+
let i = n === void 0 ? void 0 : [...new Set(n)].filter(Boolean), a = [...new Set(r)].filter((e) => {
|
|
143
|
+
if (e === void 0) return !1;
|
|
144
|
+
let n = `${e}\0${t}`;
|
|
145
|
+
if (this.articleRowsByNumByTextAndDate.get(n) === void 0) return !0;
|
|
146
|
+
let r = this.articleNumsLoadedByTextAndDate.get(n);
|
|
147
|
+
return r === "all" ? !1 : i === void 0 ? !0 : i.some((e) => !r?.has(e));
|
|
148
|
+
});
|
|
149
|
+
if (a.length === 0) return;
|
|
150
|
+
let o = new e("f_legi.preloadActiveArticlesByTextIds"), s = await o.time("getContextTextIdsByTextIds", () => this.getContextTextIdsByTextIds(a)), c = [...new Set([...s.values()].flat())], l = await o.time("getActiveArticleRowsForContextTextIds", () => i === void 0 ? this.getActiveArticleRowsForContextTextIdsWithRoots(c) : this.queryActiveArticleRowsForContextTextIds(c, i), { count: c.length }), u = /* @__PURE__ */ new Map(), d = (e, t) => {
|
|
151
|
+
if (e === null) return;
|
|
152
|
+
let n = u.get(e);
|
|
153
|
+
n === void 0 ? u.set(e, [t]) : n.push(t);
|
|
154
|
+
};
|
|
155
|
+
for (let e of l) d(e.rootTextId, e), d(e.textId, e);
|
|
156
|
+
for (let e of a) {
|
|
157
|
+
let n = `${e}\0${t}`, r = s.get(e) ?? [e], a = /* @__PURE__ */ new Map();
|
|
158
|
+
for (let e of r) for (let t of u.get(e) ?? []) a.set(`${t.id}\0${t.textId}`, {
|
|
159
|
+
id: t.id,
|
|
160
|
+
textId: t.textId,
|
|
161
|
+
num: t.num,
|
|
162
|
+
dateDebut: t.dateDebut,
|
|
163
|
+
dateFin: t.dateFin
|
|
164
|
+
});
|
|
165
|
+
let o = this.articleRowsByNumByTextAndDate.get(n) ?? /* @__PURE__ */ new Map();
|
|
166
|
+
for (let e of a.values()) {
|
|
167
|
+
if (e.num === null) continue;
|
|
168
|
+
let t = o.get(e.num);
|
|
169
|
+
t === void 0 ? o.set(e.num, [e]) : t.some((t) => t.id === e.id && t.textId === e.textId) || t.push(e);
|
|
170
|
+
}
|
|
171
|
+
if (this.articleRowsByNumByTextAndDate.set(n, o), i === void 0) this.articleNumsLoadedByTextAndDate.set(n, "all");
|
|
172
|
+
else {
|
|
173
|
+
let e = this.articleNumsLoadedByTextAndDate.get(n);
|
|
174
|
+
if (e !== "all") {
|
|
175
|
+
let t = e ?? /* @__PURE__ */ new Set();
|
|
176
|
+
for (let e of i) t.add(e);
|
|
177
|
+
this.articleNumsLoadedByTextAndDate.set(n, t);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
o.log({
|
|
182
|
+
articleRowCount: l.length,
|
|
183
|
+
articleNumCount: i?.length,
|
|
184
|
+
rootTextIdCount: c.length,
|
|
185
|
+
textIdCount: a.length
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async queryUniqueActiveArticlesByNumsUsingContextHeuristic(e) {
|
|
189
|
+
return e.length === 0 ? [] : await this.flegiDb`
|
|
190
|
+
SELECT
|
|
191
|
+
id,
|
|
192
|
+
"textId",
|
|
193
|
+
num,
|
|
194
|
+
"dateDebut",
|
|
195
|
+
"dateFin"
|
|
196
|
+
FROM (
|
|
197
|
+
SELECT
|
|
198
|
+
id,
|
|
199
|
+
text_id AS "textId",
|
|
200
|
+
num,
|
|
201
|
+
date_debut::text AS "dateDebut",
|
|
202
|
+
date_fin::text AS "dateFin",
|
|
203
|
+
row_number() OVER (
|
|
204
|
+
PARTITION BY num
|
|
205
|
+
ORDER BY id
|
|
206
|
+
) AS "rowNumber"
|
|
207
|
+
FROM article_num_candidates
|
|
208
|
+
WHERE num IN ${this.flegiDb(e)}
|
|
209
|
+
) AS ranked_articles
|
|
210
|
+
WHERE "rowNumber" <= 100
|
|
211
|
+
`;
|
|
212
|
+
}
|
|
213
|
+
async queryGloballyUniqueArticleRowsByNums(e) {
|
|
214
|
+
return e.length === 0 ? [] : await this.flegiDb`
|
|
215
|
+
WITH unique_stats AS (
|
|
216
|
+
SELECT
|
|
217
|
+
num,
|
|
218
|
+
unique_article_id,
|
|
219
|
+
unique_article_source,
|
|
220
|
+
unique_text_cid
|
|
221
|
+
FROM article_num_candidate_stats
|
|
222
|
+
WHERE
|
|
223
|
+
num IN ${this.flegiDb(e)}
|
|
224
|
+
AND candidate_article_count = 1
|
|
225
|
+
AND unique_article_id IS NOT NULL
|
|
226
|
+
AND unique_article_source IS NOT NULL
|
|
227
|
+
AND unique_text_cid IS NOT NULL
|
|
228
|
+
)
|
|
229
|
+
SELECT
|
|
230
|
+
legiarti.legi_id AS id,
|
|
231
|
+
unique_stats.unique_text_cid AS "textId",
|
|
232
|
+
legiarti.num,
|
|
233
|
+
legiarti.date_debut::text AS "dateDebut",
|
|
234
|
+
legiarti.date_fin::text AS "dateFin"
|
|
235
|
+
FROM unique_stats
|
|
236
|
+
JOIN legiarti
|
|
237
|
+
ON unique_stats.unique_article_source = 'LEGI'
|
|
238
|
+
AND legiarti.legi_id = unique_stats.unique_article_id
|
|
239
|
+
|
|
240
|
+
UNION ALL
|
|
241
|
+
|
|
242
|
+
SELECT
|
|
243
|
+
jorfarti.legi_id AS id,
|
|
244
|
+
unique_stats.unique_text_cid AS "textId",
|
|
245
|
+
jorfarti.num,
|
|
246
|
+
jorfarti.date_debut::text AS "dateDebut",
|
|
247
|
+
jorfarti.date_fin::text AS "dateFin"
|
|
248
|
+
FROM unique_stats
|
|
249
|
+
JOIN jorfarti
|
|
250
|
+
ON unique_stats.unique_article_source = 'JORF'
|
|
251
|
+
AND jorfarti.legi_id = unique_stats.unique_article_id
|
|
252
|
+
`;
|
|
253
|
+
}
|
|
254
|
+
async getActiveArticleRowsByNum(e, t) {
|
|
255
|
+
let n = `${e}\0${t}`, r = this.articleRowsByNumByTextAndDate.get(n);
|
|
256
|
+
if (r === void 0) {
|
|
257
|
+
let t = await this.getContextTextIdsFromTextId(e), i = await this.getActiveArticleRowsForContextTextIds(t);
|
|
258
|
+
r = /* @__PURE__ */ new Map();
|
|
259
|
+
for (let e of i) {
|
|
260
|
+
if (e.num === null) continue;
|
|
261
|
+
let t = r.get(e.num);
|
|
262
|
+
t === void 0 ? r.set(e.num, [e]) : t.push(e);
|
|
263
|
+
}
|
|
264
|
+
this.articleRowsByNumByTextAndDate.set(n, r), this.articleNumsLoadedByTextAndDate.set(n, "all");
|
|
265
|
+
}
|
|
266
|
+
return r;
|
|
267
|
+
}
|
|
268
|
+
async getActiveArticleRowsForContextTextIds(e) {
|
|
269
|
+
return (await this.getActiveArticleRowsForContextTextIdsWithRoots(e)).map((e) => ({
|
|
270
|
+
id: e.id,
|
|
271
|
+
textId: e.textId,
|
|
272
|
+
num: e.num,
|
|
273
|
+
dateDebut: e.dateDebut,
|
|
274
|
+
dateFin: e.dateFin
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
async getActiveArticleRowsForContextTextIdsWithRoots(e) {
|
|
278
|
+
let t = [...new Set(e)], n = t.filter((e) => !this.articleRowsByContextTextId.has(e));
|
|
279
|
+
if (n.length > 0) {
|
|
280
|
+
let e = await this.queryActiveArticleRowsForContextTextIds(n);
|
|
281
|
+
for (let e of n) this.articleRowsByContextTextId.set(e, []);
|
|
282
|
+
for (let t of e) this.articleRowsByContextTextId.get(t.rootTextId)?.push(t);
|
|
283
|
+
}
|
|
284
|
+
return t.flatMap((e) => this.articleRowsByContextTextId.get(e) ?? []).toSorted((e, t) => e.id.localeCompare(t.id));
|
|
285
|
+
}
|
|
286
|
+
async queryActiveArticleRowsForContextTextIds(e, t) {
|
|
287
|
+
if (e.length === 0 || t?.length === 0) return [];
|
|
288
|
+
let n = t === void 0 ? this.flegiDb`` : this.flegiDb`AND num IN ${this.flegiDb(t)}`, r = t === void 0 ? this.flegiDb`` : this.flegiDb`AND legiarti.num IN ${this.flegiDb(t)}`, i = t === void 0 ? this.flegiDb`` : this.flegiDb`AND jorfarti.num IN ${this.flegiDb(t)}`;
|
|
289
|
+
return (await this.flegiDb`
|
|
290
|
+
SELECT DISTINCT ON (article_rows.id, article_rows."textId")
|
|
291
|
+
article_rows.id,
|
|
292
|
+
article_rows."rootTextId",
|
|
293
|
+
article_rows."textId",
|
|
294
|
+
article_rows.num,
|
|
295
|
+
article_rows."dateDebut",
|
|
296
|
+
article_rows."dateFin"
|
|
297
|
+
FROM (
|
|
298
|
+
SELECT
|
|
299
|
+
legi_id AS id,
|
|
300
|
+
context_text_cid AS "rootTextId",
|
|
301
|
+
context_text_cid AS "textId",
|
|
302
|
+
num,
|
|
303
|
+
date_debut::text AS "dateDebut",
|
|
304
|
+
date_fin::text AS "dateFin",
|
|
305
|
+
0 AS priority,
|
|
306
|
+
true AS "hasValidParentPeriod",
|
|
307
|
+
NULL::varchar AS tri_hierarchique,
|
|
308
|
+
legi_id AS order_id
|
|
309
|
+
FROM legiarti
|
|
310
|
+
WHERE
|
|
311
|
+
context_text_cid IN ${this.flegiDb(e)}
|
|
312
|
+
${n}
|
|
313
|
+
|
|
314
|
+
UNION ALL
|
|
315
|
+
|
|
316
|
+
SELECT
|
|
317
|
+
legi_id AS id,
|
|
318
|
+
context_text_cid AS "rootTextId",
|
|
319
|
+
context_text_cid AS "textId",
|
|
320
|
+
num,
|
|
321
|
+
date_debut::text AS "dateDebut",
|
|
322
|
+
date_fin::text AS "dateFin",
|
|
323
|
+
0 AS priority,
|
|
324
|
+
true AS "hasValidParentPeriod",
|
|
325
|
+
NULL::varchar AS tri_hierarchique,
|
|
326
|
+
legi_id AS order_id
|
|
327
|
+
FROM jorfarti
|
|
328
|
+
WHERE
|
|
329
|
+
context_text_cid IN ${this.flegiDb(e)}
|
|
330
|
+
${n}
|
|
331
|
+
|
|
332
|
+
UNION ALL
|
|
333
|
+
|
|
334
|
+
-- Heuristique sur scta uniquement en fallback pour les
|
|
335
|
+
-- rares articles sans CONTEXTE -> TEXTE dans f_legi.
|
|
336
|
+
SELECT
|
|
337
|
+
legiarti.legi_id AS id,
|
|
338
|
+
COALESCE(
|
|
339
|
+
legitext.cid,
|
|
340
|
+
subltree(scta.chemin, 0, 1)::text
|
|
341
|
+
) AS "rootTextId",
|
|
342
|
+
COALESCE(
|
|
343
|
+
legitext.cid,
|
|
344
|
+
subltree(scta.chemin, 0, 1)::text
|
|
345
|
+
) AS "textId",
|
|
346
|
+
legiarti.num,
|
|
347
|
+
legiarti.date_debut::text AS "dateDebut",
|
|
348
|
+
legiarti.date_fin::text AS "dateFin",
|
|
349
|
+
1 AS priority,
|
|
350
|
+
(scta.parents_valid_period IS NOT NULL AND NOT isempty(scta.parents_valid_period)) AS "hasValidParentPeriod",
|
|
351
|
+
scta.tri_hierarchique,
|
|
352
|
+
legiarti.legi_id AS order_id
|
|
353
|
+
FROM article_location_diffs
|
|
354
|
+
JOIN legiarti
|
|
355
|
+
ON legiarti.legi_id = article_location_diffs.article_id
|
|
356
|
+
JOIN scta
|
|
357
|
+
ON scta.dernier_segment = legiarti.legi_id
|
|
358
|
+
AND scta.type_objet = 'art'
|
|
359
|
+
LEFT JOIN legitext
|
|
360
|
+
ON legitext.legi_id = subltree(scta.chemin, 0, 1)::text
|
|
361
|
+
WHERE
|
|
362
|
+
article_location_diffs.diff_type = 'missing_from_contexte'
|
|
363
|
+
AND COALESCE(
|
|
364
|
+
legitext.cid,
|
|
365
|
+
subltree(scta.chemin, 0, 1)::text
|
|
366
|
+
) IN ${this.flegiDb(e)}
|
|
367
|
+
${r}
|
|
368
|
+
|
|
369
|
+
UNION ALL
|
|
370
|
+
|
|
371
|
+
SELECT
|
|
372
|
+
jorfarti.legi_id AS id,
|
|
373
|
+
COALESCE(
|
|
374
|
+
jorftext.cid,
|
|
375
|
+
subltree(scta.chemin, 0, 1)::text
|
|
376
|
+
) AS "rootTextId",
|
|
377
|
+
COALESCE(
|
|
378
|
+
jorftext.cid,
|
|
379
|
+
subltree(scta.chemin, 0, 1)::text
|
|
380
|
+
) AS "textId",
|
|
381
|
+
jorfarti.num,
|
|
382
|
+
jorfarti.date_debut::text AS "dateDebut",
|
|
383
|
+
jorfarti.date_fin::text AS "dateFin",
|
|
384
|
+
1 AS priority,
|
|
385
|
+
(scta.parents_valid_period IS NOT NULL AND NOT isempty(scta.parents_valid_period)) AS "hasValidParentPeriod",
|
|
386
|
+
scta.tri_hierarchique,
|
|
387
|
+
jorfarti.legi_id AS order_id
|
|
388
|
+
FROM article_location_diffs
|
|
389
|
+
JOIN jorfarti
|
|
390
|
+
ON jorfarti.legi_id = article_location_diffs.article_id
|
|
391
|
+
JOIN scta
|
|
392
|
+
ON scta.dernier_segment = jorfarti.legi_id
|
|
393
|
+
AND scta.type_objet = 'art'
|
|
394
|
+
LEFT JOIN jorftext
|
|
395
|
+
ON jorftext.legi_id = subltree(scta.chemin, 0, 1)::text
|
|
396
|
+
WHERE
|
|
397
|
+
article_location_diffs.diff_type = 'missing_from_contexte'
|
|
398
|
+
AND COALESCE(
|
|
399
|
+
jorftext.cid,
|
|
400
|
+
subltree(scta.chemin, 0, 1)::text
|
|
401
|
+
) IN ${this.flegiDb(e)}
|
|
402
|
+
${i}
|
|
403
|
+
) AS article_rows
|
|
404
|
+
ORDER BY
|
|
405
|
+
article_rows.id,
|
|
406
|
+
article_rows."textId",
|
|
407
|
+
article_rows.priority,
|
|
408
|
+
article_rows."hasValidParentPeriod" DESC,
|
|
409
|
+
article_rows.tri_hierarchique,
|
|
410
|
+
article_rows.order_id
|
|
411
|
+
`).toSorted((e, t) => e.id.localeCompare(t.id));
|
|
412
|
+
}
|
|
413
|
+
async getDirectSectionChildrenByExactParentPath({ date: e, parentPath: t }) {
|
|
414
|
+
return await this.flegiDb`
|
|
415
|
+
SELECT
|
|
416
|
+
dernier_segment AS id,
|
|
417
|
+
chemin::text AS path,
|
|
418
|
+
titre AS title,
|
|
419
|
+
date_debut::text AS "dateDebut",
|
|
420
|
+
date_fin::text AS "dateFin"
|
|
421
|
+
FROM scta
|
|
422
|
+
WHERE
|
|
423
|
+
chemin <@ ${t}::ltree
|
|
424
|
+
AND nlevel(chemin) = nlevel(${t}::ltree) + 1
|
|
425
|
+
AND type_objet = 'scta'
|
|
426
|
+
AND date_debut <= ${e}::date
|
|
427
|
+
AND date_fin >= ${e}::date
|
|
428
|
+
ORDER BY tri_hierarchique
|
|
429
|
+
`;
|
|
430
|
+
}
|
|
431
|
+
async getTextIdFromSegmentIdUsingContextHeuristic(e) {
|
|
432
|
+
if (e.startsWith("LEGIARTI")) return (await this.flegiDb`
|
|
433
|
+
SELECT context_text_cid AS "textId"
|
|
434
|
+
FROM legiarti
|
|
435
|
+
WHERE legi_id = ${e}
|
|
436
|
+
LIMIT 1
|
|
437
|
+
`)[0]?.textId;
|
|
438
|
+
if (e.startsWith("JORFARTI")) return (await this.flegiDb`
|
|
439
|
+
SELECT context_text_cid AS "textId"
|
|
440
|
+
FROM jorfarti
|
|
441
|
+
WHERE legi_id = ${e}
|
|
442
|
+
LIMIT 1
|
|
443
|
+
`)[0]?.textId;
|
|
444
|
+
}
|
|
445
|
+
async getTextIdFromSegmentIdUsingSctaHeuristic(e) {
|
|
446
|
+
return (await this.flegiDb`
|
|
447
|
+
SELECT
|
|
448
|
+
COALESCE(
|
|
449
|
+
legitext.cid,
|
|
450
|
+
jorftext.cid,
|
|
451
|
+
subltree(scta.chemin, 0, 1)::text
|
|
452
|
+
) AS "textId"
|
|
453
|
+
FROM scta
|
|
454
|
+
LEFT JOIN legitext
|
|
455
|
+
ON legitext.legi_id = subltree(scta.chemin, 0, 1)::text
|
|
456
|
+
LEFT JOIN jorftext
|
|
457
|
+
ON jorftext.legi_id = subltree(scta.chemin, 0, 1)::text
|
|
458
|
+
WHERE scta.dernier_segment = ${e}
|
|
459
|
+
ORDER BY
|
|
460
|
+
(scta.parents_valid_period IS NOT NULL AND NOT isempty(scta.parents_valid_period)) DESC,
|
|
461
|
+
scta.date_debut DESC
|
|
462
|
+
LIMIT 1
|
|
463
|
+
`)[0]?.textId;
|
|
464
|
+
}
|
|
465
|
+
async getContextTextIdsFromTextId(e) {
|
|
466
|
+
let t = this.contextTextIdsByTextId.get(e);
|
|
467
|
+
return t === void 0 && (t = (await this.getContextTextIdsByTextIds([e])).get(e) ?? [e], this.contextTextIdsByTextId.set(e, t)), t;
|
|
468
|
+
}
|
|
469
|
+
async getContextTextIdsByTextIds(e) {
|
|
470
|
+
let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.contextTextIdsByTextId.has(e));
|
|
471
|
+
for (let n of e) {
|
|
472
|
+
let e = this.contextTextIdsByTextId.get(n);
|
|
473
|
+
e !== void 0 && t.set(n, e);
|
|
474
|
+
}
|
|
475
|
+
if (n.length === 0) return t;
|
|
476
|
+
for (let e of n) t.set(e, [e]);
|
|
477
|
+
let r = await this.flegiDb`
|
|
478
|
+
SELECT legi_id AS "textId", cid AS "contextTextId"
|
|
479
|
+
FROM legitext
|
|
480
|
+
WHERE legi_id IN ${this.flegiDb(n)} OR cid IN ${this.flegiDb(n)}
|
|
481
|
+
|
|
482
|
+
UNION ALL
|
|
483
|
+
|
|
484
|
+
SELECT legi_id AS "textId", cid AS "contextTextId"
|
|
485
|
+
FROM jorftext
|
|
486
|
+
WHERE legi_id IN ${this.flegiDb(n)} OR cid IN ${this.flegiDb(n)}
|
|
487
|
+
|
|
488
|
+
ORDER BY "textId", "contextTextId"
|
|
489
|
+
`;
|
|
490
|
+
for (let { contextTextId: e, textId: i } of r) for (let r of [i, e]) {
|
|
491
|
+
if (!n.includes(r)) continue;
|
|
492
|
+
let i = t.get(r) ?? [r];
|
|
493
|
+
i.includes(e) || i.push(e), t.set(r, i);
|
|
494
|
+
}
|
|
495
|
+
for (let e of n) this.contextTextIdsByTextId.set(e, t.get(e) ?? [e]);
|
|
496
|
+
return t;
|
|
497
|
+
}
|
|
498
|
+
async getRootTextIdsFromTextId(e) {
|
|
499
|
+
let t = this.rootTextIdsByTextId.get(e);
|
|
500
|
+
return t === void 0 && (t = (await this.getRootTextIdsByTextIds([e])).get(e) ?? [e], this.rootTextIdsByTextId.set(e, t)), t;
|
|
501
|
+
}
|
|
502
|
+
async getRootTextIdsByTextIds(e) {
|
|
503
|
+
let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.rootTextIdsByTextId.has(e));
|
|
504
|
+
for (let n of e) {
|
|
505
|
+
let e = this.rootTextIdsByTextId.get(n);
|
|
506
|
+
e !== void 0 && t.set(n, e);
|
|
507
|
+
}
|
|
508
|
+
if (n.length === 0) return t;
|
|
509
|
+
for (let e of n) t.set(e, [e]);
|
|
510
|
+
let r = await this.flegiDb`
|
|
511
|
+
SELECT cid AS "textId", legi_id AS "rootTextId"
|
|
512
|
+
FROM legitext
|
|
513
|
+
WHERE cid IN ${this.flegiDb(n)}
|
|
514
|
+
|
|
515
|
+
UNION ALL
|
|
516
|
+
|
|
517
|
+
SELECT cid AS "textId", legi_id AS "rootTextId"
|
|
518
|
+
FROM jorftext
|
|
519
|
+
WHERE cid IN ${this.flegiDb(n)}
|
|
520
|
+
|
|
521
|
+
ORDER BY "textId", "rootTextId"
|
|
522
|
+
`;
|
|
523
|
+
for (let { textId: e, rootTextId: n } of r) {
|
|
524
|
+
let r = t.get(e) ?? [e];
|
|
525
|
+
r.includes(n) || r.push(n), t.set(e, r);
|
|
526
|
+
}
|
|
527
|
+
for (let e of n) this.rootTextIdsByTextId.set(e, t.get(e) ?? [e]);
|
|
528
|
+
return t;
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
//#endregion
|
|
532
|
+
export { o as FlegiResolver, a as checkFlegiResolverDatabase };
|