@comunica/actor-rdf-join-inner-multi-bind-source 3.2.4-alpha.47.0 → 3.3.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.
|
@@ -11,13 +11,7 @@
|
|
|
11
11
|
"@type": "Class",
|
|
12
12
|
"requireElement": "ActorRdfJoinMultiBindSource",
|
|
13
13
|
"extends": [
|
|
14
|
-
|
|
15
|
-
"@type": "GenericComponentExtension",
|
|
16
|
-
"component": "cbrj:components/ActorRdfJoin.jsonld#ActorRdfJoin",
|
|
17
|
-
"genericTypeInstances": [
|
|
18
|
-
"carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#IActorRdfJoinMultiBindSourceTestSideData"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
14
|
+
"cbrj:components/ActorRdfJoin.jsonld#ActorRdfJoin"
|
|
21
15
|
],
|
|
22
16
|
"comment": "A comunica Inner Multi Bind Source RDF Join Actor.",
|
|
23
17
|
"parameters": [
|
|
@@ -71,10 +65,6 @@
|
|
|
71
65
|
{
|
|
72
66
|
"@type": "ParameterRangeGenericTypeReference",
|
|
73
67
|
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"@type": "ParameterRangeGenericTypeReference",
|
|
77
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
78
68
|
}
|
|
79
69
|
]
|
|
80
70
|
},
|
|
@@ -89,10 +79,6 @@
|
|
|
89
79
|
{
|
|
90
80
|
"@type": "ParameterRangeGenericTypeReference",
|
|
91
81
|
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"@type": "ParameterRangeGenericTypeReference",
|
|
95
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
96
82
|
}
|
|
97
83
|
]
|
|
98
84
|
},
|
|
@@ -102,20 +88,6 @@
|
|
|
102
88
|
},
|
|
103
89
|
"comment": "The bus this actor subscribes to."
|
|
104
90
|
},
|
|
105
|
-
{
|
|
106
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_busFailMessage",
|
|
107
|
-
"range": {
|
|
108
|
-
"@type": "ParameterRangeUnion",
|
|
109
|
-
"parameterRangeElements": [
|
|
110
|
-
"xsd:string",
|
|
111
|
-
{
|
|
112
|
-
"@type": "ParameterRangeUndefined"
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
},
|
|
116
|
-
"default": "RDF joining failed: none of the configured actors were able to handle the join type ${action.type}",
|
|
117
|
-
"comment": "The message that will be configured in the bus for reporting failures. This message may be a template string that contains references to the executed `action`. For example, the following templated string is allowed: \"RDF dereferencing failed: no actors could handle ${action.handle.mediaType}\""
|
|
118
|
-
},
|
|
119
91
|
{
|
|
120
92
|
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_beforeActors",
|
|
121
93
|
"range": {
|
|
@@ -138,10 +110,6 @@
|
|
|
138
110
|
{
|
|
139
111
|
"@type": "ParameterRangeGenericTypeReference",
|
|
140
112
|
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
"@type": "ParameterRangeGenericTypeReference",
|
|
144
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
145
113
|
}
|
|
146
114
|
]
|
|
147
115
|
}
|
|
@@ -231,12 +199,6 @@
|
|
|
231
199
|
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_bus"
|
|
232
200
|
}
|
|
233
201
|
},
|
|
234
|
-
{
|
|
235
|
-
"keyRaw": "busFailMessage",
|
|
236
|
-
"value": {
|
|
237
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_busFailMessage"
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
202
|
{
|
|
241
203
|
"keyRaw": "beforeActors",
|
|
242
204
|
"value": {
|
|
@@ -252,13 +214,7 @@
|
|
|
252
214
|
"@type": "AbstractClass",
|
|
253
215
|
"requireElement": "IActorRdfJoinInnerMultiBindSourceArgs",
|
|
254
216
|
"extends": [
|
|
255
|
-
|
|
256
|
-
"@type": "GenericComponentExtension",
|
|
257
|
-
"component": "cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinArgs",
|
|
258
|
-
"genericTypeInstances": [
|
|
259
|
-
"carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#IActorRdfJoinMultiBindSourceTestSideData"
|
|
260
|
-
]
|
|
261
|
-
}
|
|
217
|
+
"cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinArgs"
|
|
262
218
|
],
|
|
263
219
|
"parameters": [],
|
|
264
220
|
"memberFields": [
|
|
@@ -276,26 +232,6 @@
|
|
|
276
232
|
}
|
|
277
233
|
],
|
|
278
234
|
"constructorArguments": []
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#IActorRdfJoinMultiBindSourceTestSideData",
|
|
282
|
-
"@type": "AbstractClass",
|
|
283
|
-
"requireElement": "IActorRdfJoinMultiBindSourceTestSideData",
|
|
284
|
-
"extends": [
|
|
285
|
-
"cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinTestSideData"
|
|
286
|
-
],
|
|
287
|
-
"parameters": [],
|
|
288
|
-
"memberFields": [
|
|
289
|
-
{
|
|
290
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#IActorRdfJoinMultiBindSourceTestSideData__member_entriesUnsorted",
|
|
291
|
-
"memberFieldName": "entriesUnsorted"
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#IActorRdfJoinMultiBindSourceTestSideData__member_entriesSorted",
|
|
295
|
-
"memberFieldName": "entriesSorted"
|
|
296
|
-
}
|
|
297
|
-
],
|
|
298
|
-
"constructorArguments": []
|
|
299
235
|
}
|
|
300
236
|
]
|
|
301
237
|
}
|
|
@@ -26,9 +26,6 @@
|
|
|
26
26
|
"args_bus": {
|
|
27
27
|
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_bus"
|
|
28
28
|
},
|
|
29
|
-
"args_busFailMessage": {
|
|
30
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_busFailMessage"
|
|
31
|
-
},
|
|
32
29
|
"args_beforeActors": {
|
|
33
30
|
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_beforeActors",
|
|
34
31
|
"@container": "@list"
|
|
@@ -51,9 +48,6 @@
|
|
|
51
48
|
"bus": {
|
|
52
49
|
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_bus"
|
|
53
50
|
},
|
|
54
|
-
"busFailMessage": {
|
|
55
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_busFailMessage"
|
|
56
|
-
},
|
|
57
51
|
"beforeActors": {
|
|
58
52
|
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#ActorRdfJoinMultiBindSource_args_beforeActors",
|
|
59
53
|
"@container": "@list"
|
|
@@ -64,11 +58,6 @@
|
|
|
64
58
|
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#IActorRdfJoinInnerMultiBindSourceArgs",
|
|
65
59
|
"@prefix": true,
|
|
66
60
|
"@context": {}
|
|
67
|
-
},
|
|
68
|
-
"IActorRdfJoinMultiBindSourceTestSideData": {
|
|
69
|
-
"@id": "carjimbs:components/ActorRdfJoinMultiBindSource.jsonld#IActorRdfJoinMultiBindSourceTestSideData",
|
|
70
|
-
"@prefix": true,
|
|
71
|
-
"@context": {}
|
|
72
61
|
}
|
|
73
62
|
}
|
|
74
63
|
]
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import type { IActionRdfJoin, IActorRdfJoinArgs, IActorRdfJoinOutputInner
|
|
1
|
+
import type { IActionRdfJoin, IActorRdfJoinArgs, IActorRdfJoinOutputInner } from '@comunica/bus-rdf-join';
|
|
2
2
|
import { ActorRdfJoin } from '@comunica/bus-rdf-join';
|
|
3
3
|
import type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-sort';
|
|
4
|
-
import type { TestResult } from '@comunica/core';
|
|
5
4
|
import type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';
|
|
6
|
-
import type { IJoinEntryWithMetadata, IActionContext } from '@comunica/types';
|
|
5
|
+
import type { IJoinEntryWithMetadata, MetadataBindings, IActionContext } from '@comunica/types';
|
|
7
6
|
import type { Algebra } from 'sparqlalgebrajs';
|
|
8
|
-
import { Factory } from 'sparqlalgebrajs';
|
|
9
7
|
/**
|
|
10
8
|
* A comunica Inner Multi Bind Source RDF Join Actor.
|
|
11
9
|
*/
|
|
12
|
-
export declare class ActorRdfJoinMultiBindSource extends ActorRdfJoin
|
|
10
|
+
export declare class ActorRdfJoinMultiBindSource extends ActorRdfJoin {
|
|
13
11
|
readonly selectivityModifier: number;
|
|
14
12
|
readonly blockSize: number;
|
|
15
13
|
readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;
|
|
16
14
|
constructor(args: IActorRdfJoinInnerMultiBindSourceArgs);
|
|
17
|
-
getOutput(action: IActionRdfJoin
|
|
18
|
-
protected sortJoinEntries(entries: IJoinEntryWithMetadata[], context: IActionContext): Promise<
|
|
19
|
-
getJoinCoefficients(action: IActionRdfJoin,
|
|
20
|
-
createOperationFromEntries(
|
|
15
|
+
getOutput(action: IActionRdfJoin): Promise<IActorRdfJoinOutputInner>;
|
|
16
|
+
protected sortJoinEntries(entries: IJoinEntryWithMetadata[], context: IActionContext): Promise<IJoinEntryWithMetadata[]>;
|
|
17
|
+
getJoinCoefficients(action: IActionRdfJoin, metadatas: MetadataBindings[]): Promise<IMediatorTypeJoinCoefficients>;
|
|
18
|
+
createOperationFromEntries(remainingEntries: IJoinEntryWithMetadata[]): Algebra.Operation;
|
|
21
19
|
}
|
|
22
|
-
export interface IActorRdfJoinInnerMultiBindSourceArgs extends IActorRdfJoinArgs
|
|
20
|
+
export interface IActorRdfJoinInnerMultiBindSourceArgs extends IActorRdfJoinArgs {
|
|
23
21
|
/**
|
|
24
22
|
* Multiplier for selectivity values
|
|
25
23
|
* @range {double}
|
|
@@ -36,7 +34,3 @@ export interface IActorRdfJoinInnerMultiBindSourceArgs extends IActorRdfJoinArgs
|
|
|
36
34
|
*/
|
|
37
35
|
mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;
|
|
38
36
|
}
|
|
39
|
-
export interface IActorRdfJoinMultiBindSourceTestSideData extends IActorRdfJoinTestSideData {
|
|
40
|
-
entriesUnsorted: IJoinEntryWithMetadata[];
|
|
41
|
-
entriesSorted: IJoinEntryWithMetadata[];
|
|
42
|
-
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActorRdfJoinMultiBindSource = void 0;
|
|
4
|
+
const bus_query_operation_1 = require("@comunica/bus-query-operation");
|
|
4
5
|
const bus_rdf_join_1 = require("@comunica/bus-rdf-join");
|
|
5
|
-
const context_entries_1 = require("@comunica/context-entries");
|
|
6
|
-
const core_1 = require("@comunica/core");
|
|
7
|
-
const utils_iterator_1 = require("@comunica/utils-iterator");
|
|
8
|
-
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
9
6
|
const asynciterator_1 = require("asynciterator");
|
|
10
7
|
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
8
|
+
const AF = new sparqlalgebrajs_1.Factory();
|
|
11
9
|
/**
|
|
12
10
|
* A comunica Inner Multi Bind Source RDF Join Actor.
|
|
13
11
|
*/
|
|
@@ -19,11 +17,10 @@ class ActorRdfJoinMultiBindSource extends bus_rdf_join_1.ActorRdfJoin {
|
|
|
19
17
|
canHandleUndefs: true,
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
|
-
async getOutput(action
|
|
23
|
-
const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
24
|
-
const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
|
|
20
|
+
async getOutput(action) {
|
|
25
21
|
// Order the entries so we can pick the first one (usually the one with the lowest cardinality)
|
|
26
|
-
const
|
|
22
|
+
const entriesUnsorted = await bus_rdf_join_1.ActorRdfJoin.getEntriesWithMetadatas(action.entries);
|
|
23
|
+
const entries = await this.sortJoinEntries(entriesUnsorted, action.context);
|
|
27
24
|
this.logDebug(action.context, 'First entry for Bind Join Source: ', () => ({ entry: entries[0].operation, metadata: entries[0].metadata }));
|
|
28
25
|
// Close the non-smallest streams
|
|
29
26
|
for (const [i, element] of entries.entries()) {
|
|
@@ -37,11 +34,11 @@ class ActorRdfJoinMultiBindSource extends bus_rdf_join_1.ActorRdfJoin {
|
|
|
37
34
|
const remainingEntries = [...entries];
|
|
38
35
|
remainingEntries.splice(0, 1);
|
|
39
36
|
// Get source for remaining entries (guaranteed thanks to prior check in getJoinCoefficients())
|
|
40
|
-
const sourceWrapper =
|
|
37
|
+
const sourceWrapper = bus_query_operation_1.ActorQueryOperation.getOperationSource(remainingEntries[0].operation);
|
|
41
38
|
// Determine the operation to pass
|
|
42
|
-
const operation = this.createOperationFromEntries(
|
|
39
|
+
const operation = this.createOperationFromEntries(remainingEntries);
|
|
43
40
|
// Slice the smallest stream into chunks according to the block size, so we avoid blocking too long.
|
|
44
|
-
const chunkedStreams = new
|
|
41
|
+
const chunkedStreams = new bus_rdf_join_1.ChunkedIterator(smallestStream.bindingsStream, this.blockSize, { autoStart: false });
|
|
45
42
|
// For each chunk, pass the query and the bindings to the source for execution
|
|
46
43
|
const bindingsStream = new asynciterator_1.UnionIterator(chunkedStreams.map(chunk => sourceWrapper.source.queryBindings(operation, sourceWrapper.context ? action.context.merge(sourceWrapper.context) : action.context, { joinBindings: { bindings: chunk, metadata: smallestMetadata } })));
|
|
47
44
|
return {
|
|
@@ -51,16 +48,12 @@ class ActorRdfJoinMultiBindSource extends bus_rdf_join_1.ActorRdfJoin {
|
|
|
51
48
|
metadata: () => this.constructResultMetadata(entries, entries.map(entry => entry.metadata), action.context),
|
|
52
49
|
},
|
|
53
50
|
physicalPlanMetadata: {
|
|
54
|
-
bindIndex:
|
|
51
|
+
bindIndex: entriesUnsorted.indexOf(entries[0]),
|
|
55
52
|
},
|
|
56
53
|
};
|
|
57
54
|
}
|
|
58
55
|
async sortJoinEntries(entries, context) {
|
|
59
|
-
|
|
60
|
-
if (entriesTest.isFailed()) {
|
|
61
|
-
return entriesTest;
|
|
62
|
-
}
|
|
63
|
-
entries = entriesTest.get();
|
|
56
|
+
entries = await bus_rdf_join_1.ActorRdfJoin.sortJoinEntries(this.mediatorJoinEntriesSort, entries, context);
|
|
64
57
|
// Prioritize entries with modified operations, so these are not re-executed
|
|
65
58
|
entries = entries.sort((entryLeft, entryRight) => {
|
|
66
59
|
if (entryLeft.operationModified && !entryRight.operationModified) {
|
|
@@ -68,68 +61,62 @@ class ActorRdfJoinMultiBindSource extends bus_rdf_join_1.ActorRdfJoin {
|
|
|
68
61
|
}
|
|
69
62
|
return 0;
|
|
70
63
|
});
|
|
71
|
-
return
|
|
64
|
+
return entries;
|
|
72
65
|
}
|
|
73
|
-
async getJoinCoefficients(action,
|
|
74
|
-
let { metadatas } = sideData;
|
|
75
|
-
const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
76
|
-
const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
|
|
66
|
+
async getJoinCoefficients(action, metadatas) {
|
|
77
67
|
// Order the entries so we can pick the first one (usually the one with the lowest cardinality)
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return entriesTest;
|
|
82
|
-
}
|
|
83
|
-
const entriesSorted = entriesTest.get();
|
|
84
|
-
metadatas = entriesSorted.map(entry => entry.metadata);
|
|
68
|
+
const entries = await this.sortJoinEntries(action.entries
|
|
69
|
+
.map((entry, i) => ({ ...entry, metadata: metadatas[i] })), action.context);
|
|
70
|
+
metadatas = entries.map(entry => entry.metadata);
|
|
85
71
|
const requestInitialTimes = bus_rdf_join_1.ActorRdfJoin.getRequestInitialTimes(metadatas);
|
|
86
72
|
const requestItemTimes = bus_rdf_join_1.ActorRdfJoin.getRequestItemTimes(metadatas);
|
|
87
73
|
// Determine first stream and remaining ones
|
|
88
|
-
const remainingEntries = [...
|
|
74
|
+
const remainingEntries = [...entries];
|
|
89
75
|
const remainingRequestInitialTimes = [...requestInitialTimes];
|
|
90
76
|
const remainingRequestItemTimes = [...requestItemTimes];
|
|
91
77
|
remainingEntries.splice(0, 1);
|
|
92
78
|
remainingRequestInitialTimes.splice(0, 1);
|
|
93
79
|
remainingRequestItemTimes.splice(0, 1);
|
|
94
80
|
// Reject binding on operations without sources
|
|
95
|
-
const sources = remainingEntries.map(entry =>
|
|
81
|
+
const sources = remainingEntries.map(entry => bus_query_operation_1.ActorQueryOperation.getOperationSource(entry.operation));
|
|
96
82
|
if (sources.some(source => !source)) {
|
|
97
|
-
|
|
83
|
+
throw new Error(`Actor ${this.name} can not bind on remaining operations without source annotation`);
|
|
98
84
|
}
|
|
99
85
|
// Reject binding on operations with un-equal sources
|
|
100
86
|
if (sources.some(source => source !== sources[0])) {
|
|
101
|
-
|
|
87
|
+
throw new Error(`Actor ${this.name} can not bind on remaining operations with non-equal source annotation`);
|
|
102
88
|
}
|
|
103
89
|
// Reject if the source can not handle bindings
|
|
104
90
|
const sourceWrapper = sources[0];
|
|
105
|
-
const testingOperation = this.createOperationFromEntries(
|
|
91
|
+
const testingOperation = this.createOperationFromEntries(remainingEntries);
|
|
106
92
|
const selectorShape = await sourceWrapper.source.getSelectorShape(action.context);
|
|
107
|
-
if (!
|
|
108
|
-
|
|
93
|
+
if (!bus_query_operation_1.ActorQueryOperation
|
|
94
|
+
.doesShapeAcceptOperation(selectorShape, testingOperation, { joinBindings: true })) {
|
|
95
|
+
throw new Error(`Actor ${this.name} detected a source that can not handle passing down join bindings`);
|
|
109
96
|
}
|
|
110
97
|
// Determine selectivities of smallest entry with all other entries
|
|
111
98
|
const selectivities = await Promise.all(remainingEntries
|
|
112
99
|
.map(async (entry) => (await this.mediatorJoinSelectivity.mediate({
|
|
113
|
-
entries: [
|
|
100
|
+
entries: [entries[0], entry],
|
|
114
101
|
context: action.context,
|
|
115
102
|
})).selectivity * this.selectivityModifier));
|
|
116
103
|
// Determine coefficients for remaining entries
|
|
117
104
|
const cardinalityRemaining = remainingEntries
|
|
118
105
|
.map((entry, i) => entry.metadata.cardinality.value * selectivities[i])
|
|
119
106
|
.reduce((sum, element) => sum + element, 0);
|
|
120
|
-
return
|
|
107
|
+
return {
|
|
121
108
|
iterations: 1,
|
|
122
109
|
persistedItems: metadatas[0].cardinality.value,
|
|
123
110
|
blockingItems: metadatas[0].cardinality.value,
|
|
124
111
|
requestTime: requestInitialTimes[0] + metadatas[0].cardinality.value * requestItemTimes[0] +
|
|
125
112
|
requestInitialTimes[1] + cardinalityRemaining * requestItemTimes[1],
|
|
126
|
-
}
|
|
113
|
+
};
|
|
127
114
|
}
|
|
128
|
-
createOperationFromEntries(
|
|
115
|
+
createOperationFromEntries(remainingEntries) {
|
|
129
116
|
if (remainingEntries.length === 1) {
|
|
130
117
|
return remainingEntries[0].operation;
|
|
131
118
|
}
|
|
132
|
-
return
|
|
119
|
+
return AF.createJoin(remainingEntries.map(entry => entry.operation), true);
|
|
133
120
|
}
|
|
134
121
|
}
|
|
135
122
|
exports.ActorRdfJoinMultiBindSource = ActorRdfJoinMultiBindSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorRdfJoinMultiBindSource.js","sourceRoot":"","sources":["ActorRdfJoinMultiBindSource.ts"],"names":[],"mappings":";;;AAMA,yDAAsD;AAEtD,+DAA0D;AAE1D,yCAA0E;AAS1E,6DAA2D;AAC3D,2EAA+F;AAG/F,iDAA8C;AAE9C,qDAA0C;AAE1C;;GAEG;AACH,MAAa,2BAA4B,SAAQ,2BAAsD;IAKrG,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE;YACV,WAAW,EAAE,OAAO;YACpB,YAAY,EAAE,aAAa;YAC3B,eAAe,EAAE,IAAI;SACtB,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,SAAS,CACpB,MAAsB,EACtB,QAAkD;QAElD,MAAM,WAAW,GAAwB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QAC3F,MAAM,cAAc,GAAG,IAAI,yBAAO,CAAC,WAAW,CAAC,CAAC;QAEhD,+FAA+F;QAC/F,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;QACvC,IAAI,CAAC,QAAQ,CACX,MAAM,CAAC,OAAO,EACd,oCAAoC,EACpC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC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,\n IActorRdfJoinArgs,\n IActorRdfJoinOutputInner,\n IActorRdfJoinTestSideData,\n} from '@comunica/bus-rdf-join';\nimport { ActorRdfJoin } from '@comunica/bus-rdf-join';\nimport type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-sort';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { TestResult } from '@comunica/core';\nimport { passTestWithSideData, failTest, passTest } from '@comunica/core';\nimport type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';\nimport type {\n IJoinEntryWithMetadata,\n IQueryOperationResultBindings,\n IQuerySourceWrapper,\n IActionContext,\n ComunicaDataFactory,\n} from '@comunica/types';\nimport { ChunkedIterator } from '@comunica/utils-iterator';\nimport { doesShapeAcceptOperation, getOperationSource } from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\nimport type { AsyncIterator } from 'asynciterator';\nimport { UnionIterator } from 'asynciterator';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport { Factory } from 'sparqlalgebrajs';\n\n/**\n * A comunica Inner Multi Bind Source RDF Join Actor.\n */\nexport class ActorRdfJoinMultiBindSource extends ActorRdfJoin<IActorRdfJoinMultiBindSourceTestSideData> {\n public readonly selectivityModifier: number;\n public readonly blockSize: number;\n public readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n\n public constructor(args: IActorRdfJoinInnerMultiBindSourceArgs) {\n super(args, {\n logicalType: 'inner',\n physicalName: 'bind-source',\n canHandleUndefs: true,\n });\n }\n\n public async getOutput(\n action: IActionRdfJoin,\n sideData: IActorRdfJoinMultiBindSourceTestSideData,\n ): Promise<IActorRdfJoinOutputInner> {\n const dataFactory: ComunicaDataFactory = action.context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new Factory(dataFactory);\n\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entries = sideData.entriesSorted;\n this.logDebug(\n action.context,\n 'First entry for Bind Join Source: ',\n () => ({ entry: entries[0].operation, metadata: entries[0].metadata }),\n );\n\n // Close the non-smallest streams\n for (const [ i, element ] of entries.entries()) {\n if (i !== 0) {\n element.output.bindingsStream.close();\n }\n }\n\n // Take the stream with the lowest cardinality\n const smallestStream: IQueryOperationResultBindings = entries[0].output;\n const smallestMetadata = entries[0].metadata;\n const remainingEntries = [ ...entries ];\n remainingEntries.splice(0, 1);\n\n // Get source for remaining entries (guaranteed thanks to prior check in getJoinCoefficients())\n const sourceWrapper = <IQuerySourceWrapper> getOperationSource(remainingEntries[0].operation);\n\n // Determine the operation to pass\n const operation = this.createOperationFromEntries(algebraFactory, remainingEntries);\n\n // Slice the smallest stream into chunks according to the block size, so we avoid blocking too long.\n const chunkedStreams: AsyncIterator<AsyncIterator<RDF.Bindings>> = new ChunkedIterator(\n smallestStream.bindingsStream,\n this.blockSize,\n { autoStart: false },\n );\n\n // For each chunk, pass the query and the bindings to the source for execution\n const bindingsStream = new UnionIterator(chunkedStreams.map(chunk => sourceWrapper.source.queryBindings(\n operation,\n sourceWrapper.context ? action.context.merge(sourceWrapper.context) : action.context,\n { joinBindings: { bindings: chunk, metadata: smallestMetadata }},\n )));\n\n return {\n result: {\n type: 'bindings',\n bindingsStream,\n metadata: () => this.constructResultMetadata(entries, entries.map(entry => entry.metadata), action.context),\n },\n physicalPlanMetadata: {\n bindIndex: sideData.entriesUnsorted.indexOf(entries[0]),\n },\n };\n }\n\n protected async sortJoinEntries(\n entries: IJoinEntryWithMetadata[],\n context: IActionContext,\n ): Promise<TestResult<IJoinEntryWithMetadata[]>> {\n const entriesTest = await ActorRdfJoin.sortJoinEntries(this.mediatorJoinEntriesSort, entries, context);\n if (entriesTest.isFailed()) {\n return entriesTest;\n }\n entries = entriesTest.get();\n\n // Prioritize entries with modified operations, so these are not re-executed\n entries = entries.sort((entryLeft, entryRight) => {\n if (entryLeft.operationModified && !entryRight.operationModified) {\n return -1;\n }\n return 0;\n });\n\n return passTest(entries);\n }\n\n public async getJoinCoefficients(\n action: IActionRdfJoin,\n sideData: IActorRdfJoinTestSideData,\n ): Promise<TestResult<IMediatorTypeJoinCoefficients, IActorRdfJoinMultiBindSourceTestSideData>> {\n let { metadatas } = sideData;\n\n const dataFactory: ComunicaDataFactory = action.context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new Factory(dataFactory);\n\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entriesUnsorted = action.entries.map((entry, i) => ({ ...entry, metadata: metadatas[i] }));\n const entriesTest = await this.sortJoinEntries(entriesUnsorted, action.context);\n if (entriesTest.isFailed()) {\n return entriesTest;\n }\n const entriesSorted = entriesTest.get();\n metadatas = entriesSorted.map(entry => entry.metadata);\n\n const requestInitialTimes = ActorRdfJoin.getRequestInitialTimes(metadatas);\n const requestItemTimes = ActorRdfJoin.getRequestItemTimes(metadatas);\n\n // Determine first stream and remaining ones\n const remainingEntries = [ ...entriesSorted ];\n const remainingRequestInitialTimes = [ ...requestInitialTimes ];\n const remainingRequestItemTimes = [ ...requestItemTimes ];\n remainingEntries.splice(0, 1);\n remainingRequestInitialTimes.splice(0, 1);\n remainingRequestItemTimes.splice(0, 1);\n\n // Reject binding on operations without sources\n const sources = remainingEntries.map(entry => getOperationSource(entry.operation));\n if (sources.some(source => !source)) {\n return failTest(`Actor ${this.name} can not bind on remaining operations without source annotation`);\n }\n\n // Reject binding on operations with un-equal sources\n if (sources.some(source => source !== sources[0])) {\n return failTest(`Actor ${this.name} can not bind on remaining operations with non-equal source annotation`);\n }\n\n // Reject if the source can not handle bindings\n const sourceWrapper: IQuerySourceWrapper = <IQuerySourceWrapper> sources[0];\n const testingOperation = this.createOperationFromEntries(algebraFactory, remainingEntries);\n const selectorShape = await sourceWrapper.source.getSelectorShape(action.context);\n if (!doesShapeAcceptOperation(selectorShape, testingOperation, { joinBindings: true })) {\n return failTest(`Actor ${this.name} detected a source that can not handle passing down join bindings`);\n }\n\n // Determine selectivities of smallest entry with all other entries\n const selectivities = await Promise.all(remainingEntries\n .map(async entry => (await this.mediatorJoinSelectivity.mediate({\n entries: [ entriesSorted[0], entry ],\n context: action.context,\n })).selectivity * this.selectivityModifier));\n\n // Determine coefficients for remaining entries\n const cardinalityRemaining = remainingEntries\n .map((entry, i) => entry.metadata.cardinality.value * selectivities[i])\n .reduce((sum, element) => sum + element, 0);\n\n return passTestWithSideData({\n iterations: 1,\n persistedItems: metadatas[0].cardinality.value,\n blockingItems: metadatas[0].cardinality.value,\n requestTime: requestInitialTimes[0] + metadatas[0].cardinality.value * requestItemTimes[0] +\n requestInitialTimes[1] + cardinalityRemaining * requestItemTimes[1],\n }, { ...sideData, entriesUnsorted, entriesSorted });\n }\n\n public createOperationFromEntries(\n algebraFactory: Factory,\n remainingEntries: IJoinEntryWithMetadata[],\n ): Algebra.Operation {\n if (remainingEntries.length === 1) {\n return remainingEntries[0].operation;\n }\n return algebraFactory.createJoin(remainingEntries.map(entry => entry.operation), true);\n }\n}\n\nexport interface IActorRdfJoinInnerMultiBindSourceArgs\n extends IActorRdfJoinArgs<IActorRdfJoinMultiBindSourceTestSideData> {\n /**\n * Multiplier for selectivity values\n * @range {double}\n * @default {0.0001}\n */\n selectivityModifier: number;\n /**\n * The maximum amount of bindings to send to the source per block.\n * @default {16}\n */\n blockSize: number;\n /**\n * The join entries sort mediator\n */\n mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n}\n\nexport interface IActorRdfJoinMultiBindSourceTestSideData extends IActorRdfJoinTestSideData {\n entriesUnsorted: IJoinEntryWithMetadata[];\n entriesSorted: IJoinEntryWithMetadata[];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorRdfJoinMultiBindSource.js","sourceRoot":"","sources":["ActorRdfJoinMultiBindSource.ts"],"names":[],"mappings":";;;AAAA,uEAAoE;AAEpE,yDAAuE;AAYvE,iDAA8C;AAE9C,qDAA0C;AAE1C,MAAM,EAAE,GAAG,IAAI,yBAAO,EAAE,CAAC;AAEzB;;GAEG;AACH,MAAa,2BAA4B,SAAQ,2BAAY;IAK3D,YAAmB,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,OAAO;SACxB,CAAC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAE/C,+CAA+C;QAC/C,MAAM,oBAAoB,GAAG,gBAAgB;aAC1C,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;aACtE,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC;QAE9C,OAAO;YACL,UAAU,EAAE,CAAC;YACb,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK;YAC9C,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK;YAC7C,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC,CAAC;gBACxF,mBAAmB,CAAC,CAAC,CAAC,GAAG,oBAAoB,GAAG,gBAAgB,CAAC,CAAC,CAAC;SACtE,CAAC;IACJ,CAAC;IAEM,0BAA0B,CAAC,gBAA0C;QAC1E,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvC,CAAC;QACD,OAAO,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;CACF;AAzJD,kEAyJC","sourcesContent":["import { ActorQueryOperation } from '@comunica/bus-query-operation';\nimport type { IActionRdfJoin, IActorRdfJoinArgs, IActorRdfJoinOutputInner } from '@comunica/bus-rdf-join';\nimport { ActorRdfJoin, ChunkedIterator } from '@comunica/bus-rdf-join';\nimport type { MediatorRdfJoinEntriesSort } from '@comunica/bus-rdf-join-entries-sort';\nimport type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';\nimport type {\n IJoinEntryWithMetadata,\n IQueryOperationResultBindings,\n IQuerySourceWrapper,\n MetadataBindings,\n IActionContext,\n} from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { AsyncIterator } from 'asynciterator';\nimport { UnionIterator } from 'asynciterator';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport { Factory } from 'sparqlalgebrajs';\n\nconst AF = new Factory();\n\n/**\n * A comunica Inner Multi Bind Source RDF Join Actor.\n */\nexport class ActorRdfJoinMultiBindSource extends ActorRdfJoin {\n public readonly selectivityModifier: number;\n public readonly blockSize: number;\n public readonly mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n\n public constructor(args: IActorRdfJoinInnerMultiBindSourceArgs) {\n super(args, {\n logicalType: 'inner',\n physicalName: 'bind-source',\n canHandleUndefs: true,\n });\n }\n\n public async getOutput(action: IActionRdfJoin): Promise<IActorRdfJoinOutputInner> {\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entriesUnsorted = await ActorRdfJoin.getEntriesWithMetadatas(action.entries);\n const entries = await this.sortJoinEntries(entriesUnsorted, action.context);\n\n this.logDebug(\n action.context,\n 'First entry for Bind Join Source: ',\n () => ({ entry: entries[0].operation, metadata: entries[0].metadata }),\n );\n\n // Close the non-smallest streams\n for (const [ i, element ] of entries.entries()) {\n if (i !== 0) {\n element.output.bindingsStream.close();\n }\n }\n\n // Take the stream with the lowest cardinality\n const smallestStream: IQueryOperationResultBindings = entries[0].output;\n const smallestMetadata = entries[0].metadata;\n const remainingEntries = [ ...entries ];\n remainingEntries.splice(0, 1);\n\n // Get source for remaining entries (guaranteed thanks to prior check in getJoinCoefficients())\n const sourceWrapper: IQuerySourceWrapper = ActorQueryOperation.getOperationSource(remainingEntries[0].operation)!;\n\n // Determine the operation to pass\n const operation = this.createOperationFromEntries(remainingEntries);\n\n // Slice the smallest stream into chunks according to the block size, so we avoid blocking too long.\n const chunkedStreams: AsyncIterator<AsyncIterator<RDF.Bindings>> = new ChunkedIterator(\n smallestStream.bindingsStream,\n this.blockSize,\n { autoStart: false },\n );\n\n // For each chunk, pass the query and the bindings to the source for execution\n const bindingsStream = new UnionIterator(chunkedStreams.map(chunk => sourceWrapper.source.queryBindings(\n operation,\n sourceWrapper.context ? action.context.merge(sourceWrapper.context) : action.context,\n { joinBindings: { bindings: chunk, metadata: smallestMetadata }},\n )));\n\n return {\n result: {\n type: 'bindings',\n bindingsStream,\n metadata: () => this.constructResultMetadata(entries, entries.map(entry => entry.metadata), action.context),\n },\n physicalPlanMetadata: {\n bindIndex: entriesUnsorted.indexOf(entries[0]),\n },\n };\n }\n\n protected async sortJoinEntries(\n entries: IJoinEntryWithMetadata[],\n context: IActionContext,\n ): Promise<IJoinEntryWithMetadata[]> {\n entries = await ActorRdfJoin.sortJoinEntries(this.mediatorJoinEntriesSort, entries, context);\n\n // Prioritize entries with modified operations, so these are not re-executed\n entries = entries.sort((entryLeft, entryRight) => {\n if (entryLeft.operationModified && !entryRight.operationModified) {\n return -1;\n }\n return 0;\n });\n\n return entries;\n }\n\n public async getJoinCoefficients(\n action: IActionRdfJoin,\n metadatas: MetadataBindings[],\n ): Promise<IMediatorTypeJoinCoefficients> {\n // Order the entries so we can pick the first one (usually the one with the lowest cardinality)\n const entries = await this.sortJoinEntries(action.entries\n .map((entry, i) => ({ ...entry, metadata: metadatas[i] })), action.context);\n metadatas = entries.map(entry => entry.metadata);\n\n const requestInitialTimes = ActorRdfJoin.getRequestInitialTimes(metadatas);\n const requestItemTimes = ActorRdfJoin.getRequestItemTimes(metadatas);\n\n // Determine first stream and remaining ones\n const remainingEntries = [ ...entries ];\n const remainingRequestInitialTimes = [ ...requestInitialTimes ];\n const remainingRequestItemTimes = [ ...requestItemTimes ];\n remainingEntries.splice(0, 1);\n remainingRequestInitialTimes.splice(0, 1);\n remainingRequestItemTimes.splice(0, 1);\n\n // Reject binding on operations without sources\n const sources = remainingEntries.map(entry => ActorQueryOperation.getOperationSource(entry.operation));\n if (sources.some(source => !source)) {\n throw new Error(`Actor ${this.name} can not bind on remaining operations without source annotation`);\n }\n\n // Reject binding on operations with un-equal sources\n if (sources.some(source => source !== sources[0])) {\n throw new Error(`Actor ${this.name} can not bind on remaining operations with non-equal source annotation`);\n }\n\n // Reject if the source can not handle bindings\n const sourceWrapper: IQuerySourceWrapper = sources[0]!;\n const testingOperation = this.createOperationFromEntries(remainingEntries);\n const selectorShape = await sourceWrapper.source.getSelectorShape(action.context);\n if (!ActorQueryOperation\n .doesShapeAcceptOperation(selectorShape, testingOperation, { joinBindings: true })) {\n throw new Error(`Actor ${this.name} detected a source that can not handle passing down join bindings`);\n }\n\n // Determine selectivities of smallest entry with all other entries\n const selectivities = await Promise.all(remainingEntries\n .map(async entry => (await this.mediatorJoinSelectivity.mediate({\n entries: [ entries[0], entry ],\n context: action.context,\n })).selectivity * this.selectivityModifier));\n\n // Determine coefficients for remaining entries\n const cardinalityRemaining = remainingEntries\n .map((entry, i) => entry.metadata.cardinality.value * selectivities[i])\n .reduce((sum, element) => sum + element, 0);\n\n return {\n iterations: 1,\n persistedItems: metadatas[0].cardinality.value,\n blockingItems: metadatas[0].cardinality.value,\n requestTime: requestInitialTimes[0] + metadatas[0].cardinality.value * requestItemTimes[0] +\n requestInitialTimes[1] + cardinalityRemaining * requestItemTimes[1],\n };\n }\n\n public createOperationFromEntries(remainingEntries: IJoinEntryWithMetadata[]): Algebra.Operation {\n if (remainingEntries.length === 1) {\n return remainingEntries[0].operation;\n }\n return AF.createJoin(remainingEntries.map(entry => entry.operation), true);\n }\n}\n\nexport interface IActorRdfJoinInnerMultiBindSourceArgs extends IActorRdfJoinArgs {\n /**\n * Multiplier for selectivity values\n * @range {double}\n * @default {0.0001}\n */\n selectivityModifier: number;\n /**\n * The maximum amount of bindings to send to the source per block.\n * @default {16}\n */\n blockSize: number;\n /**\n * The join entries sort mediator\n */\n mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-rdf-join-inner-multi-bind-source",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "A inner-multi-bind-source rdf-join actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"funding": {
|
|
8
|
-
"type": "opencollective",
|
|
9
|
-
"url": "https://opencollective.com/comunica-association"
|
|
10
|
-
},
|
|
11
7
|
"homepage": "https://comunica.dev/",
|
|
12
8
|
"repository": {
|
|
13
9
|
"type": "git",
|
|
@@ -41,16 +37,14 @@
|
|
|
41
37
|
"build:components": "componentsjs-generator"
|
|
42
38
|
},
|
|
43
39
|
"dependencies": {
|
|
44
|
-
"@comunica/bus-
|
|
45
|
-
"@comunica/bus-rdf-join
|
|
46
|
-
"@comunica/
|
|
47
|
-
"@comunica/
|
|
48
|
-
"@comunica/
|
|
49
|
-
"@
|
|
50
|
-
"@comunica/utils-iterator": "3.2.4-alpha.47.0",
|
|
51
|
-
"@comunica/utils-query-operation": "3.2.4-alpha.47.0",
|
|
40
|
+
"@comunica/bus-query-operation": "^3.3.0",
|
|
41
|
+
"@comunica/bus-rdf-join": "^3.3.0",
|
|
42
|
+
"@comunica/bus-rdf-join-entries-sort": "^3.3.0",
|
|
43
|
+
"@comunica/mediatortype-join-coefficients": "^3.3.0",
|
|
44
|
+
"@comunica/types": "^3.3.0",
|
|
45
|
+
"@rdfjs/types": "*",
|
|
52
46
|
"asynciterator": "^3.9.0",
|
|
53
|
-
"sparqlalgebrajs": "^4.3.
|
|
47
|
+
"sparqlalgebrajs": "^4.3.7"
|
|
54
48
|
},
|
|
55
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "02bde397d206f1f5a523643a6a604c89e792e2f9"
|
|
56
50
|
}
|