@lde/search-pipeline 0.62.0 → 0.63.0
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/dist/extraction.d.ts +4 -2
- package/dist/extraction.d.ts.map +1 -1
- package/dist/extraction.js +9 -4
- package/dist/search-stages.d.ts.map +1 -1
- package/dist/search-stages.js +90 -26
- package/package.json +4 -4
package/dist/extraction.d.ts
CHANGED
|
@@ -69,8 +69,10 @@ export declare function extractionQuery(searchType: SearchType, schema: SearchSc
|
|
|
69
69
|
export declare function extractionQueryString(searchType: SearchType, schema: SearchSchema, options?: ExtractionOptions): string;
|
|
70
70
|
/**
|
|
71
71
|
* The fields a reference reads off a referent of a target it does not expand
|
|
72
|
-
* `local`ly: the target’s key field, where it is keyed
|
|
73
|
-
*
|
|
72
|
+
* `local`ly: the target’s key field, where it is keyed; – for a `searchable`
|
|
73
|
+
* reference – its label field, by which the reference is searched; and each of
|
|
74
|
+
* the reference’s presence leaves, whose companions say whether any referent
|
|
75
|
+
* holds one. Each field once, though it plays several of these parts.
|
|
74
76
|
*/
|
|
75
77
|
export declare function referentHopFields(field: SearchField, target: RootType): PathField[];
|
|
76
78
|
/** A field the extraction reads off a referent: path-bearing. */
|
package/dist/extraction.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extraction.d.ts","sourceRoot":"","sources":["../src/extraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EAKpB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"extraction.d.ts","sourceRoot":"","sources":["../src/extraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EAKpB,MAAM,2BAA2B,CAAC;AAcnC,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACX,MAAM,aAAa,CAAC;AAQrB,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,iBAAsB,GAC9B,cAAc,CA2BhB;AAED,+EAA+E;AAC/E,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,MAAM,CAER;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,QAAQ,GACf,SAAS,EAAE,CAab;AA+XD,iEAAiE;AACjE,KAAK,SAAS,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/extraction.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AstFactory, } from '@traqula/rules-sparql-1-1';
|
|
2
2
|
import { Parser } from '@traqula/parser-sparql-1-1';
|
|
3
3
|
import { Generator } from '@traqula/generator-sparql-1-1';
|
|
4
|
-
import { endpointFieldOf, fieldNamed, irAlias, isInlineReference, labelFieldOf, localLookupTargetsOf, referencedTargetsOf, referenceTypeNamed, } from '@lde/search/adapter';
|
|
4
|
+
import { endpointFieldOf, fieldNamed, irAlias, isInlineReference, labelFieldOf, localLookupTargetsOf, physicalFields, referencedTargetsOf, referenceTypeNamed, } from '@lde/search/adapter';
|
|
5
5
|
const factory = new AstFactory();
|
|
6
6
|
const parser = new Parser();
|
|
7
7
|
const generator = new Generator();
|
|
@@ -77,17 +77,22 @@ export function extractionQueryString(searchType, schema, options) {
|
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* The fields a reference reads off a referent of a target it does not expand
|
|
80
|
-
* `local`ly: the target’s key field, where it is keyed
|
|
81
|
-
*
|
|
80
|
+
* `local`ly: the target’s key field, where it is keyed; – for a `searchable`
|
|
81
|
+
* reference – its label field, by which the reference is searched; and each of
|
|
82
|
+
* the reference’s presence leaves, whose companions say whether any referent
|
|
83
|
+
* holds one. Each field once, though it plays several of these parts.
|
|
82
84
|
*/
|
|
83
85
|
export function referentHopFields(field, target) {
|
|
84
|
-
|
|
86
|
+
const hopFields = [
|
|
85
87
|
keyedFieldOf(target),
|
|
86
88
|
// `searchSchema` guarantees a searchable reference’s label a path.
|
|
87
89
|
field.searchable === undefined
|
|
88
90
|
? undefined
|
|
89
91
|
: labelFieldOf(target),
|
|
92
|
+
// …and a lookup’s target each presence leaf, with a path.
|
|
93
|
+
...physicalFields(field).leafExists.map(({ leaf }) => fieldNamed(target, leaf)),
|
|
90
94
|
].filter((hopField) => hopField !== undefined);
|
|
95
|
+
return [...new Set(hopFields)];
|
|
91
96
|
}
|
|
92
97
|
/**
|
|
93
98
|
* Walk a type’s path-bearing fields off a subject variable, collecting the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-stages.d.ts","sourceRoot":"","sources":["../src/search-stages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search-stages.d.ts","sourceRoot":"","sources":["../src/search-stages.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,EAEL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,KAAK,QAAQ,EAGb,KAAK,YAAY,EAElB,MAAM,aAAa,CAAC;AAUrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,UAAU,EAAE,QAAQ,CAAC;IACrB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,CAAC;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@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DataFactory } from 'n3';
|
|
1
2
|
import { Distribution } from '@lde/dataset';
|
|
2
3
|
import { SparqlConstructReader, SparqlItemSelector, Stage, } from '@lde/pipeline';
|
|
3
4
|
import { projectRoots, } from '@lde/search';
|
|
4
|
-
import { endpointFieldOf, irAlias, isInlineReference, referencedTargetsOf, referenceTypeNamed, } from '@lde/search/adapter';
|
|
5
|
+
import { endpointFieldOf, irAlias, physicalFields, isInlineReference, referencedTargetsOf, referenceTypeNamed, } from '@lde/search/adapter';
|
|
5
6
|
import { extractionQueryString, referentHopFields } from './extraction.js';
|
|
6
7
|
/**
|
|
7
8
|
* Compose one projecting {@link Stage} per root type – the source side of a
|
|
@@ -235,38 +236,51 @@ export function registrySource(endpoint) {
|
|
|
235
236
|
/** {@link SearchStageType.batchSize} when the type sets none. */
|
|
236
237
|
export const defaultBatchSize = { endpoint: 10, imported: 100 };
|
|
237
238
|
/**
|
|
238
|
-
* A transform passing each referent of the type’s `searchable` references
|
|
239
|
-
* its inline referents’ included
|
|
239
|
+
* A transform passing each referent of the type’s `searchable` references –
|
|
240
|
+
* its inline referents’ included – and of its lookups declaring presence
|
|
241
|
+
* leaves, through its target type’s transforms: the
|
|
240
242
|
* quads the extraction read off the referent ({@link referentHopFields}) go
|
|
241
243
|
* in, and what the target’s transforms make of them comes back in their place.
|
|
244
|
+
* A lookup’s referent named by IRI alone is seeded for its presence leaves,
|
|
245
|
+
* through the type’s own transforms too where the lookup names its own type.
|
|
242
246
|
* `undefined` where no such reference names a target with transforms.
|
|
243
247
|
*
|
|
244
248
|
* The batch is buffered to find the referents, so memory stays bounded by the
|
|
245
249
|
* stage’s `batchSize`.
|
|
246
250
|
*/
|
|
247
251
|
function referentTransforms(searchType, schema, transformsByClass) {
|
|
248
|
-
// Per target with transforms
|
|
249
|
-
// aliases its referents carry. A target’s aliases
|
|
250
|
-
// belongs to two targets.
|
|
252
|
+
// Per target with transforms other than the type itself: the reference
|
|
253
|
+
// fields naming it, and the aliases its referents carry. A target’s aliases
|
|
254
|
+
// are its own, so no quad belongs to two targets.
|
|
251
255
|
const routes = new Map();
|
|
252
|
-
|
|
256
|
+
// Per reference counting presence leaves: the one target (`searchSchema`
|
|
257
|
+
// refuses several) its referents named by IRI alone are seeded through.
|
|
258
|
+
const countedTargetByField = new Map();
|
|
259
|
+
for (const { alias, field } of describedReferences(searchType, schema)) {
|
|
253
260
|
for (const target of referencedTargetsOf(field, schema)) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
aliases: new Set(),
|
|
260
|
-
};
|
|
261
|
-
route.fields.add(alias);
|
|
262
|
-
for (const hopField of referentHopFields(field, target)) {
|
|
263
|
-
route.aliases.add(irAlias(target, hopField));
|
|
264
|
-
}
|
|
265
|
-
routes.set(target, route);
|
|
261
|
+
if (transformsByClass.get(target.class) === undefined) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (physicalFields(field).leafExists.length > 0) {
|
|
265
|
+
countedTargetByField.set(alias, target);
|
|
266
266
|
}
|
|
267
|
+
// A reference to its own type: the type’s transform saw the batch, its
|
|
268
|
+
// referents’ quads included.
|
|
269
|
+
if (target === searchType) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const route = routes.get(target) ?? {
|
|
273
|
+
fields: new Set(),
|
|
274
|
+
aliases: new Set(),
|
|
275
|
+
};
|
|
276
|
+
route.fields.add(alias);
|
|
277
|
+
for (const hopField of referentHopFields(field, target)) {
|
|
278
|
+
route.aliases.add(irAlias(target, hopField));
|
|
279
|
+
}
|
|
280
|
+
routes.set(target, route);
|
|
267
281
|
}
|
|
268
282
|
}
|
|
269
|
-
if (routes.size === 0) {
|
|
283
|
+
if (routes.size === 0 && countedTargetByField.size === 0) {
|
|
270
284
|
return undefined;
|
|
271
285
|
}
|
|
272
286
|
const targetsByField = new Map();
|
|
@@ -281,16 +295,26 @@ function referentTransforms(searchType, schema, transformsByClass) {
|
|
|
281
295
|
}
|
|
282
296
|
return async function* referentTransforms(quads, context) {
|
|
283
297
|
const batch = [];
|
|
298
|
+
// Every node the batch states anything of.
|
|
299
|
+
const subjects = new Set();
|
|
284
300
|
// Each target’s referents in this batch: the objects of the references
|
|
285
|
-
// naming it.
|
|
301
|
+
// naming it – and, by IRI, the ones a presence leaf is counted for.
|
|
286
302
|
const referents = new Map();
|
|
303
|
+
const counted = new Map();
|
|
287
304
|
for await (const quad of quads) {
|
|
288
305
|
batch.push(quad);
|
|
306
|
+
subjects.add(termKey(quad.subject));
|
|
289
307
|
for (const target of targetsByField.get(quad.predicate.value) ?? []) {
|
|
290
308
|
const keys = referents.get(target) ?? new Set();
|
|
291
309
|
keys.add(termKey(quad.object));
|
|
292
310
|
referents.set(target, keys);
|
|
293
311
|
}
|
|
312
|
+
const countedTarget = countedTargetByField.get(quad.predicate.value);
|
|
313
|
+
if (countedTarget !== undefined && quad.object.termType === 'NamedNode') {
|
|
314
|
+
const nodes = counted.get(countedTarget) ?? new Map();
|
|
315
|
+
nodes.set(termKey(quad.object), quad.object);
|
|
316
|
+
counted.set(countedTarget, nodes);
|
|
317
|
+
}
|
|
294
318
|
}
|
|
295
319
|
// One pass sorting each quad into its target’s input, or keeping it.
|
|
296
320
|
const inputs = new Map();
|
|
@@ -306,34 +330,74 @@ function referentTransforms(searchType, schema, transformsByClass) {
|
|
|
306
330
|
yield quad;
|
|
307
331
|
}
|
|
308
332
|
}
|
|
333
|
+
// A referent a presence leaf is counted for, and that its target’s
|
|
334
|
+
// transforms would see nothing of, enters them as `<referent> rdf:type
|
|
335
|
+
// <class>`: a transform describing a node from its key then sees it. A
|
|
336
|
+
// referent of another target is described by its input; one of the type’s
|
|
337
|
+
// own by anything the batch states of it, which the type’s transforms
|
|
338
|
+
// have already seen. The seed itself is not kept.
|
|
339
|
+
const seeds = new Map();
|
|
340
|
+
for (const [target, nodes] of counted) {
|
|
341
|
+
const input = inputs.get(target) ?? [];
|
|
342
|
+
const described = target === searchType
|
|
343
|
+
? subjects
|
|
344
|
+
: new Set(input.map((quad) => termKey(quad.subject)));
|
|
345
|
+
const seeded = new Set();
|
|
346
|
+
for (const [key, node] of nodes) {
|
|
347
|
+
if (!described.has(key)) {
|
|
348
|
+
input.push(factory.quad(node, RDF_TYPE, factory.namedNode(target.class)));
|
|
349
|
+
seeded.add(key);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
seeds.set(target, seeded);
|
|
353
|
+
inputs.set(target, input);
|
|
354
|
+
}
|
|
309
355
|
for (const [target, input] of inputs) {
|
|
356
|
+
if (input.length === 0) {
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
310
359
|
let stream = streamOf(input);
|
|
311
360
|
for (const transform of transformsByClass.get(target.class)) {
|
|
312
361
|
stream = transform(stream, context);
|
|
313
362
|
}
|
|
314
|
-
|
|
363
|
+
const seeded = seeds.get(target);
|
|
364
|
+
for await (const quad of stream) {
|
|
365
|
+
if (seeded?.has(termKey(quad.subject)) &&
|
|
366
|
+
quad.predicate.equals(RDF_TYPE) &&
|
|
367
|
+
quad.object.value === target.class) {
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
yield quad;
|
|
371
|
+
}
|
|
315
372
|
}
|
|
316
373
|
};
|
|
317
374
|
}
|
|
318
|
-
|
|
375
|
+
const factory = DataFactory;
|
|
376
|
+
const RDF_TYPE = factory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
|
|
377
|
+
/** The type’s reference fields whose referents are described – `searchable`
|
|
378
|
+
* ones, and lookups declaring presence leaves – each with the IR Alias whose
|
|
319
379
|
* objects are its referents: its own, and those of the inline referents it
|
|
320
380
|
* nests. A graph that leaves an edge out points at the endpoint through the
|
|
321
381
|
* inline field itself, so an endpoint field is reached through both.
|
|
322
382
|
* `searchSchema` refuses an inline cycle, so the descent ends. */
|
|
323
|
-
function
|
|
383
|
+
function describedReferences(owner, schema) {
|
|
324
384
|
return owner.fields.flatMap((field) => {
|
|
325
385
|
if (isInlineReference(field)) {
|
|
326
386
|
// Guaranteed declared: `searchSchema` resolves every inline `typeName`.
|
|
327
387
|
const referenceType = referenceTypeNamed(schema, field.ref.typeName);
|
|
328
388
|
const endpointField = endpointFieldOf(referenceType, field.ref.identity);
|
|
329
389
|
return [
|
|
330
|
-
...
|
|
390
|
+
...describedReferences(referenceType, schema),
|
|
331
391
|
...(endpointField?.searchable === undefined
|
|
332
392
|
? []
|
|
333
393
|
: [{ alias: irAlias(owner, field), field: endpointField }]),
|
|
334
394
|
];
|
|
335
395
|
}
|
|
336
|
-
|
|
396
|
+
// A reference’s referents are described when it is searched by their
|
|
397
|
+
// labels, or counted for a presence leaf.
|
|
398
|
+
return field.kind === 'reference' &&
|
|
399
|
+
(field.searchable !== undefined ||
|
|
400
|
+
physicalFields(field).leafExists.length > 0)
|
|
337
401
|
? [{ alias: irAlias(owner, field), field }]
|
|
338
402
|
: [];
|
|
339
403
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lde/search-pipeline",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Search indexing as an @lde/pipeline instance: a Writer<Quad> that applies the @lde/search projection to extracted RDF and fans each document out to the transactional engine writer for its type's collection. Glue between the pipeline quad world and the search-engine document world; owns no projection or engine logic itself.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "git+https://github.com/ldelements/lde.git",
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"!**/*.tsbuildinfo"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lde/search": "^0.
|
|
28
|
+
"@lde/search": "^0.49.0",
|
|
29
29
|
"@rdfjs/types": "^2.0.1",
|
|
30
30
|
"@traqula/generator-sparql-1-1": "^1.3.1",
|
|
31
31
|
"@traqula/parser-sparql-1-1": "^1.3.1",
|
|
32
32
|
"@traqula/rules-sparql-1-1": "^1.2.0",
|
|
33
|
+
"n3": "^2.13.12",
|
|
33
34
|
"tslib": "^2.3.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@lde/search-typesense": "^0.
|
|
37
|
-
"n3": "^2.13.12",
|
|
37
|
+
"@lde/search-typesense": "^0.65.0",
|
|
38
38
|
"testcontainers": "^12.1.0",
|
|
39
39
|
"typesense": "^3.2.0"
|
|
40
40
|
},
|