@comunica/actor-query-operation-from-quad 5.2.3 → 5.4.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.
|
@@ -160,6 +160,10 @@
|
|
|
160
160
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_copyOperation",
|
|
161
161
|
"memberFieldName": "copyOperation"
|
|
162
162
|
},
|
|
163
|
+
{
|
|
164
|
+
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_copyMetadata",
|
|
165
|
+
"memberFieldName": "copyMetadata"
|
|
166
|
+
},
|
|
163
167
|
{
|
|
164
168
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_applyOperationDefaultGraph",
|
|
165
169
|
"memberFieldName": "applyOperationDefaultGraph"
|
|
@@ -168,6 +172,10 @@
|
|
|
168
172
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_applyOperationNamedGraph",
|
|
169
173
|
"memberFieldName": "applyOperationNamedGraph"
|
|
170
174
|
},
|
|
175
|
+
{
|
|
176
|
+
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_applyNamedGraphToPattern",
|
|
177
|
+
"memberFieldName": "applyNamedGraphToPattern"
|
|
178
|
+
},
|
|
171
179
|
{
|
|
172
180
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_joinOperations",
|
|
173
181
|
"memberFieldName": "joinOperations"
|
|
@@ -12,11 +12,23 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
12
12
|
constructor(args: IActorQueryOperationTypedMediatedArgs);
|
|
13
13
|
/**
|
|
14
14
|
* Create a deep copy of the given operation.
|
|
15
|
+
*
|
|
16
|
+
* The graph transformations of this actor no longer use this: they let an algebra traversal copy the
|
|
17
|
+
* operations they rewrite. It is part of the public API of this actor though, so it stays.
|
|
15
18
|
* @param {Operation} operation An operation.
|
|
16
19
|
* @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.
|
|
17
20
|
* @return {Operation} The copied operation.
|
|
18
21
|
*/
|
|
19
22
|
static copyOperation(operation: Algebra.Operation, recursiveCb: (subOperation: Algebra.Operation) => Algebra.Operation): Algebra.Operation;
|
|
23
|
+
/**
|
|
24
|
+
* Copy the metadata of the given original operation onto the given new operation.
|
|
25
|
+
* This is required because operations are recreated with a different graph in this actor,
|
|
26
|
+
* and the metadata may contain information that must be retained, such as the source annotation.
|
|
27
|
+
* @param {Operation} operationNew The new operation to copy the metadata to. This operation is mutated.
|
|
28
|
+
* @param {Operation} operationOriginal The original operation to copy the metadata from.
|
|
29
|
+
* @return {Operation} The new operation.
|
|
30
|
+
*/
|
|
31
|
+
static copyMetadata<O extends Algebra.Operation>(operationNew: O, operationOriginal: Algebra.Operation): O;
|
|
20
32
|
/**
|
|
21
33
|
* Recursively transform the given operation to use the given graphs as default graph
|
|
22
34
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
@@ -33,11 +45,20 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
33
45
|
* @package
|
|
34
46
|
* @param algebraFactory The algebra factory.
|
|
35
47
|
* @param {Operation} operation An operation.
|
|
36
|
-
* @param {RDF.Term[]} namedGraphs Graph terms.
|
|
37
|
-
* @param {RDF.Term[]} defaultGraphs Default graph terms.
|
|
48
|
+
* @param {RDF.Term[]} namedGraphs Graph terms, as defined by FROM NAMED.
|
|
49
|
+
* @param {RDF.Term[]} defaultGraphs Default graph terms, as defined by FROM.
|
|
38
50
|
* @return {Operation} A new operation.
|
|
39
51
|
*/
|
|
40
52
|
static applyOperationNamedGraph(algebraFactory: AlgebraFactory, operation: Algebra.Operation, namedGraphs: RDF.NamedNode[], defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
53
|
+
/**
|
|
54
|
+
* Transform a single BGP, quad pattern or property path to use the given graphs as named graph.
|
|
55
|
+
* @param algebraFactory The algebra factory.
|
|
56
|
+
* @param operation A BGP, quad pattern or property path operation.
|
|
57
|
+
* @param {RDF.Term[]} namedGraphs Graph terms, as defined by FROM NAMED.
|
|
58
|
+
* @param {RDF.Term[]} defaultGraphs Default graph terms, as defined by FROM.
|
|
59
|
+
* @return {Operation} A new operation.
|
|
60
|
+
*/
|
|
61
|
+
private static applyNamedGraphToPattern;
|
|
41
62
|
/**
|
|
42
63
|
* Transform the given array of operations into a join operation.
|
|
43
64
|
* @package
|
|
@@ -15,11 +15,15 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Create a deep copy of the given operation.
|
|
18
|
+
*
|
|
19
|
+
* The graph transformations of this actor no longer use this: they let an algebra traversal copy the
|
|
20
|
+
* operations they rewrite. It is part of the public API of this actor though, so it stays.
|
|
18
21
|
* @param {Operation} operation An operation.
|
|
19
22
|
* @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.
|
|
20
23
|
* @return {Operation} The copied operation.
|
|
21
24
|
*/
|
|
22
25
|
static copyOperation(operation, recursiveCb) {
|
|
26
|
+
// TODO (next major): can be removed
|
|
23
27
|
const copiedOperation = {};
|
|
24
28
|
for (const [key, value] of Object.entries(operation)) {
|
|
25
29
|
const castedKey = key;
|
|
@@ -41,6 +45,20 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
41
45
|
}
|
|
42
46
|
return copiedOperation;
|
|
43
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Copy the metadata of the given original operation onto the given new operation.
|
|
50
|
+
* This is required because operations are recreated with a different graph in this actor,
|
|
51
|
+
* and the metadata may contain information that must be retained, such as the source annotation.
|
|
52
|
+
* @param {Operation} operationNew The new operation to copy the metadata to. This operation is mutated.
|
|
53
|
+
* @param {Operation} operationOriginal The original operation to copy the metadata from.
|
|
54
|
+
* @return {Operation} The new operation.
|
|
55
|
+
*/
|
|
56
|
+
static copyMetadata(operationNew, operationOriginal) {
|
|
57
|
+
if (operationOriginal.metadata) {
|
|
58
|
+
operationNew.metadata = operationOriginal.metadata;
|
|
59
|
+
}
|
|
60
|
+
return operationNew;
|
|
61
|
+
}
|
|
44
62
|
/**
|
|
45
63
|
* Recursively transform the given operation to use the given graphs as default graph
|
|
46
64
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
@@ -51,34 +69,47 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
51
69
|
* @return {Operation} A new operation.
|
|
52
70
|
*/
|
|
53
71
|
static applyOperationDefaultGraph(algebraFactory, operation, defaultGraphs) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
return utils_algebra_1.algebraUtils.mapOperation(operation, {
|
|
73
|
+
[utils_algebra_1.Algebra.Types.BGP]: {
|
|
74
|
+
preVisitor: () => ({ continue: false, copy: false }),
|
|
75
|
+
transform: (bgp) => {
|
|
76
|
+
if (bgp.patterns.length === 0) {
|
|
77
|
+
return bgp;
|
|
78
|
+
}
|
|
79
|
+
return ActorQueryOperationFromQuad
|
|
80
|
+
.joinOperations(algebraFactory, bgp.patterns.map((pattern) => {
|
|
81
|
+
if (pattern.graph.termType !== 'DefaultGraph') {
|
|
82
|
+
return algebraFactory.createBgp([pattern]);
|
|
83
|
+
}
|
|
84
|
+
const bgps = defaultGraphs.map((graph) => algebraFactory.createBgp([ActorQueryOperationFromQuad.copyMetadata(algebraFactory
|
|
85
|
+
.createPattern(pattern.subject, pattern.predicate, pattern.object, graph), pattern)]));
|
|
86
|
+
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, bgps);
|
|
87
|
+
}));
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
[utils_algebra_1.Algebra.Types.PATH]: {
|
|
91
|
+
preVisitor: () => ({ continue: false, copy: false }),
|
|
92
|
+
transform: (path) => {
|
|
93
|
+
if (path.graph.termType !== 'DefaultGraph') {
|
|
94
|
+
return path;
|
|
95
|
+
}
|
|
96
|
+
const paths = defaultGraphs.map(graph => ActorQueryOperationFromQuad.copyMetadata(algebraFactory.createPath(path.subject, path.predicate, path.object, graph), path));
|
|
97
|
+
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
[utils_algebra_1.Algebra.Types.PATTERN]: {
|
|
101
|
+
preVisitor: () => ({ continue: false, copy: false }),
|
|
102
|
+
transform: (pattern) => {
|
|
60
103
|
if (pattern.graph.termType !== 'DefaultGraph') {
|
|
61
|
-
return
|
|
104
|
+
return pattern;
|
|
62
105
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
const paths = defaultGraphs.map((graph) => {
|
|
72
|
-
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATH)) {
|
|
73
|
-
return algebraFactory
|
|
74
|
-
.createPath(operation.subject, operation.predicate, operation.object, graph);
|
|
75
|
-
}
|
|
76
|
-
return Object.assign(algebraFactory
|
|
77
|
-
.createPattern(operation.subject, operation.predicate, operation.object, graph), { metadata: operation.metadata });
|
|
78
|
-
});
|
|
79
|
-
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);
|
|
80
|
-
}
|
|
81
|
-
return ActorQueryOperationFromQuad.copyOperation(operation, subOperation => this.applyOperationDefaultGraph(algebraFactory, subOperation, defaultGraphs));
|
|
106
|
+
const paths = defaultGraphs.map(graph => ActorQueryOperationFromQuad.copyMetadata(algebraFactory.createPattern(pattern.subject, pattern.predicate, pattern.object, graph), pattern));
|
|
107
|
+
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
// A construct template holds the quads to produce, it is never matched against the dataset.
|
|
111
|
+
[utils_algebra_1.Algebra.Types.CONSTRUCT]: { preVisitor: () => ({ ignoreKeys: new Set(['template', 'metadata']) }) },
|
|
112
|
+
});
|
|
82
113
|
}
|
|
83
114
|
/**
|
|
84
115
|
* Recursively transform the given operation to use the given graphs as named graph
|
|
@@ -86,58 +117,90 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
86
117
|
* @package
|
|
87
118
|
* @param algebraFactory The algebra factory.
|
|
88
119
|
* @param {Operation} operation An operation.
|
|
89
|
-
* @param {RDF.Term[]} namedGraphs Graph terms.
|
|
90
|
-
* @param {RDF.Term[]} defaultGraphs Default graph terms.
|
|
120
|
+
* @param {RDF.Term[]} namedGraphs Graph terms, as defined by FROM NAMED.
|
|
121
|
+
* @param {RDF.Term[]} defaultGraphs Default graph terms, as defined by FROM.
|
|
91
122
|
* @return {Operation} A new operation.
|
|
92
123
|
*/
|
|
93
124
|
static applyOperationNamedGraph(algebraFactory, operation, namedGraphs, defaultGraphs) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
125
|
+
return utils_algebra_1.algebraUtils.mapOperation(operation, {
|
|
126
|
+
[utils_algebra_1.Algebra.Types.BGP]: {
|
|
127
|
+
preVisitor: () => ({ continue: false, copy: false }),
|
|
128
|
+
transform: bgp => bgp.patterns.length === 0 ?
|
|
129
|
+
bgp :
|
|
130
|
+
ActorQueryOperationFromQuad.applyNamedGraphToPattern(algebraFactory, bgp, namedGraphs, defaultGraphs),
|
|
131
|
+
},
|
|
132
|
+
[utils_algebra_1.Algebra.Types.PATH]: {
|
|
133
|
+
preVisitor: () => ({ continue: false, copy: false }),
|
|
134
|
+
transform: path => ActorQueryOperationFromQuad
|
|
135
|
+
.applyNamedGraphToPattern(algebraFactory, path, namedGraphs, defaultGraphs),
|
|
136
|
+
},
|
|
137
|
+
[utils_algebra_1.Algebra.Types.PATTERN]: {
|
|
138
|
+
preVisitor: () => ({ continue: false, copy: false }),
|
|
139
|
+
transform: pattern => ActorQueryOperationFromQuad
|
|
140
|
+
.applyNamedGraphToPattern(algebraFactory, pattern, namedGraphs, defaultGraphs),
|
|
141
|
+
},
|
|
142
|
+
[utils_algebra_1.Algebra.Types.CONSTRUCT]: { preVisitor: () => ({ ignoreKeys: new Set(['template', 'metadata']) }) },
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Transform a single BGP, quad pattern or property path to use the given graphs as named graph.
|
|
147
|
+
* @param algebraFactory The algebra factory.
|
|
148
|
+
* @param operation A BGP, quad pattern or property path operation.
|
|
149
|
+
* @param {RDF.Term[]} namedGraphs Graph terms, as defined by FROM NAMED.
|
|
150
|
+
* @param {RDF.Term[]} defaultGraphs Default graph terms, as defined by FROM.
|
|
151
|
+
* @return {Operation} A new operation.
|
|
152
|
+
*/
|
|
153
|
+
static applyNamedGraphToPattern(algebraFactory, operation, namedGraphs, defaultGraphs) {
|
|
154
|
+
const patternGraph = utils_algebra_1.algebraUtils.isKnownOperation(operation, utils_algebra_1.Algebra.Types.BGP) ?
|
|
155
|
+
operation.patterns[0].graph :
|
|
156
|
+
operation.graph;
|
|
157
|
+
if (patternGraph.termType === 'DefaultGraph') {
|
|
158
|
+
// Patterns over the default graph are not restricted by FROM NAMED.
|
|
159
|
+
// They are handled afterwards by the default graph transformation.
|
|
160
|
+
if (defaultGraphs.length > 0) {
|
|
161
|
+
return operation;
|
|
102
162
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.createValues([patternGraph], [bindings]);
|
|
111
|
-
let pattern;
|
|
112
|
-
if (operation.type === 'bgp') {
|
|
113
|
-
pattern = algebraFactory
|
|
114
|
-
.createBgp(operation.patterns.map((pat) => algebraFactory
|
|
115
|
-
.createPattern(pat.subject, pat.predicate, pat.object, graph)));
|
|
116
|
-
}
|
|
117
|
-
else if (operation.type === 'path') {
|
|
118
|
-
pattern = algebraFactory
|
|
119
|
-
.createPath(operation.subject, operation.predicate, operation.object, graph);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
pattern = algebraFactory
|
|
123
|
-
.createPattern(operation.subject, operation.predicate, operation.object, graph);
|
|
124
|
-
}
|
|
125
|
-
return algebraFactory.createJoin([values, pattern]);
|
|
126
|
-
}
|
|
127
|
-
// If the pattern graph is a variable, take the union of the pattern applied to each available named graph
|
|
128
|
-
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, namedGraphs.map((graph) => ActorQueryOperationFromQuad.applyOperationNamedGraph(algebraFactory, operation, [graph], defaultGraphs)));
|
|
163
|
+
// SPARQL 1.0 spec (8.2) and SPARQL 1.1 spec (13.2) describe that
|
|
164
|
+
// when FROM NAMED's are used without a FROM, the default graph must be empty.
|
|
165
|
+
return algebraFactory.createValues([], []);
|
|
166
|
+
}
|
|
167
|
+
if (patternGraph.termType === 'Variable') {
|
|
168
|
+
if (namedGraphs.length === 0) {
|
|
169
|
+
return algebraFactory.createValues([], []);
|
|
129
170
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
171
|
+
if (namedGraphs.length === 1) {
|
|
172
|
+
const graph = namedGraphs[0];
|
|
173
|
+
// If the pattern graph is a variable, replace the graph and bind the variable using VALUES
|
|
174
|
+
const bindings = {};
|
|
175
|
+
bindings[patternGraph.value] = graph;
|
|
176
|
+
const values = algebraFactory
|
|
177
|
+
.createValues([patternGraph], [bindings]);
|
|
178
|
+
let pattern;
|
|
179
|
+
if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.BGP)) {
|
|
180
|
+
pattern = algebraFactory
|
|
181
|
+
.createBgp(operation.patterns.map((pat) => ActorQueryOperationFromQuad.copyMetadata(algebraFactory.createPattern(pat.subject, pat.predicate, pat.object, graph), pat)));
|
|
182
|
+
}
|
|
183
|
+
else if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATH)) {
|
|
184
|
+
pattern = ActorQueryOperationFromQuad.copyMetadata(algebraFactory.createPath(operation.subject, operation.predicate, operation.object, graph), operation);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
pattern = ActorQueryOperationFromQuad.copyMetadata(algebraFactory.createPattern(operation.subject, operation.predicate, operation.object, graph), operation);
|
|
188
|
+
}
|
|
189
|
+
return algebraFactory.createJoin([values, pattern]);
|
|
135
190
|
}
|
|
136
|
-
//
|
|
137
|
-
return algebraFactory.
|
|
191
|
+
// If the pattern graph is a variable, take the union of the pattern applied to each available named graph
|
|
192
|
+
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, namedGraphs.map((graph) => ActorQueryOperationFromQuad.applyNamedGraphToPattern(algebraFactory, operation, [graph], defaultGraphs)));
|
|
193
|
+
}
|
|
194
|
+
// The pattern's graph is defined.
|
|
195
|
+
// SPARQL 1.0 spec (8.2) and SPARQL 1.1 spec (13.2) describe that only the graphs from FROM NAMED
|
|
196
|
+
// are available as named graphs, so graphs that were only selected in a FROM must not be matched here.
|
|
197
|
+
const isNamedGraphAvailable = namedGraphs.some((namedGraph) => namedGraph.equals(patternGraph));
|
|
198
|
+
if (isNamedGraphAvailable) {
|
|
199
|
+
// Return the pattern as-is if the pattern's graph was selected in a FROM NAMED
|
|
200
|
+
return operation;
|
|
138
201
|
}
|
|
139
|
-
|
|
140
|
-
|
|
202
|
+
// No-op if the pattern's graph was not selected in a FROM NAMED.
|
|
203
|
+
return algebraFactory.createValues([], []);
|
|
141
204
|
}
|
|
142
205
|
/**
|
|
143
206
|
* Transform the given array of operations into a join operation.
|
|
@@ -187,13 +250,16 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
187
250
|
*/
|
|
188
251
|
static createOperation(algebraFactory, pattern) {
|
|
189
252
|
let operation = pattern.input;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
253
|
+
// The named graph transformation must be applied first,
|
|
254
|
+
// as it needs to distinguish patterns that apply to the default graph
|
|
255
|
+
// from patterns that were explicitly scoped to a graph via GRAPH.
|
|
193
256
|
if (pattern.named.length > 0 || pattern.default.length > 0) {
|
|
194
257
|
operation = ActorQueryOperationFromQuad
|
|
195
258
|
.applyOperationNamedGraph(algebraFactory, operation, pattern.named, pattern.default);
|
|
196
259
|
}
|
|
260
|
+
if (pattern.default.length > 0) {
|
|
261
|
+
operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(algebraFactory, operation, pattern.default);
|
|
262
|
+
}
|
|
197
263
|
return operation;
|
|
198
264
|
}
|
|
199
265
|
async testOperation(_operation, _context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryOperationFromQuad.js","sourceRoot":"","sources":["ActorQueryOperationFromQuad.ts"],"names":[],"mappings":";;;AACA,uEAAiF;AACjF,+DAA0D;AAE1D,yCAA8C;AAE9C,2DAAoF;AAGpF;;GAEG;AACH,MAAa,2BAA4B,SAAQ,sDAA8C;IACrF,MAAM,CAAU,aAAa,GAAa,MAAM,CAAC,IAAI,CAAC,uBAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAQ,uBAAO,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAEpH,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,uBAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CACzB,SAA4B,EAC5B,WAAmE;QAEnE,MAAM,eAAe,GAA4B,EAAE,CAAC;QACpD,KAAK,MAAM,CAAE,GAAG,EAAE,KAAK,CAAE,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACvD,MAAM,SAAS,G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OAaG;IACI,MAAM,CAAC,eAAe,CAAC,cAA8B,EAAE,OAAqB;QACjF,IAAI,SAAS,GAAsB,OAAO,CAAC,KAAK,CAAC;QACjD,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,SAAS,GAAG,2BAA2B,CAAC,0BAA0B,CAAC,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACjH,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3D,SAAS,GAAG,2BAA2B;iBACpC,wBAAwB,CAAC,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,UAAwB,EAAE,QAAwB;QAC3E,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,YAAY,CACvB,iBAA+B,EAC/B,OAAuB;QAEvB,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,cAAc,GAAG,IAAI,8BAAc,CAAC,WAAW,CAAC,CAAC;QAEvD,MAAM,SAAS,GAAsB,2BAA2B,CAAC,eAAe,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;QACpH,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;;AAtPH,kEAuPC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type { ComunicaDataFactory, IActionContext, IQueryOperationResult } from '@comunica/types';\nimport { Algebra, AlgebraFactory, isKnownOperation } from '@comunica/utils-algebra';\nimport type * as RDF from '@rdfjs/types';\n\n/**\n * A comunica From Query Operation Actor.\n */\nexport class ActorQueryOperationFromQuad extends ActorQueryOperationTypedMediated<Algebra.From> {\n private static readonly ALGEBRA_TYPES: string[] = Object.keys(Algebra.Types).map(key => (<any> Algebra.Types)[key]);\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, Algebra.Types.FROM);\n }\n\n /**\n * Create a deep copy of the given operation.\n * @param {Operation} operation An operation.\n * @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.\n * @return {Operation} The copied operation.\n */\n public static copyOperation(\n operation: Algebra.Operation,\n recursiveCb: (subOperation: Algebra.Operation) => Algebra.Operation,\n ): Algebra.Operation {\n const copiedOperation: Algebra.Operation = <any> {};\n for (const [ key, value ] of Object.entries(operation)) {\n const castedKey = <keyof typeof operation> key;\n if (Array.isArray(value) && key !== 'template') {\n // We exclude the 'template' entry, as we don't want to modify the template value of construct operations\n if (key === 'variables') {\n copiedOperation[castedKey] = <any> value;\n } else {\n copiedOperation[castedKey] = <any> value.map(recursiveCb);\n }\n } else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(value.type)) {\n copiedOperation[castedKey] = <any> recursiveCb(value);\n } else {\n copiedOperation[castedKey] = value;\n }\n }\n return copiedOperation;\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as default graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} defaultGraphs Graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationDefaultGraph(\n algebraFactory: AlgebraFactory,\n operation: Algebra.Operation,\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((isKnownOperation(operation, Algebra.Types.BGP) && operation.patterns.length > 0) ||\n isKnownOperation(operation, Algebra.Types.PATH) || isKnownOperation(operation, Algebra.Types.PATTERN)) {\n if (isKnownOperation(operation, Algebra.Types.BGP)) {\n return ActorQueryOperationFromQuad\n .joinOperations(algebraFactory, operation.patterns.map((pattern) => {\n if (pattern.graph.termType !== 'DefaultGraph') {\n return algebraFactory.createBgp([ pattern ]);\n }\n const bgps = defaultGraphs.map((graph: RDF.Term) =>\n algebraFactory.createBgp([ Object.assign(\n algebraFactory\n .createPattern(pattern.subject, pattern.predicate, pattern.object, graph),\n { metadata: pattern.metadata },\n ) ]));\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, bgps);\n }));\n }\n if (operation.graph.termType !== 'DefaultGraph') {\n return operation;\n }\n const paths = defaultGraphs.map(\n (graph: RDF.Term) => {\n if (isKnownOperation(operation, Algebra.Types.PATH)) {\n return algebraFactory\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n }\n return Object.assign(algebraFactory\n .createPattern(\n operation.subject,\n operation.predicate,\n operation.object,\n graph,\n ), { metadata: operation.metadata });\n },\n );\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n subOperation => this.applyOperationDefaultGraph(algebraFactory, subOperation, defaultGraphs),\n );\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as named graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} namedGraphs Graph terms.\n * @param {RDF.Term[]} defaultGraphs Default graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationNamedGraph(\n algebraFactory: AlgebraFactory,\n operation: Algebra.Operation,\n namedGraphs: RDF.NamedNode[],\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((isKnownOperation(operation, Algebra.Types.BGP) && operation.patterns.length > 0) ||\n isKnownOperation(operation, Algebra.Types.PATH) || isKnownOperation(operation, Algebra.Types.PATTERN)) {\n const patternGraph: RDF.Term = operation.type === 'bgp' ? operation.patterns[0].graph : operation.graph;\n if (patternGraph.termType === 'DefaultGraph') {\n // SPARQL spec (8.2) describes that when FROM NAMED's are used without a FROM, the default graph must be empty.\n // The FROMs are transformed before this step to a named node, so this will not apply to this case anymore.\n return algebraFactory.createBgp([]);\n }\n if (patternGraph.termType === 'Variable') {\n if (namedGraphs.length === 1) {\n const graph: RDF.NamedNode = namedGraphs[0];\n // If the pattern graph is a variable, replace the graph and bind the variable using VALUES\n const bindings: Record<string, RDF.Literal | RDF.NamedNode> = {};\n bindings[patternGraph.value] = graph;\n const values: Algebra.Values = algebraFactory\n .createValues([ patternGraph ], [ bindings ]);\n\n let pattern: Algebra.Operation;\n if (operation.type === 'bgp') {\n pattern = algebraFactory\n .createBgp(operation.patterns.map((pat: Algebra.Pattern) => algebraFactory\n .createPattern(pat.subject, pat.predicate, pat.object, graph)));\n } else if (operation.type === 'path') {\n pattern = algebraFactory\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n } else {\n pattern = algebraFactory\n .createPattern(operation.subject, operation.predicate, operation.object, graph);\n }\n\n return algebraFactory.createJoin([ values, pattern ]);\n }\n // If the pattern graph is a variable, take the union of the pattern applied to each available named graph\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, namedGraphs.map(\n (graph: RDF.NamedNode) => ActorQueryOperationFromQuad.applyOperationNamedGraph(\n algebraFactory,\n operation,\n [ graph ],\n defaultGraphs,\n ),\n ));\n }\n // The pattern's graph is defined (including the default graphs)\n const isNamedGraphAvailable: boolean = [ ...namedGraphs, ...defaultGraphs ].some(\n (namedGraph: RDF.Term) => namedGraph.equals(patternGraph),\n );\n if (isNamedGraphAvailable) {\n // Return the pattern as-is if the pattern's graph was selected in a FROM NAMED\n return operation;\n }\n // No-op if the pattern's graph was not selected in a FROM NAMED.\n return algebraFactory.createBgp([]);\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n (subOperation: Algebra.Operation) => this\n .applyOperationNamedGraph(algebraFactory, subOperation, namedGraphs, defaultGraphs),\n );\n }\n\n /**\n * Transform the given array of operations into a join operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Join} A join operation.\n */\n public static joinOperations(algebraFactory: AlgebraFactory, operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return algebraFactory.createJoin(operations);\n }\n throw new Error('A join can only be applied on at least one operation');\n }\n\n /**\n * Transform the given array of operations into a union operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Union} A union operation.\n */\n public static unionOperations(algebraFactory: AlgebraFactory, operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return algebraFactory.createUnion(operations);\n }\n throw new Error('A union can only be applied on at least one operation');\n }\n\n /**\n * Transform an operation based on the default and named graphs in the pattern.\n *\n * FROM sets the default graph.\n * If multiple are available, take the union of the operation for all of them at quad-pattern level.\n *\n * FROM NAMED indicates which named graphs are available.\n * This will rewrite the query so that only triples from the given named graphs can be selected.\n *\n * @package\n * @param algebraFactory The algebra factory.\n * @param {From} pattern A from operation.\n * @return {Operation} The transformed operation.\n */\n public static createOperation(algebraFactory: AlgebraFactory, pattern: Algebra.From): Algebra.Operation {\n let operation: Algebra.Operation = pattern.input;\n if (pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(algebraFactory, operation, pattern.default);\n }\n if (pattern.named.length > 0 || pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad\n .applyOperationNamedGraph(algebraFactory, operation, pattern.named, pattern.default);\n }\n return operation;\n }\n\n public async testOperation(_operation: Algebra.From, _context: IActionContext): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async runOperation(\n operationOriginal: Algebra.From,\n context: IActionContext,\n ): Promise<IQueryOperationResult> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new AlgebraFactory(dataFactory);\n\n const operation: Algebra.Operation = ActorQueryOperationFromQuad.createOperation(algebraFactory, operationOriginal);\n return this.mediatorQueryOperation.mediate({ operation, context });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorQueryOperationFromQuad.js","sourceRoot":"","sources":["ActorQueryOperationFromQuad.ts"],"names":[],"mappings":";;;AACA,uEAAiF;AACjF,+DAA0D;AAE1D,yCAA8C;AAE9C,2DAAkG;AAGlG;;GAEG;AACH,MAAa,2BAA4B,SAAQ,sDAA8C;IACrF,MAAM,CAAU,aAAa,GAAa,MAAM,CAAC,IAAI,CAAC,uBAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAQ,uBAAO,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAEpH,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,uBAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,aAAa,CACzB,SAA4B,EAC5B,WAAmE;QAEnE,oCAAoC;QACpC,MAAM,eAAe,GAA4B,EAAE,CAAC;QACpD,KAAK,MAAM,CAAE,GAAG,EAAE,KAAK,CAAE,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACvD,MAAM,SAAS,GAA4B,GAAG,CAAC;YAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC/C,yGAAyG;gBACzG,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;oBACxB,eAAe,CAAC,SAAS,CAAC,GAAS,KAAK,CAAC;gBAC3C,CAAC;qBAAM,CAAC;o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AEM,KAAK,CAAC,aAAa,CAAC,UAAwB,EAAE,QAAwB;QAC3E,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,YAAY,CACvB,iBAA+B,EAC/B,OAAuB;QAEvB,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,cAAc,GAAG,IAAI,8BAAc,CAAC,WAAW,CAAC,CAAC;QAEvD,MAAM,SAAS,GAAsB,2BAA2B,CAAC,eAAe,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;QACpH,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;;AA/TH,kEAgUC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type { ComunicaDataFactory, IActionContext, IQueryOperationResult } from '@comunica/types';\nimport { Algebra, AlgebraFactory, algebraUtils, isKnownOperation } from '@comunica/utils-algebra';\nimport type * as RDF from '@rdfjs/types';\n\n/**\n * A comunica From Query Operation Actor.\n */\nexport class ActorQueryOperationFromQuad extends ActorQueryOperationTypedMediated<Algebra.From> {\n private static readonly ALGEBRA_TYPES: string[] = Object.keys(Algebra.Types).map(key => (<any> Algebra.Types)[key]);\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, Algebra.Types.FROM);\n }\n\n /**\n * Create a deep copy of the given operation.\n *\n * The graph transformations of this actor no longer use this: they let an algebra traversal copy the\n * operations they rewrite. It is part of the public API of this actor though, so it stays.\n * @param {Operation} operation An operation.\n * @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.\n * @return {Operation} The copied operation.\n */\n public static copyOperation(\n operation: Algebra.Operation,\n recursiveCb: (subOperation: Algebra.Operation) => Algebra.Operation,\n ): Algebra.Operation {\n // TODO (next major): can be removed\n const copiedOperation: Algebra.Operation = <any> {};\n for (const [ key, value ] of Object.entries(operation)) {\n const castedKey = <keyof typeof operation> key;\n if (Array.isArray(value) && key !== 'template') {\n // We exclude the 'template' entry, as we don't want to modify the template value of construct operations\n if (key === 'variables') {\n copiedOperation[castedKey] = <any> value;\n } else {\n copiedOperation[castedKey] = <any> value.map(recursiveCb);\n }\n } else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(value.type)) {\n copiedOperation[castedKey] = <any> recursiveCb(value);\n } else {\n copiedOperation[castedKey] = value;\n }\n }\n return copiedOperation;\n }\n\n /**\n * Copy the metadata of the given original operation onto the given new operation.\n * This is required because operations are recreated with a different graph in this actor,\n * and the metadata may contain information that must be retained, such as the source annotation.\n * @param {Operation} operationNew The new operation to copy the metadata to. This operation is mutated.\n * @param {Operation} operationOriginal The original operation to copy the metadata from.\n * @return {Operation} The new operation.\n */\n public static copyMetadata<O extends Algebra.Operation>(operationNew: O, operationOriginal: Algebra.Operation): O {\n if (operationOriginal.metadata) {\n operationNew.metadata = operationOriginal.metadata;\n }\n return operationNew;\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as default graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} defaultGraphs Graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationDefaultGraph(\n algebraFactory: AlgebraFactory,\n operation: Algebra.Operation,\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n return algebraUtils.mapOperation(operation, {\n [Algebra.Types.BGP]: {\n preVisitor: () => ({ continue: false, copy: false }),\n transform: (bgp) => {\n if (bgp.patterns.length === 0) {\n return bgp;\n }\n return ActorQueryOperationFromQuad\n .joinOperations(algebraFactory, bgp.patterns.map((pattern) => {\n if (pattern.graph.termType !== 'DefaultGraph') {\n return algebraFactory.createBgp([ pattern ]);\n }\n const bgps = defaultGraphs.map((graph: RDF.Term) =>\n algebraFactory.createBgp([ ActorQueryOperationFromQuad.copyMetadata(\n algebraFactory\n .createPattern(pattern.subject, pattern.predicate, pattern.object, graph),\n pattern,\n ) ]));\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, bgps);\n }));\n },\n },\n [Algebra.Types.PATH]: {\n preVisitor: () => ({ continue: false, copy: false }),\n transform: (path) => {\n if (path.graph.termType !== 'DefaultGraph') {\n return path;\n }\n const paths = defaultGraphs.map(graph => ActorQueryOperationFromQuad.copyMetadata(\n algebraFactory.createPath(path.subject, path.predicate, path.object, graph),\n path,\n ));\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);\n },\n },\n [Algebra.Types.PATTERN]: {\n preVisitor: () => ({ continue: false, copy: false }),\n transform: (pattern) => {\n if (pattern.graph.termType !== 'DefaultGraph') {\n return pattern;\n }\n const paths = defaultGraphs.map(graph => ActorQueryOperationFromQuad.copyMetadata(\n algebraFactory.createPattern(pattern.subject, pattern.predicate, pattern.object, graph),\n pattern,\n ));\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);\n },\n },\n // A construct template holds the quads to produce, it is never matched against the dataset.\n [Algebra.Types.CONSTRUCT]: { preVisitor: () => ({ ignoreKeys: new Set([ 'template', 'metadata' ]) }) },\n });\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as named graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} namedGraphs Graph terms, as defined by FROM NAMED.\n * @param {RDF.Term[]} defaultGraphs Default graph terms, as defined by FROM.\n * @return {Operation} A new operation.\n */\n public static applyOperationNamedGraph(\n algebraFactory: AlgebraFactory,\n operation: Algebra.Operation,\n namedGraphs: RDF.NamedNode[],\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n return algebraUtils.mapOperation(operation, {\n [Algebra.Types.BGP]: {\n preVisitor: () => ({ continue: false, copy: false }),\n transform: bgp => bgp.patterns.length === 0 ?\n bgp :\n ActorQueryOperationFromQuad.applyNamedGraphToPattern(algebraFactory, bgp, namedGraphs, defaultGraphs),\n },\n [Algebra.Types.PATH]: {\n preVisitor: () => ({ continue: false, copy: false }),\n transform: path => ActorQueryOperationFromQuad\n .applyNamedGraphToPattern(algebraFactory, path, namedGraphs, defaultGraphs),\n },\n [Algebra.Types.PATTERN]: {\n preVisitor: () => ({ continue: false, copy: false }),\n transform: pattern => ActorQueryOperationFromQuad\n .applyNamedGraphToPattern(algebraFactory, pattern, namedGraphs, defaultGraphs),\n },\n [Algebra.Types.CONSTRUCT]: { preVisitor: () => ({ ignoreKeys: new Set([ 'template', 'metadata' ]) }) },\n });\n }\n\n /**\n * Transform a single BGP, quad pattern or property path to use the given graphs as named graph.\n * @param algebraFactory The algebra factory.\n * @param operation A BGP, quad pattern or property path operation.\n * @param {RDF.Term[]} namedGraphs Graph terms, as defined by FROM NAMED.\n * @param {RDF.Term[]} defaultGraphs Default graph terms, as defined by FROM.\n * @return {Operation} A new operation.\n */\n private static applyNamedGraphToPattern(\n algebraFactory: AlgebraFactory,\n operation: Algebra.Bgp | Algebra.Path | Algebra.Pattern,\n namedGraphs: RDF.NamedNode[],\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n const patternGraph: RDF.Term = algebraUtils.isKnownOperation(operation, Algebra.Types.BGP) ?\n operation.patterns[0].graph :\n operation.graph;\n if (patternGraph.termType === 'DefaultGraph') {\n // Patterns over the default graph are not restricted by FROM NAMED.\n // They are handled afterwards by the default graph transformation.\n if (defaultGraphs.length > 0) {\n return operation;\n }\n // SPARQL 1.0 spec (8.2) and SPARQL 1.1 spec (13.2) describe that\n // when FROM NAMED's are used without a FROM, the default graph must be empty.\n return algebraFactory.createValues([], []);\n }\n if (patternGraph.termType === 'Variable') {\n if (namedGraphs.length === 0) {\n return algebraFactory.createValues([], []);\n }\n if (namedGraphs.length === 1) {\n const graph: RDF.NamedNode = namedGraphs[0];\n // If the pattern graph is a variable, replace the graph and bind the variable using VALUES\n const bindings: Record<string, RDF.Literal | RDF.NamedNode> = {};\n bindings[patternGraph.value] = graph;\n const values: Algebra.Values = algebraFactory\n .createValues([ patternGraph ], [ bindings ]);\n\n let pattern: Algebra.Operation;\n if (isKnownOperation(operation, Algebra.Types.BGP)) {\n pattern = algebraFactory\n .createBgp(operation.patterns.map((pat: Algebra.Pattern) => ActorQueryOperationFromQuad.copyMetadata(\n algebraFactory.createPattern(pat.subject, pat.predicate, pat.object, graph),\n pat,\n )));\n } else if (isKnownOperation(operation, Algebra.Types.PATH)) {\n pattern = ActorQueryOperationFromQuad.copyMetadata(\n algebraFactory.createPath(operation.subject, operation.predicate, operation.object, graph),\n operation,\n );\n } else {\n pattern = ActorQueryOperationFromQuad.copyMetadata(\n algebraFactory.createPattern(operation.subject, operation.predicate, operation.object, graph),\n operation,\n );\n }\n\n return algebraFactory.createJoin([ values, pattern ]);\n }\n // If the pattern graph is a variable, take the union of the pattern applied to each available named graph\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, namedGraphs.map(\n (graph: RDF.NamedNode) => ActorQueryOperationFromQuad.applyNamedGraphToPattern(\n algebraFactory,\n operation,\n [ graph ],\n defaultGraphs,\n ),\n ));\n }\n // The pattern's graph is defined.\n // SPARQL 1.0 spec (8.2) and SPARQL 1.1 spec (13.2) describe that only the graphs from FROM NAMED\n // are available as named graphs, so graphs that were only selected in a FROM must not be matched here.\n const isNamedGraphAvailable: boolean = namedGraphs.some(\n (namedGraph: RDF.Term) => namedGraph.equals(patternGraph),\n );\n if (isNamedGraphAvailable) {\n // Return the pattern as-is if the pattern's graph was selected in a FROM NAMED\n return operation;\n }\n // No-op if the pattern's graph was not selected in a FROM NAMED.\n return algebraFactory.createValues([], []);\n }\n\n /**\n * Transform the given array of operations into a join operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Join} A join operation.\n */\n public static joinOperations(algebraFactory: AlgebraFactory, operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return algebraFactory.createJoin(operations);\n }\n throw new Error('A join can only be applied on at least one operation');\n }\n\n /**\n * Transform the given array of operations into a union operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Union} A union operation.\n */\n public static unionOperations(algebraFactory: AlgebraFactory, operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return algebraFactory.createUnion(operations);\n }\n throw new Error('A union can only be applied on at least one operation');\n }\n\n /**\n * Transform an operation based on the default and named graphs in the pattern.\n *\n * FROM sets the default graph.\n * If multiple are available, take the union of the operation for all of them at quad-pattern level.\n *\n * FROM NAMED indicates which named graphs are available.\n * This will rewrite the query so that only triples from the given named graphs can be selected.\n *\n * @package\n * @param algebraFactory The algebra factory.\n * @param {From} pattern A from operation.\n * @return {Operation} The transformed operation.\n */\n public static createOperation(algebraFactory: AlgebraFactory, pattern: Algebra.From): Algebra.Operation {\n let operation: Algebra.Operation = pattern.input;\n // The named graph transformation must be applied first,\n // as it needs to distinguish patterns that apply to the default graph\n // from patterns that were explicitly scoped to a graph via GRAPH.\n if (pattern.named.length > 0 || pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad\n .applyOperationNamedGraph(algebraFactory, operation, pattern.named, pattern.default);\n }\n if (pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(algebraFactory, operation, pattern.default);\n }\n return operation;\n }\n\n public async testOperation(_operation: Algebra.From, _context: IActionContext): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async runOperation(\n operationOriginal: Algebra.From,\n context: IActionContext,\n ): Promise<IQueryOperationResult> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new AlgebraFactory(dataFactory);\n\n const operation: Algebra.Operation = ActorQueryOperationFromQuad.createOperation(algebraFactory, operationOriginal);\n return this.mediatorQueryOperation.mediate({ operation, context });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-operation-from-quad",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "A from query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"build:components": "componentsjs-generator"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@comunica/bus-query-operation": "^5.
|
|
45
|
-
"@comunica/context-entries": "^5.
|
|
46
|
-
"@comunica/core": "^5.
|
|
47
|
-
"@comunica/types": "^5.
|
|
48
|
-
"@comunica/utils-algebra": "^5.
|
|
44
|
+
"@comunica/bus-query-operation": "^5.4.0",
|
|
45
|
+
"@comunica/context-entries": "^5.4.0",
|
|
46
|
+
"@comunica/core": "^5.4.0",
|
|
47
|
+
"@comunica/types": "^5.4.0",
|
|
48
|
+
"@comunica/utils-algebra": "^5.4.0",
|
|
49
49
|
"@rdfjs/types": "*"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "8a0a10913cb705adda45997210ebbe5502274a60"
|
|
52
52
|
}
|