@comunica/actor-rdf-join-inner-multi-bind 2.0.1-alpha.5.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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2017–now Ruben Taelman, Joachim Van Herwegen
4
+ Comunica Association and Ghent University – imec, Belgium
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Comunica Inner Multi-way Bind RDF Join Actor
2
+
3
+ [![npm version](https://badge.fury.io/js/%40comunica%2Factor-rdf-join-inner-multi-bind.svg)](https://www.npmjs.com/package/@comunica/actor-rdf-join-inner-multi-bind)
4
+
5
+ An [RDF Join](https://github.com/comunica/comunica/tree/master/packages/bus-rdf-join) actor that inner-joins 2 or more streams
6
+ by picking the one with the lowest cardinality,
7
+ binding each item with the remaining operations,
8
+ and recursively resolving those operations by delegating to the [Query Operation bus](https://github.com/comunica/comunica/tree/master/packages/bus-query-operation).
9
+
10
+ By default, it will bind in a depth-first manner, but this can be changed to breadth-first iteration if needed.
11
+
12
+ As soon as at least one of the join entries can contain undefined values,
13
+ this actor will maintain the original join order,
14
+ and just pick the first one as the one to bind from.
15
+
16
+ This module is part of the [Comunica framework](https://github.com/comunica/comunica),
17
+ and should only be used by [developers that want to build their own query engine](https://comunica.dev/docs/modify/).
18
+
19
+ [Click here if you just want to query with Comunica](https://comunica.dev/docs/query/).
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ $ yarn add @comunica/actor-rdf-join-inner-multi-bind
25
+ ```
26
+
27
+ ## Configure
28
+
29
+ After installing, this package can be added to your engine's configuration as follows:
30
+ ```text
31
+ {
32
+ "@context": [
33
+ ...
34
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-join-inner-multi-bind/^2.0.0/components/context.jsonld"
35
+ ],
36
+ "actors": [
37
+ ...
38
+ {
39
+ "@id": "urn:comunica:default:rdf-join/actors#inner-multi-bind",
40
+ "@type": "ActorRdfJoinMultiBind",
41
+ "mediatorJoinSelectivity": { "@id": "urn:comunica:default:rdf-join-selectivity/mediators#main" },
42
+ "mediatorQueryOperation": { "@id": "urn:comunica:default:query-operation/mediators#main" }
43
+ }
44
+ ]
45
+ }
46
+ ```
47
+
48
+ ### Config Parameters
49
+
50
+ * `mediatorJoinSelectivity`: A mediator over the [RDF Join Selectivity bus](https://github.com/comunica/comunica/tree/master/packages/bus-rdf-join-selectivity).
51
+ * `bindOrder`: The order in which elements should be bound. _(defaults to `depth-first`, but can also be `breadth-first`)_
52
+ * `mediatorQueryOperation`: A mediator over the [Query Operation bus](https://github.com/comunica/comunica/tree/master/packages/bus-query-operation).
@@ -0,0 +1,268 @@
1
+ {
2
+ "@context": [
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-join-inner-multi-bind/^2.0.0/components/context.jsonld",
4
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^2.0.0/components/context.jsonld",
5
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-rdf-join/^2.0.0/components/context.jsonld"
6
+ ],
7
+ "@id": "npmd:@comunica/actor-rdf-join-inner-multi-bind",
8
+ "components": [
9
+ {
10
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind",
11
+ "@type": "Class",
12
+ "requireElement": "ActorRdfJoinMultiBind",
13
+ "extends": [
14
+ "cbrj:components/ActorRdfJoin.jsonld#ActorRdfJoin"
15
+ ],
16
+ "comment": "A comunica Multi-way Bind RDF Join Actor.",
17
+ "parameters": [
18
+ {
19
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bindOrder",
20
+ "range": {
21
+ "@type": "ParameterRangeUnion",
22
+ "parameterRangeElements": [
23
+ {
24
+ "@type": "ParameterRangeLiteral",
25
+ "parameterRangeValueLiteral": "depth-first"
26
+ },
27
+ {
28
+ "@type": "ParameterRangeLiteral",
29
+ "parameterRangeValueLiteral": "breadth-first"
30
+ }
31
+ ]
32
+ },
33
+ "default": "depth-first",
34
+ "comment": "The order in which elements should be bound"
35
+ },
36
+ {
37
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_selectivityModifier",
38
+ "range": "xsd:double",
39
+ "default": "0.0001",
40
+ "comment": "Multiplier for selectivity values"
41
+ },
42
+ {
43
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorQueryOperation",
44
+ "range": "cc:components/Mediator.jsonld#Mediator",
45
+ "comment": "The query operation mediator"
46
+ },
47
+ {
48
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorJoinSelectivity",
49
+ "range": "cc:components/Mediator.jsonld#Mediator"
50
+ },
51
+ {
52
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_name",
53
+ "range": "xsd:string",
54
+ "default": {
55
+ "@id": "rdf:subject"
56
+ },
57
+ "comment": "The name for this actor."
58
+ },
59
+ {
60
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bus",
61
+ "range": {
62
+ "@type": "ParameterRangeGenericComponent",
63
+ "component": "cc:components/Bus.jsonld#Bus",
64
+ "genericTypeInstances": [
65
+ {
66
+ "@type": "ParameterRangeGenericComponent",
67
+ "component": "cc:components/Actor.jsonld#Actor",
68
+ "genericTypeInstances": [
69
+ {
70
+ "@type": "ParameterRangeGenericTypeReference",
71
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
72
+ },
73
+ {
74
+ "@type": "ParameterRangeGenericTypeReference",
75
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
76
+ },
77
+ {
78
+ "@type": "ParameterRangeGenericTypeReference",
79
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
80
+ }
81
+ ]
82
+ },
83
+ {
84
+ "@type": "ParameterRangeGenericTypeReference",
85
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
86
+ },
87
+ {
88
+ "@type": "ParameterRangeGenericTypeReference",
89
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
90
+ },
91
+ {
92
+ "@type": "ParameterRangeGenericTypeReference",
93
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
94
+ }
95
+ ]
96
+ },
97
+ "default": {
98
+ "@id": "cbrj:components/ActorRdfJoin.jsonld#ActorRdfJoin_default_bus",
99
+ "@type": "cc:components/Bus.jsonld#Bus"
100
+ },
101
+ "comment": "The bus this actor subscribes to."
102
+ },
103
+ {
104
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_beforeActors",
105
+ "range": {
106
+ "@type": "ParameterRangeUnion",
107
+ "parameterRangeElements": [
108
+ {
109
+ "@type": "ParameterRangeArray",
110
+ "parameterRangeValue": {
111
+ "@type": "ParameterRangeGenericComponent",
112
+ "component": "cc:components/Actor.jsonld#Actor",
113
+ "genericTypeInstances": [
114
+ {
115
+ "@type": "ParameterRangeGenericTypeReference",
116
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
117
+ },
118
+ {
119
+ "@type": "ParameterRangeGenericTypeReference",
120
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
121
+ },
122
+ {
123
+ "@type": "ParameterRangeGenericTypeReference",
124
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
125
+ }
126
+ ]
127
+ }
128
+ },
129
+ {
130
+ "@type": "ParameterRangeUndefined"
131
+ }
132
+ ]
133
+ },
134
+ "comment": "Actor that must be registered in the bus before this actor."
135
+ }
136
+ ],
137
+ "memberFields": [
138
+ {
139
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_bindOrder",
140
+ "memberFieldName": "bindOrder",
141
+ "range": {
142
+ "@type": "ParameterRangeUnion",
143
+ "parameterRangeElements": [
144
+ {
145
+ "@type": "ParameterRangeLiteral",
146
+ "parameterRangeValueLiteral": "depth-first"
147
+ },
148
+ {
149
+ "@type": "ParameterRangeLiteral",
150
+ "parameterRangeValueLiteral": "breadth-first"
151
+ }
152
+ ]
153
+ }
154
+ },
155
+ {
156
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_selectivityModifier",
157
+ "memberFieldName": "selectivityModifier",
158
+ "range": "xsd:number"
159
+ },
160
+ {
161
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_mediatorQueryOperation",
162
+ "memberFieldName": "mediatorQueryOperation",
163
+ "range": "cc:components/Mediator.jsonld#Mediator"
164
+ },
165
+ {
166
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_FACTORY",
167
+ "memberFieldName": "FACTORY",
168
+ "range": {
169
+ "@type": "ParameterRangeWildcard"
170
+ }
171
+ },
172
+ {
173
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_constructor",
174
+ "memberFieldName": "constructor"
175
+ },
176
+ {
177
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_createBindStream",
178
+ "memberFieldName": "createBindStream"
179
+ },
180
+ {
181
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_getLeftEntryIndex",
182
+ "memberFieldName": "getLeftEntryIndex"
183
+ },
184
+ {
185
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_getOutput",
186
+ "memberFieldName": "getOutput"
187
+ },
188
+ {
189
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind__member_getJoinCoefficients",
190
+ "memberFieldName": "getJoinCoefficients"
191
+ }
192
+ ],
193
+ "constructorArguments": [
194
+ {
195
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args__constructorArgument",
196
+ "fields": [
197
+ {
198
+ "keyRaw": "bindOrder",
199
+ "value": {
200
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bindOrder"
201
+ }
202
+ },
203
+ {
204
+ "keyRaw": "selectivityModifier",
205
+ "value": {
206
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_selectivityModifier"
207
+ }
208
+ },
209
+ {
210
+ "keyRaw": "mediatorQueryOperation",
211
+ "value": {
212
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorQueryOperation"
213
+ }
214
+ },
215
+ {
216
+ "keyRaw": "mediatorJoinSelectivity",
217
+ "value": {
218
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorJoinSelectivity"
219
+ }
220
+ },
221
+ {
222
+ "keyRaw": "name",
223
+ "value": {
224
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_name"
225
+ }
226
+ },
227
+ {
228
+ "keyRaw": "bus",
229
+ "value": {
230
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bus"
231
+ }
232
+ },
233
+ {
234
+ "keyRaw": "beforeActors",
235
+ "value": {
236
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_beforeActors"
237
+ }
238
+ }
239
+ ]
240
+ }
241
+ ]
242
+ },
243
+ {
244
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs",
245
+ "@type": "AbstractClass",
246
+ "requireElement": "IActorRdfJoinMultiBindArgs",
247
+ "extends": [
248
+ "cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinArgs"
249
+ ],
250
+ "parameters": [],
251
+ "memberFields": [
252
+ {
253
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs__member_bindOrder",
254
+ "memberFieldName": "bindOrder"
255
+ },
256
+ {
257
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs__member_selectivityModifier",
258
+ "memberFieldName": "selectivityModifier"
259
+ },
260
+ {
261
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs__member_mediatorQueryOperation",
262
+ "memberFieldName": "mediatorQueryOperation"
263
+ }
264
+ ],
265
+ "constructorArguments": []
266
+ }
267
+ ]
268
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "@context": [
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-join-inner-multi-bind/^2.0.0/components/context.jsonld"
4
+ ],
5
+ "@id": "npmd:@comunica/actor-rdf-join-inner-multi-bind",
6
+ "@type": "Module",
7
+ "requireName": "@comunica/actor-rdf-join-inner-multi-bind",
8
+ "import": [
9
+ "carjimb:components/ActorRdfJoinMultiBind.jsonld"
10
+ ]
11
+ }
@@ -0,0 +1,64 @@
1
+ {
2
+ "@context": [
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld",
4
+ {
5
+ "npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
6
+ "carjimb": "npmd:@comunica/actor-rdf-join-inner-multi-bind/^2.0.0/",
7
+ "ActorRdfJoinMultiBind": {
8
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind",
9
+ "@prefix": true,
10
+ "@context": {
11
+ "args_bindOrder": {
12
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bindOrder"
13
+ },
14
+ "args_selectivityModifier": {
15
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_selectivityModifier"
16
+ },
17
+ "args_mediatorQueryOperation": {
18
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorQueryOperation"
19
+ },
20
+ "args_mediatorJoinSelectivity": {
21
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorJoinSelectivity"
22
+ },
23
+ "args_name": {
24
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_name"
25
+ },
26
+ "args_bus": {
27
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bus"
28
+ },
29
+ "args_beforeActors": {
30
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_beforeActors",
31
+ "@container": "@list"
32
+ },
33
+ "bindOrder": {
34
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bindOrder"
35
+ },
36
+ "selectivityModifier": {
37
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_selectivityModifier"
38
+ },
39
+ "mediatorQueryOperation": {
40
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorQueryOperation"
41
+ },
42
+ "mediatorJoinSelectivity": {
43
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_mediatorJoinSelectivity"
44
+ },
45
+ "name": {
46
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_name"
47
+ },
48
+ "bus": {
49
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_bus"
50
+ },
51
+ "beforeActors": {
52
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#ActorRdfJoinMultiBind_args_beforeActors",
53
+ "@container": "@list"
54
+ }
55
+ }
56
+ },
57
+ "IActorRdfJoinMultiBindArgs": {
58
+ "@id": "carjimb:components/ActorRdfJoinMultiBind.jsonld#IActorRdfJoinMultiBindArgs",
59
+ "@prefix": true,
60
+ "@context": {}
61
+ }
62
+ }
63
+ ]
64
+ }
@@ -0,0 +1,54 @@
1
+ import type { MediatorQueryOperation } from '@comunica/bus-query-operation';
2
+ import type { IActionRdfJoin, IJoinEntry, IActorRdfJoinOutputInner, IActorRdfJoinArgs } from '@comunica/bus-rdf-join';
3
+ import { ActorRdfJoin } from '@comunica/bus-rdf-join';
4
+ import type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';
5
+ import type { Bindings, BindingsStream, MetadataBindings } from '@comunica/types';
6
+ import { Factory, Algebra } from 'sparqlalgebrajs';
7
+ /**
8
+ * A comunica Multi-way Bind RDF Join Actor.
9
+ */
10
+ export declare class ActorRdfJoinMultiBind extends ActorRdfJoin {
11
+ readonly bindOrder: BindOrder;
12
+ readonly selectivityModifier: number;
13
+ readonly mediatorQueryOperation: MediatorQueryOperation;
14
+ static readonly FACTORY: Factory;
15
+ constructor(args: IActorRdfJoinMultiBindArgs);
16
+ /**
17
+ * Create a new bindings stream that takes every binding of the base stream
18
+ * and binds it to the remaining patterns, evaluates those patterns, and emits all their bindings.
19
+ *
20
+ * @param bindOrder The order in which elements should be bound.
21
+ * @param baseStream The base stream.
22
+ * @param operations The operations to bind with each binding of the base stream.
23
+ * @param operationBinder A callback to retrieve the bindings stream of bound operations.
24
+ * @param optional If the original bindings should be emitted when the resulting bindings stream is empty.
25
+ * @return {BindingsStream}
26
+ */
27
+ static createBindStream(bindOrder: BindOrder, baseStream: BindingsStream, operations: Algebra.Operation[], operationBinder: (boundOperations: Algebra.Operation[], operationBindings: Bindings) => Promise<BindingsStream>, optional: boolean): BindingsStream;
28
+ /**
29
+ * Determine the entry with the lowest cardinality.
30
+ * @param entries Join entries
31
+ * @param metadatas Resolved metadata objects.
32
+ */
33
+ static getLeftEntryIndex(entries: IJoinEntry[], metadatas: MetadataBindings[]): Promise<number>;
34
+ getOutput(action: IActionRdfJoin): Promise<IActorRdfJoinOutputInner>;
35
+ getJoinCoefficients(action: IActionRdfJoin, metadatas: MetadataBindings[]): Promise<IMediatorTypeJoinCoefficients>;
36
+ }
37
+ export interface IActorRdfJoinMultiBindArgs extends IActorRdfJoinArgs {
38
+ /**
39
+ * The order in which elements should be bound
40
+ * @default {depth-first}
41
+ */
42
+ bindOrder: BindOrder;
43
+ /**
44
+ * Multiplier for selectivity values
45
+ * @range {double}
46
+ * @default {0.0001}
47
+ */
48
+ selectivityModifier: number;
49
+ /**
50
+ * The query operation mediator
51
+ */
52
+ mediatorQueryOperation: MediatorQueryOperation;
53
+ }
54
+ export declare type BindOrder = 'depth-first' | 'breadth-first';
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActorRdfJoinMultiBind = void 0;
4
+ const bus_query_operation_1 = require("@comunica/bus-query-operation");
5
+ const bus_rdf_join_1 = require("@comunica/bus-rdf-join");
6
+ const context_entries_1 = require("@comunica/context-entries");
7
+ const asynciterator_1 = require("asynciterator");
8
+ const sparqlalgebrajs_1 = require("sparqlalgebrajs");
9
+ /**
10
+ * A comunica Multi-way Bind RDF Join Actor.
11
+ */
12
+ class ActorRdfJoinMultiBind extends bus_rdf_join_1.ActorRdfJoin {
13
+ constructor(args) {
14
+ super(args, {
15
+ logicalType: 'inner',
16
+ physicalName: 'bind',
17
+ canHandleUndefs: true,
18
+ });
19
+ }
20
+ /**
21
+ * Create a new bindings stream that takes every binding of the base stream
22
+ * and binds it to the remaining patterns, evaluates those patterns, and emits all their bindings.
23
+ *
24
+ * @param bindOrder The order in which elements should be bound.
25
+ * @param baseStream The base stream.
26
+ * @param operations The operations to bind with each binding of the base stream.
27
+ * @param operationBinder A callback to retrieve the bindings stream of bound operations.
28
+ * @param optional If the original bindings should be emitted when the resulting bindings stream is empty.
29
+ * @return {BindingsStream}
30
+ */
31
+ static createBindStream(bindOrder, baseStream, operations, operationBinder, optional) {
32
+ // Create bindings function
33
+ const binder = (bindings) => {
34
+ // We don't bind the filter because filters are always handled last,
35
+ // and we need to avoid binding filters of sub-queries, which are to be handled first. (see spec test bind10)
36
+ const subOperations = operations
37
+ .map(operation => (0, bus_query_operation_1.materializeOperation)(operation, bindings, { bindFilter: false }));
38
+ const bindingsMerger = (subBindings) => subBindings.merge(bindings);
39
+ return new asynciterator_1.TransformIterator(async () => (await operationBinder(subOperations, bindings))
40
+ .transform({ map: bindingsMerger }), { maxBufferSize: 128 });
41
+ };
42
+ // Create an iterator that binds elements from the base stream in different orders
43
+ switch (bindOrder) {
44
+ case 'depth-first':
45
+ return new asynciterator_1.MultiTransformIterator(baseStream, { autoStart: false, multiTransform: binder, optional });
46
+ case 'breadth-first':
47
+ return new asynciterator_1.UnionIterator(baseStream.transform({
48
+ map: binder,
49
+ optional,
50
+ }), { autoStart: false });
51
+ default:
52
+ throw new Error(`Received request for unknown bind order: ${bindOrder}`);
53
+ }
54
+ }
55
+ /**
56
+ * Determine the entry with the lowest cardinality.
57
+ * @param entries Join entries
58
+ * @param metadatas Resolved metadata objects.
59
+ */
60
+ static async getLeftEntryIndex(entries, metadatas) {
61
+ // If there is a stream that can contain undefs, we don't modify the join order and just pick the first one.
62
+ const canContainUndefs = metadatas.some(metadata => metadata.canContainUndefs);
63
+ if (canContainUndefs) {
64
+ return 0;
65
+ }
66
+ // Calculate number of occurrences of each variable
67
+ const variableOccurrences = {};
68
+ for (const metadata of metadatas) {
69
+ for (const variable of metadata.variables) {
70
+ let counter = variableOccurrences[variable.value];
71
+ if (!counter) {
72
+ counter = 0;
73
+ }
74
+ variableOccurrences[variable.value] = ++counter;
75
+ }
76
+ }
77
+ // Determine variables that occur in at least two join entries
78
+ const multiOccurrenceVariables = [];
79
+ for (const [variable, count] of Object.entries(variableOccurrences)) {
80
+ if (count >= 2) {
81
+ multiOccurrenceVariables.push(variable);
82
+ }
83
+ }
84
+ // Reject if no entries have common variables
85
+ if (multiOccurrenceVariables.length === 0) {
86
+ throw new Error(`Bind join can only join entries with at least one common variable`);
87
+ }
88
+ // Determine indexes of entries without common variables
89
+ // These will be blacklisted from lowest cardinality determination
90
+ const indexesWithoutCommonVariables = [];
91
+ for (const [i, metadata] of metadatas.entries()) {
92
+ let hasCommon = false;
93
+ for (const variable of metadata.variables) {
94
+ if (multiOccurrenceVariables.includes(variable.value)) {
95
+ hasCommon = true;
96
+ break;
97
+ }
98
+ }
99
+ if (!hasCommon) {
100
+ indexesWithoutCommonVariables.push(i);
101
+ }
102
+ }
103
+ return bus_rdf_join_1.ActorRdfJoin.getLowestCardinalityIndex(metadatas, indexesWithoutCommonVariables);
104
+ }
105
+ async getOutput(action) {
106
+ // Find the stream with lowest cardinality
107
+ const metadatas = await bus_rdf_join_1.ActorRdfJoin.getMetadatas(action.entries);
108
+ const smallestIndex = await ActorRdfJoinMultiBind.getLeftEntryIndex(action.entries, metadatas);
109
+ this.logDebug(action.context, 'First entry for Bind Join: ', () => ({ entry: action.entries[smallestIndex].operation, metadata: metadatas[smallestIndex] }));
110
+ // Close the non-smallest streams
111
+ for (const [i, element] of action.entries.entries()) {
112
+ if (i !== smallestIndex) {
113
+ element.output.bindingsStream.close();
114
+ }
115
+ }
116
+ // Take the stream with the lowest cardinality
117
+ const smallestStream = action.entries.slice(smallestIndex)[0].output;
118
+ const remainingEntries = [...action.entries];
119
+ remainingEntries.splice(smallestIndex, 1);
120
+ const remainingMetadatas = [...metadatas];
121
+ remainingMetadatas.splice(smallestIndex, 1);
122
+ // Bind the remaining patterns for each binding in the stream
123
+ const subContext = action.context && action.context
124
+ .set(context_entries_1.KeysQueryOperation.joinLeftMetadata, metadatas[smallestIndex])
125
+ .set(context_entries_1.KeysQueryOperation.joinRightMetadatas, remainingMetadatas);
126
+ const bindingsStream = ActorRdfJoinMultiBind.createBindStream(this.bindOrder, smallestStream.bindingsStream, remainingEntries.map(entry => entry.operation), async (operations, operationBindings) => {
127
+ // Send the materialized patterns to the mediator for recursive join evaluation.
128
+ const operation = operations.length === 1 ?
129
+ operations[0] :
130
+ ActorRdfJoinMultiBind.FACTORY.createJoin(operations);
131
+ const output = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({ operation, context: subContext?.set(context_entries_1.KeysQueryOperation.joinBindings, operationBindings) }));
132
+ return output.bindingsStream;
133
+ }, false);
134
+ return {
135
+ result: {
136
+ type: 'bindings',
137
+ bindingsStream,
138
+ metadata: () => this.constructResultMetadata(action.entries, metadatas, action.context),
139
+ },
140
+ physicalPlanMetadata: {
141
+ bindIndex: smallestIndex,
142
+ bindOrder: this.bindOrder,
143
+ },
144
+ };
145
+ }
146
+ async getJoinCoefficients(action, metadatas) {
147
+ const requestInitialTimes = bus_rdf_join_1.ActorRdfJoin.getRequestInitialTimes(metadatas);
148
+ const requestItemTimes = bus_rdf_join_1.ActorRdfJoin.getRequestItemTimes(metadatas);
149
+ // Find the stream with lowest cardinality
150
+ const smallestIndex = await ActorRdfJoinMultiBind.getLeftEntryIndex(action.entries, metadatas);
151
+ // Take the stream with the lowest cardinality
152
+ const remainingEntries = [...action.entries];
153
+ const remainingMetadatas = [...metadatas];
154
+ const remainingRequestInitialTimes = [...requestInitialTimes];
155
+ const remainingRequestItemTimes = [...requestItemTimes];
156
+ remainingEntries.splice(smallestIndex, 1);
157
+ remainingMetadatas.splice(smallestIndex, 1);
158
+ remainingRequestInitialTimes.splice(smallestIndex, 1);
159
+ remainingRequestItemTimes.splice(smallestIndex, 1);
160
+ // Reject binding on some operation types
161
+ if (remainingEntries
162
+ .some(entry => entry.operation.type === sparqlalgebrajs_1.Algebra.types.EXTEND || entry.operation.type === sparqlalgebrajs_1.Algebra.types.GROUP)) {
163
+ throw new Error(`Actor ${this.name} can not bind on Extend and Group operations`);
164
+ }
165
+ // Determine selectivities of smallest entry with all other entries
166
+ const selectivities = await Promise.all(remainingEntries
167
+ .map(async (entry) => (await this.mediatorJoinSelectivity.mediate({
168
+ entries: [
169
+ action.entries[smallestIndex],
170
+ entry,
171
+ ],
172
+ context: action.context,
173
+ })).selectivity * this.selectivityModifier));
174
+ // Determine coefficients for remaining entries
175
+ const cardinalityRemaining = remainingMetadatas
176
+ .map((metadata, i) => metadata.cardinality.value * selectivities[i])
177
+ .reduce((sum, element) => sum + element, 0);
178
+ const receiveInitialCostRemaining = remainingRequestInitialTimes
179
+ .reduce((sum, element, i) => sum + (element * selectivities[i]), 0);
180
+ const receiveItemCostRemaining = remainingRequestItemTimes
181
+ .reduce((sum, element, i) => sum + (element * selectivities[i]), 0);
182
+ return {
183
+ iterations: metadatas[smallestIndex].cardinality.value * cardinalityRemaining,
184
+ persistedItems: 0,
185
+ blockingItems: 0,
186
+ requestTime: requestInitialTimes[smallestIndex] +
187
+ metadatas[smallestIndex].cardinality.value * (requestItemTimes[smallestIndex] +
188
+ receiveInitialCostRemaining +
189
+ cardinalityRemaining * receiveItemCostRemaining),
190
+ };
191
+ }
192
+ }
193
+ exports.ActorRdfJoinMultiBind = ActorRdfJoinMultiBind;
194
+ ActorRdfJoinMultiBind.FACTORY = new sparqlalgebrajs_1.Factory();
195
+ //# sourceMappingURL=ActorRdfJoinMultiBind.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './ActorRdfJoinMultiBind';
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./ActorRdfJoinMultiBind"), exports);
14
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@comunica/actor-rdf-join-inner-multi-bind",
3
+ "version": "2.0.1-alpha.5.0",
4
+ "description": "A multi-bind rdf-join actor",
5
+ "lsd:module": true,
6
+ "main": "lib/index.js",
7
+ "typings": "lib/index",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/comunica/comunica.git",
11
+ "directory": "packages/actor-rdf-join-inner-multi-bind"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "keywords": [
17
+ "comunica",
18
+ "actor",
19
+ "rdf-join",
20
+ "multi-bind"
21
+ ],
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/comunica/comunica/issues"
25
+ },
26
+ "homepage": "https://comunica.dev/",
27
+ "files": [
28
+ "components",
29
+ "lib/**/*.d.ts",
30
+ "lib/**/*.js"
31
+ ],
32
+ "dependencies": {
33
+ "@comunica/bus-query-operation": "2.0.1-alpha.5.0",
34
+ "@comunica/bus-rdf-join": "2.0.1-alpha.5.0",
35
+ "@comunica/context-entries": "2.0.1-alpha.5.0",
36
+ "@comunica/core": "2.0.1-alpha.5.0",
37
+ "asynciterator": "^3.2.1",
38
+ "sparqlalgebrajs": "^4.0.0"
39
+ },
40
+ "scripts": {
41
+ "build": "npm run build:ts && npm run build:components",
42
+ "build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
43
+ "build:components": "componentsjs-generator"
44
+ },
45
+ "gitHead": "e2ae2e9e924bf0656df60cc99774f7e560d47695"
46
+ }