@comunica/actor-rdf-join-selectivity-variable-counting 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,42 @@
1
+ # Comunica Variable Counting RDF Join Selectivity Actor
2
+
3
+ [![npm version](https://badge.fury.io/js/%40comunica%2Factor-rdf-join-selectivity-variable-counting.svg)](https://www.npmjs.com/package/@comunica/actor-rdf-join-selectivity-variable-counting)
4
+
5
+ An [RDF Join Selectivity](https://github.com/comunica/comunica/tree/master/packages/bus-rdf-join-selectivity) actor
6
+ that heuristically tries to estimate the selectivity of joins by counting the overlap of variables and non-variables
7
+ in patterns.
8
+
9
+ Based on the _"variable counting predicates"_ heuristic from
10
+ [_Stocker, Markus, et al. "SPARQL basic graph pattern optimization using selectivity estimation." Proceedings of the 17th international conference on World Wide Web. 2008._](https://www.semanticscholar.org/paper/SPARQL-basic-graph-pattern-optimization-using-Stocker-Seaborne/da4d7bf764d918f6dfb2b285dfc3e12da7b62b00).
11
+ Implementation inspired by http://www.docjar.com/docs/api/com/hp/hpl/jena/sparql/engine/optimizer/heuristic/VariableCountingUnbound.html.
12
+ This algorithm is extended to also support non-triple-pattern operations and quads.
13
+
14
+ This module is part of the [Comunica framework](https://github.com/comunica/comunica),
15
+ and should only be used by [developers that want to build their own query engine](https://comunica.dev/docs/modify/).
16
+
17
+ [Click here if you just want to query with Comunica](https://comunica.dev/docs/query/).
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ $ yarn add @comunica/actor-rdf-join-selectivity-variable-counting
23
+ ```
24
+
25
+ ## Configure
26
+
27
+ After installing, this package can be added to your engine's configuration as follows:
28
+ ```text
29
+ {
30
+ "@context": [
31
+ ...
32
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-join-selectivity-variable-counting/^2.0.0/components/context.jsonld"
33
+ ],
34
+ "actors": [
35
+ ...
36
+ {
37
+ "@id": "config-sets:join.json#myRdfJoinSelectivityActorVariableCounting",
38
+ "@type": "ActorRdfJoinSelectivityVariableCounting"
39
+ }
40
+ ]
41
+ }
42
+ ```
@@ -0,0 +1,166 @@
1
+ {
2
+ "@context": [
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-join-selectivity-variable-counting/^2.0.0/components/context.jsonld",
4
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-rdf-join-selectivity/^2.0.0/components/context.jsonld",
5
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^2.0.0/components/context.jsonld"
6
+ ],
7
+ "@id": "npmd:@comunica/actor-rdf-join-selectivity-variable-counting",
8
+ "components": [
9
+ {
10
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting",
11
+ "@type": "Class",
12
+ "requireElement": "ActorRdfJoinSelectivityVariableCounting",
13
+ "extends": [
14
+ "cbrjs:components/ActorRdfJoinSelectivity.jsonld#ActorRdfJoinSelectivity"
15
+ ],
16
+ "comment": "A comunica Variable Counting RDF Join Selectivity Actor. Based on the \"variable counting predicates\" heuristic from \"SPARQL basic graph pattern optimization using selectivity estimation.\"",
17
+ "parameters": [
18
+ {
19
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_name",
20
+ "range": "xsd:string",
21
+ "default": {
22
+ "@id": "rdf:subject"
23
+ },
24
+ "comment": "The name for this actor."
25
+ },
26
+ {
27
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_bus",
28
+ "range": {
29
+ "@type": "ParameterRangeGenericComponent",
30
+ "component": "cc:components/Bus.jsonld#Bus",
31
+ "genericTypeInstances": [
32
+ {
33
+ "@type": "ParameterRangeGenericComponent",
34
+ "component": "cc:components/Actor.jsonld#Actor",
35
+ "genericTypeInstances": [
36
+ {
37
+ "@type": "ParameterRangeGenericTypeReference",
38
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
39
+ },
40
+ {
41
+ "@type": "ParameterRangeGenericTypeReference",
42
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
43
+ },
44
+ {
45
+ "@type": "ParameterRangeGenericTypeReference",
46
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ "@type": "ParameterRangeGenericTypeReference",
52
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
53
+ },
54
+ {
55
+ "@type": "ParameterRangeGenericTypeReference",
56
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
57
+ },
58
+ {
59
+ "@type": "ParameterRangeGenericTypeReference",
60
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
61
+ }
62
+ ]
63
+ },
64
+ "default": {
65
+ "@id": "cbrjs:components/ActorRdfJoinSelectivity.jsonld#ActorRdfJoinSelectivity_default_bus",
66
+ "@type": "cc:components/Bus.jsonld#Bus"
67
+ },
68
+ "comment": "The bus this actor subscribes to."
69
+ },
70
+ {
71
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_beforeActors",
72
+ "range": {
73
+ "@type": "ParameterRangeUnion",
74
+ "parameterRangeElements": [
75
+ {
76
+ "@type": "ParameterRangeArray",
77
+ "parameterRangeValue": {
78
+ "@type": "ParameterRangeGenericComponent",
79
+ "component": "cc:components/Actor.jsonld#Actor",
80
+ "genericTypeInstances": [
81
+ {
82
+ "@type": "ParameterRangeGenericTypeReference",
83
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
84
+ },
85
+ {
86
+ "@type": "ParameterRangeGenericTypeReference",
87
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
88
+ },
89
+ {
90
+ "@type": "ParameterRangeGenericTypeReference",
91
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
92
+ }
93
+ ]
94
+ }
95
+ },
96
+ {
97
+ "@type": "ParameterRangeUndefined"
98
+ }
99
+ ]
100
+ },
101
+ "comment": "Actor that must be registered in the bus before this actor."
102
+ }
103
+ ],
104
+ "memberFields": [
105
+ {
106
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_MAX_PAIRWISE_COST",
107
+ "memberFieldName": "MAX_PAIRWISE_COST",
108
+ "range": "xsd:number"
109
+ },
110
+ {
111
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_constructor",
112
+ "memberFieldName": "constructor"
113
+ },
114
+ {
115
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_test",
116
+ "memberFieldName": "test"
117
+ },
118
+ {
119
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_getPatternCost",
120
+ "memberFieldName": "getPatternCost"
121
+ },
122
+ {
123
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_getJoinTypes",
124
+ "memberFieldName": "getJoinTypes"
125
+ },
126
+ {
127
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_getOperationsPairwiseJoinCost",
128
+ "memberFieldName": "getOperationsPairwiseJoinCost"
129
+ },
130
+ {
131
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_getOperationsJoinCost",
132
+ "memberFieldName": "getOperationsJoinCost"
133
+ },
134
+ {
135
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting__member_run",
136
+ "memberFieldName": "run"
137
+ }
138
+ ],
139
+ "constructorArguments": [
140
+ {
141
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args__constructorArgument",
142
+ "fields": [
143
+ {
144
+ "keyRaw": "name",
145
+ "value": {
146
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_name"
147
+ }
148
+ },
149
+ {
150
+ "keyRaw": "bus",
151
+ "value": {
152
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_bus"
153
+ }
154
+ },
155
+ {
156
+ "keyRaw": "beforeActors",
157
+ "value": {
158
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_beforeActors"
159
+ }
160
+ }
161
+ ]
162
+ }
163
+ ]
164
+ }
165
+ ]
166
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "@context": [
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-join-selectivity-variable-counting/^2.0.0/components/context.jsonld"
4
+ ],
5
+ "@id": "npmd:@comunica/actor-rdf-join-selectivity-variable-counting",
6
+ "@type": "Module",
7
+ "requireName": "@comunica/actor-rdf-join-selectivity-variable-counting",
8
+ "import": [
9
+ "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld"
10
+ ]
11
+ }
@@ -0,0 +1,35 @@
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
+ "carjsvc": "npmd:@comunica/actor-rdf-join-selectivity-variable-counting/^2.0.0/",
7
+ "ActorRdfJoinSelectivityVariableCounting": {
8
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting",
9
+ "@prefix": true,
10
+ "@context": {
11
+ "args_name": {
12
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_name"
13
+ },
14
+ "args_bus": {
15
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_bus"
16
+ },
17
+ "args_beforeActors": {
18
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_beforeActors",
19
+ "@container": "@list"
20
+ },
21
+ "name": {
22
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_name"
23
+ },
24
+ "bus": {
25
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_bus"
26
+ },
27
+ "beforeActors": {
28
+ "@id": "carjsvc:components/ActorRdfJoinSelectivityVariableCounting.jsonld#ActorRdfJoinSelectivityVariableCounting_args_beforeActors",
29
+ "@container": "@list"
30
+ }
31
+ }
32
+ }
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,54 @@
1
+ import type { IActionRdfJoinSelectivity, IActorRdfJoinSelectivityOutput } from '@comunica/bus-rdf-join-selectivity';
2
+ import { ActorRdfJoinSelectivity } from '@comunica/bus-rdf-join-selectivity';
3
+ import type { IActorArgs } from '@comunica/core';
4
+ import type { IMediatorTypeAccuracy } from '@comunica/mediatortype-accuracy';
5
+ import { Algebra } from 'sparqlalgebrajs';
6
+ /**
7
+ * A comunica Variable Counting RDF Join Selectivity Actor.
8
+ * Based on the "variable counting predicates" heuristic from
9
+ * "SPARQL basic graph pattern optimization using selectivity estimation."
10
+ */
11
+ export declare class ActorRdfJoinSelectivityVariableCounting extends ActorRdfJoinSelectivity {
12
+ static MAX_PAIRWISE_COST: number;
13
+ constructor(args: IActorArgs<IActionRdfJoinSelectivity, IMediatorTypeAccuracy, IActorRdfJoinSelectivityOutput>);
14
+ test(action: IActionRdfJoinSelectivity): Promise<IMediatorTypeAccuracy>;
15
+ static getPatternCost(pattern: Algebra.Pattern | Algebra.Path): number;
16
+ static getJoinTypes(operation1: Algebra.Pattern | Algebra.Path, operation2: Algebra.Pattern | Algebra.Path): JoinTypes[];
17
+ static getOperationsPairwiseJoinCost(operation1: Algebra.Pattern | Algebra.Path, operation2: Algebra.Pattern | Algebra.Path): number;
18
+ static getOperationsJoinCost(operations: Algebra.Operation[]): number;
19
+ run(action: IActionRdfJoinSelectivity): Promise<IActorRdfJoinSelectivityOutput>;
20
+ }
21
+ export declare enum JoinTypes {
22
+ boundSS = 0,
23
+ boundSP = 1,
24
+ boundSO = 2,
25
+ boundSG = 3,
26
+ boundPS = 4,
27
+ boundPP = 5,
28
+ boundPO = 6,
29
+ boundPG = 7,
30
+ boundOS = 8,
31
+ boundOP = 9,
32
+ boundOO = 10,
33
+ boundOG = 11,
34
+ boundGS = 12,
35
+ boundGP = 13,
36
+ boundGO = 14,
37
+ boundGG = 15,
38
+ unboundSS = 16,
39
+ unboundSP = 17,
40
+ unboundSO = 18,
41
+ unboundSG = 19,
42
+ unboundPS = 20,
43
+ unboundPP = 21,
44
+ unboundPO = 22,
45
+ unboundPG = 23,
46
+ unboundOS = 24,
47
+ unboundOP = 25,
48
+ unboundOO = 26,
49
+ unboundOG = 27,
50
+ unboundGS = 28,
51
+ unboundGP = 29,
52
+ unboundGO = 30,
53
+ unboundGG = 31
54
+ }
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JoinTypes = exports.ActorRdfJoinSelectivityVariableCounting = void 0;
4
+ const bus_rdf_join_selectivity_1 = require("@comunica/bus-rdf-join-selectivity");
5
+ const sparqlalgebrajs_1 = require("sparqlalgebrajs");
6
+ /**
7
+ * A comunica Variable Counting RDF Join Selectivity Actor.
8
+ * Based on the "variable counting predicates" heuristic from
9
+ * "SPARQL basic graph pattern optimization using selectivity estimation."
10
+ */
11
+ class ActorRdfJoinSelectivityVariableCounting extends bus_rdf_join_selectivity_1.ActorRdfJoinSelectivity {
12
+ constructor(args) {
13
+ super(args);
14
+ }
15
+ async test(action) {
16
+ return { accuracy: 0.5 };
17
+ }
18
+ static getPatternCost(pattern) {
19
+ let cost = 1;
20
+ if (pattern.subject.termType === 'Variable') {
21
+ cost += 4;
22
+ }
23
+ if (pattern.predicate.termType === 'Variable' || pattern.type === sparqlalgebrajs_1.Algebra.types.PATH) {
24
+ cost += 1;
25
+ }
26
+ if (pattern.object.termType === 'Variable') {
27
+ cost += 2;
28
+ }
29
+ if (pattern.graph.termType === 'Variable') {
30
+ cost += 1;
31
+ }
32
+ return cost / 9;
33
+ }
34
+ static getJoinTypes(operation1, operation2) {
35
+ const joinTypes = [];
36
+ // Check operation1.subject
37
+ if (operation1.subject.termType === 'Variable') {
38
+ if (operation1.subject.equals(operation2.subject)) {
39
+ joinTypes.push(JoinTypes.unboundSS);
40
+ }
41
+ if (operation2.type === 'pattern' && operation1.subject.equals(operation2.predicate)) {
42
+ joinTypes.push(JoinTypes.unboundSP);
43
+ }
44
+ if (operation1.subject.equals(operation2.object)) {
45
+ joinTypes.push(JoinTypes.unboundSO);
46
+ }
47
+ if (operation1.subject.equals(operation2.graph)) {
48
+ joinTypes.push(JoinTypes.unboundSG);
49
+ }
50
+ }
51
+ else {
52
+ if (operation1.subject.equals(operation2.subject)) {
53
+ joinTypes.push(JoinTypes.boundSS);
54
+ }
55
+ if (operation2.type === 'pattern' && operation1.subject.equals(operation2.predicate)) {
56
+ joinTypes.push(JoinTypes.boundSP);
57
+ }
58
+ if (operation1.subject.equals(operation2.object)) {
59
+ joinTypes.push(JoinTypes.boundSO);
60
+ }
61
+ if (operation1.subject.equals(operation2.graph)) {
62
+ joinTypes.push(JoinTypes.boundSG);
63
+ }
64
+ }
65
+ // Check operation1.predicate
66
+ if (operation1.type === 'pattern') {
67
+ if (operation1.predicate.termType === 'Variable') {
68
+ if (operation1.predicate.equals(operation2.subject)) {
69
+ joinTypes.push(JoinTypes.unboundPS);
70
+ }
71
+ if (operation2.type === 'pattern' && operation1.predicate.equals(operation2.predicate)) {
72
+ joinTypes.push(JoinTypes.unboundPP);
73
+ }
74
+ if (operation1.predicate.equals(operation2.object)) {
75
+ joinTypes.push(JoinTypes.unboundPO);
76
+ }
77
+ if (operation1.predicate.equals(operation2.graph)) {
78
+ joinTypes.push(JoinTypes.unboundPG);
79
+ }
80
+ }
81
+ else {
82
+ if (operation1.predicate.equals(operation2.subject)) {
83
+ joinTypes.push(JoinTypes.boundPS);
84
+ }
85
+ if (operation2.type === 'pattern' && operation1.predicate.equals(operation2.predicate)) {
86
+ joinTypes.push(JoinTypes.boundPP);
87
+ }
88
+ if (operation1.predicate.equals(operation2.object)) {
89
+ joinTypes.push(JoinTypes.boundPO);
90
+ }
91
+ if (operation1.predicate.equals(operation2.graph)) {
92
+ joinTypes.push(JoinTypes.boundPG);
93
+ }
94
+ }
95
+ }
96
+ // Check operation1.object
97
+ if (operation1.object.termType === 'Variable') {
98
+ if (operation1.object.equals(operation2.subject)) {
99
+ joinTypes.push(JoinTypes.unboundOS);
100
+ }
101
+ if (operation2.type === 'pattern' && operation1.object.equals(operation2.predicate)) {
102
+ joinTypes.push(JoinTypes.unboundOP);
103
+ }
104
+ if (operation1.object.equals(operation2.object)) {
105
+ joinTypes.push(JoinTypes.unboundOO);
106
+ }
107
+ if (operation1.object.equals(operation2.graph)) {
108
+ joinTypes.push(JoinTypes.unboundOG);
109
+ }
110
+ }
111
+ else {
112
+ if (operation1.object.equals(operation2.subject)) {
113
+ joinTypes.push(JoinTypes.boundOS);
114
+ }
115
+ if (operation2.type === 'pattern' && operation1.object.equals(operation2.predicate)) {
116
+ joinTypes.push(JoinTypes.boundOP);
117
+ }
118
+ if (operation1.object.equals(operation2.object)) {
119
+ joinTypes.push(JoinTypes.boundOO);
120
+ }
121
+ if (operation1.object.equals(operation2.graph)) {
122
+ joinTypes.push(JoinTypes.boundOG);
123
+ }
124
+ }
125
+ // Check operation1.graph
126
+ if (operation1.graph.termType === 'Variable') {
127
+ if (operation1.graph.equals(operation2.subject)) {
128
+ joinTypes.push(JoinTypes.unboundGS);
129
+ }
130
+ if (operation2.type === 'pattern' && operation1.graph.equals(operation2.predicate)) {
131
+ joinTypes.push(JoinTypes.unboundGP);
132
+ }
133
+ if (operation1.graph.equals(operation2.object)) {
134
+ joinTypes.push(JoinTypes.unboundGO);
135
+ }
136
+ if (operation1.graph.equals(operation2.graph)) {
137
+ joinTypes.push(JoinTypes.unboundGG);
138
+ }
139
+ }
140
+ else {
141
+ if (operation1.graph.equals(operation2.subject)) {
142
+ joinTypes.push(JoinTypes.boundGS);
143
+ }
144
+ if (operation2.type === 'pattern' && operation1.graph.equals(operation2.predicate)) {
145
+ joinTypes.push(JoinTypes.boundGP);
146
+ }
147
+ if (operation1.graph.equals(operation2.object)) {
148
+ joinTypes.push(JoinTypes.boundGO);
149
+ }
150
+ if (operation1.graph.equals(operation2.graph)) {
151
+ joinTypes.push(JoinTypes.boundGG);
152
+ }
153
+ }
154
+ return joinTypes;
155
+ }
156
+ static getOperationsPairwiseJoinCost(operation1, operation2) {
157
+ let cost = ActorRdfJoinSelectivityVariableCounting.MAX_PAIRWISE_COST;
158
+ for (const joinType of ActorRdfJoinSelectivityVariableCounting.getJoinTypes(operation1, operation2)) {
159
+ switch (joinType) {
160
+ case JoinTypes.boundSS:
161
+ cost -= 2 * 2;
162
+ break;
163
+ case JoinTypes.boundSP:
164
+ cost -= 3 * 2;
165
+ break;
166
+ case JoinTypes.boundSO:
167
+ cost -= 1 * 2;
168
+ break;
169
+ case JoinTypes.boundSG:
170
+ cost -= 3 * 2;
171
+ break;
172
+ case JoinTypes.boundPS:
173
+ cost -= 3 * 2;
174
+ break;
175
+ case JoinTypes.boundPP:
176
+ // Special case: patterns with equal (bound) predicates have the highest cost
177
+ return 1;
178
+ case JoinTypes.boundPO:
179
+ cost -= 3 * 2;
180
+ break;
181
+ case JoinTypes.boundPG:
182
+ cost -= 3 * 2;
183
+ break;
184
+ case JoinTypes.boundOS:
185
+ cost -= 1 * 2;
186
+ break;
187
+ case JoinTypes.boundOP:
188
+ cost -= 3 * 2;
189
+ break;
190
+ case JoinTypes.boundOO:
191
+ cost -= 1 * 2;
192
+ break;
193
+ case JoinTypes.boundOG:
194
+ cost -= 3 * 2;
195
+ break;
196
+ case JoinTypes.boundGS:
197
+ cost -= 3 * 2;
198
+ break;
199
+ case JoinTypes.boundGP:
200
+ cost -= 3 * 2;
201
+ break;
202
+ case JoinTypes.boundGO:
203
+ cost -= 3 * 2;
204
+ break;
205
+ case JoinTypes.boundGG:
206
+ cost -= 3 * 2;
207
+ break;
208
+ case JoinTypes.unboundSS:
209
+ cost -= 2;
210
+ break;
211
+ case JoinTypes.unboundSP:
212
+ cost -= 3;
213
+ break;
214
+ case JoinTypes.unboundSO:
215
+ cost -= 1;
216
+ break;
217
+ case JoinTypes.unboundSG:
218
+ cost -= 3;
219
+ break;
220
+ case JoinTypes.unboundPS:
221
+ cost -= 3;
222
+ break;
223
+ case JoinTypes.unboundPP:
224
+ cost -= 3;
225
+ break;
226
+ case JoinTypes.unboundPO:
227
+ cost -= 3;
228
+ break;
229
+ case JoinTypes.unboundPG:
230
+ cost -= 3;
231
+ break;
232
+ case JoinTypes.unboundOS:
233
+ cost -= 1;
234
+ break;
235
+ case JoinTypes.unboundOP:
236
+ cost -= 3;
237
+ break;
238
+ case JoinTypes.unboundOO:
239
+ cost -= 1;
240
+ break;
241
+ case JoinTypes.unboundOG:
242
+ cost -= 3;
243
+ break;
244
+ case JoinTypes.unboundGS:
245
+ cost -= 3;
246
+ break;
247
+ case JoinTypes.unboundGP:
248
+ cost -= 3;
249
+ break;
250
+ case JoinTypes.unboundGO:
251
+ cost -= 3;
252
+ break;
253
+ case JoinTypes.unboundGG:
254
+ cost -= 3;
255
+ break;
256
+ }
257
+ }
258
+ return cost / ActorRdfJoinSelectivityVariableCounting.MAX_PAIRWISE_COST;
259
+ }
260
+ static getOperationsJoinCost(operations) {
261
+ // Determine all operations that select values (patterns and paths)
262
+ const patterns = [];
263
+ for (const operation of operations) {
264
+ sparqlalgebrajs_1.Util.recurseOperation(operation, {
265
+ [sparqlalgebrajs_1.Algebra.types.PATTERN](pattern) {
266
+ patterns.push(pattern);
267
+ return false;
268
+ },
269
+ [sparqlalgebrajs_1.Algebra.types.PATH](path) {
270
+ patterns.push(path);
271
+ return false;
272
+ },
273
+ });
274
+ }
275
+ // Determine pairwise costs
276
+ let totalCost = 0;
277
+ let costEntries = 0;
278
+ for (const pattern1 of patterns) {
279
+ for (const pattern2 of patterns) {
280
+ if (pattern1 !== pattern2) {
281
+ totalCost += ActorRdfJoinSelectivityVariableCounting.getOperationsPairwiseJoinCost(pattern1, pattern2);
282
+ costEntries++;
283
+ }
284
+ }
285
+ }
286
+ // Combine all pairwise costs, and multiply with costs of each pattern separately
287
+ return totalCost / costEntries * patterns
288
+ .reduce((factor, pattern) => factor * ActorRdfJoinSelectivityVariableCounting.getPatternCost(pattern), 1);
289
+ }
290
+ async run(action) {
291
+ if (action.entries.length <= 1) {
292
+ return { selectivity: 1 };
293
+ }
294
+ return {
295
+ selectivity: ActorRdfJoinSelectivityVariableCounting
296
+ .getOperationsJoinCost(action.entries.map(entry => entry.operation)),
297
+ };
298
+ }
299
+ }
300
+ exports.ActorRdfJoinSelectivityVariableCounting = ActorRdfJoinSelectivityVariableCounting;
301
+ // Calculated as sum of unbound join type costs times 2 (best-case)
302
+ ActorRdfJoinSelectivityVariableCounting.MAX_PAIRWISE_COST = 41 * 2;
303
+ var JoinTypes;
304
+ (function (JoinTypes) {
305
+ JoinTypes[JoinTypes["boundSS"] = 0] = "boundSS";
306
+ JoinTypes[JoinTypes["boundSP"] = 1] = "boundSP";
307
+ JoinTypes[JoinTypes["boundSO"] = 2] = "boundSO";
308
+ JoinTypes[JoinTypes["boundSG"] = 3] = "boundSG";
309
+ JoinTypes[JoinTypes["boundPS"] = 4] = "boundPS";
310
+ JoinTypes[JoinTypes["boundPP"] = 5] = "boundPP";
311
+ JoinTypes[JoinTypes["boundPO"] = 6] = "boundPO";
312
+ JoinTypes[JoinTypes["boundPG"] = 7] = "boundPG";
313
+ JoinTypes[JoinTypes["boundOS"] = 8] = "boundOS";
314
+ JoinTypes[JoinTypes["boundOP"] = 9] = "boundOP";
315
+ JoinTypes[JoinTypes["boundOO"] = 10] = "boundOO";
316
+ JoinTypes[JoinTypes["boundOG"] = 11] = "boundOG";
317
+ JoinTypes[JoinTypes["boundGS"] = 12] = "boundGS";
318
+ JoinTypes[JoinTypes["boundGP"] = 13] = "boundGP";
319
+ JoinTypes[JoinTypes["boundGO"] = 14] = "boundGO";
320
+ JoinTypes[JoinTypes["boundGG"] = 15] = "boundGG";
321
+ JoinTypes[JoinTypes["unboundSS"] = 16] = "unboundSS";
322
+ JoinTypes[JoinTypes["unboundSP"] = 17] = "unboundSP";
323
+ JoinTypes[JoinTypes["unboundSO"] = 18] = "unboundSO";
324
+ JoinTypes[JoinTypes["unboundSG"] = 19] = "unboundSG";
325
+ JoinTypes[JoinTypes["unboundPS"] = 20] = "unboundPS";
326
+ JoinTypes[JoinTypes["unboundPP"] = 21] = "unboundPP";
327
+ JoinTypes[JoinTypes["unboundPO"] = 22] = "unboundPO";
328
+ JoinTypes[JoinTypes["unboundPG"] = 23] = "unboundPG";
329
+ JoinTypes[JoinTypes["unboundOS"] = 24] = "unboundOS";
330
+ JoinTypes[JoinTypes["unboundOP"] = 25] = "unboundOP";
331
+ JoinTypes[JoinTypes["unboundOO"] = 26] = "unboundOO";
332
+ JoinTypes[JoinTypes["unboundOG"] = 27] = "unboundOG";
333
+ JoinTypes[JoinTypes["unboundGS"] = 28] = "unboundGS";
334
+ JoinTypes[JoinTypes["unboundGP"] = 29] = "unboundGP";
335
+ JoinTypes[JoinTypes["unboundGO"] = 30] = "unboundGO";
336
+ JoinTypes[JoinTypes["unboundGG"] = 31] = "unboundGG";
337
+ })(JoinTypes = exports.JoinTypes || (exports.JoinTypes = {}));
338
+ //# sourceMappingURL=ActorRdfJoinSelectivityVariableCounting.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './ActorRdfJoinSelectivityVariableCounting';
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("./ActorRdfJoinSelectivityVariableCounting"), exports);
14
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@comunica/actor-rdf-join-selectivity-variable-counting",
3
+ "version": "2.0.1-alpha.5.0",
4
+ "description": "A variable-counting rdf-join-selectivity 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-selectivity-variable-counting"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "keywords": [
17
+ "comunica",
18
+ "actor",
19
+ "rdf-join-selectivity",
20
+ "variable-counting"
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-rdf-join-selectivity": "2.0.1-alpha.5.0",
34
+ "@comunica/core": "2.0.1-alpha.5.0",
35
+ "sparqlalgebrajs": "^4.0.0"
36
+ },
37
+ "scripts": {
38
+ "build": "npm run build:ts && npm run build:components",
39
+ "build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
40
+ "build:components": "componentsjs-generator"
41
+ },
42
+ "gitHead": "e2ae2e9e924bf0656df60cc99774f7e560d47695"
43
+ }