@comunica/actor-query-operation-from-quad 4.4.2-alpha.49.0 → 4.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/components/ActorQueryOperationFromQuad.jsonld +1 -11
- package/components/components.jsonld +0 -0
- package/components/context.jsonld +0 -0
- package/lib/ActorQueryOperationFromQuad.d.ts +6 -6
- package/lib/ActorQueryOperationFromQuad.js +23 -22
- package/lib/ActorQueryOperationFromQuad.js.map +1 -1
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/index.js.map +0 -0
- package/package.json +8 -8
|
@@ -15,17 +15,7 @@
|
|
|
15
15
|
"@type": "GenericComponentExtension",
|
|
16
16
|
"component": "cbqo:components/ActorQueryOperationTypedMediated.jsonld#ActorQueryOperationTypedMediated",
|
|
17
17
|
"genericTypeInstances": [
|
|
18
|
-
|
|
19
|
-
"@type": "ParameterRangeIntersection",
|
|
20
|
-
"parameterRangeElements": [
|
|
21
|
-
{
|
|
22
|
-
"@type": "ParameterRangeWildcard"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"@type": "ParameterRangeWildcard"
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
18
|
+
"urn:npm:sparqlalgebrajs:From"
|
|
29
19
|
]
|
|
30
20
|
}
|
|
31
21
|
],
|
|
File without changes
|
|
File without changes
|
|
@@ -2,8 +2,8 @@ import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-
|
|
|
2
2
|
import { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';
|
|
3
3
|
import type { IActorTest, TestResult } from '@comunica/core';
|
|
4
4
|
import type { IActionContext, IQueryOperationResult } from '@comunica/types';
|
|
5
|
-
import { Algebra, AlgebraFactory } from '@comunica/utils-algebra';
|
|
6
5
|
import type * as RDF from '@rdfjs/types';
|
|
6
|
+
import { Algebra, Factory } from 'sparqlalgebrajs';
|
|
7
7
|
/**
|
|
8
8
|
* A comunica From Query Operation Actor.
|
|
9
9
|
*/
|
|
@@ -26,7 +26,7 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
26
26
|
* @param {RDF.Term[]} defaultGraphs Graph terms.
|
|
27
27
|
* @return {Operation} A new operation.
|
|
28
28
|
*/
|
|
29
|
-
static applyOperationDefaultGraph(algebraFactory:
|
|
29
|
+
static applyOperationDefaultGraph(algebraFactory: Factory, operation: Algebra.Operation, defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
30
30
|
/**
|
|
31
31
|
* Recursively transform the given operation to use the given graphs as named graph
|
|
32
32
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
@@ -37,7 +37,7 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
37
37
|
* @param {RDF.Term[]} defaultGraphs Default graph terms.
|
|
38
38
|
* @return {Operation} A new operation.
|
|
39
39
|
*/
|
|
40
|
-
static applyOperationNamedGraph(algebraFactory:
|
|
40
|
+
static applyOperationNamedGraph(algebraFactory: Factory, operation: Algebra.Operation, namedGraphs: RDF.NamedNode[], defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
41
41
|
/**
|
|
42
42
|
* Transform the given array of operations into a join operation.
|
|
43
43
|
* @package
|
|
@@ -45,7 +45,7 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
45
45
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
46
46
|
* @return {Join} A join operation.
|
|
47
47
|
*/
|
|
48
|
-
static joinOperations(algebraFactory:
|
|
48
|
+
static joinOperations(algebraFactory: Factory, operations: Algebra.Operation[]): Algebra.Operation;
|
|
49
49
|
/**
|
|
50
50
|
* Transform the given array of operations into a union operation.
|
|
51
51
|
* @package
|
|
@@ -53,7 +53,7 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
53
53
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
54
54
|
* @return {Union} A union operation.
|
|
55
55
|
*/
|
|
56
|
-
static unionOperations(algebraFactory:
|
|
56
|
+
static unionOperations(algebraFactory: Factory, operations: Algebra.Operation[]): Algebra.Operation;
|
|
57
57
|
/**
|
|
58
58
|
* Transform an operation based on the default and named graphs in the pattern.
|
|
59
59
|
*
|
|
@@ -68,7 +68,7 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
68
68
|
* @param {From} pattern A from operation.
|
|
69
69
|
* @return {Operation} The transformed operation.
|
|
70
70
|
*/
|
|
71
|
-
static createOperation(algebraFactory:
|
|
71
|
+
static createOperation(algebraFactory: Factory, pattern: Algebra.From): Algebra.Operation;
|
|
72
72
|
testOperation(_operation: Algebra.From, _context: IActionContext): Promise<TestResult<IActorTest>>;
|
|
73
73
|
runOperation(operationOriginal: Algebra.From, context: IActionContext): Promise<IQueryOperationResult>;
|
|
74
74
|
}
|
|
@@ -4,13 +4,13 @@ exports.ActorQueryOperationFromQuad = void 0;
|
|
|
4
4
|
const bus_query_operation_1 = require("@comunica/bus-query-operation");
|
|
5
5
|
const context_entries_1 = require("@comunica/context-entries");
|
|
6
6
|
const core_1 = require("@comunica/core");
|
|
7
|
-
const
|
|
7
|
+
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
8
8
|
/**
|
|
9
9
|
* A comunica From Query Operation Actor.
|
|
10
10
|
*/
|
|
11
11
|
class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperationTypedMediated {
|
|
12
12
|
constructor(args) {
|
|
13
|
-
super(args,
|
|
13
|
+
super(args, 'from');
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Create a deep copy of the given operation.
|
|
@@ -20,22 +20,21 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
20
20
|
*/
|
|
21
21
|
static copyOperation(operation, recursiveCb) {
|
|
22
22
|
const copiedOperation = {};
|
|
23
|
-
for (const
|
|
24
|
-
|
|
25
|
-
if (Array.isArray(value) && key !== 'template') {
|
|
23
|
+
for (const key of Object.keys(operation)) {
|
|
24
|
+
if (Array.isArray(operation[key]) && key !== 'template') {
|
|
26
25
|
// We exclude the 'template' entry, as we don't want to modify the template value of construct operations
|
|
27
26
|
if (key === 'variables') {
|
|
28
|
-
copiedOperation[
|
|
27
|
+
copiedOperation[key] = operation[key];
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
|
-
copiedOperation[
|
|
30
|
+
copiedOperation[key] = operation[key].map(recursiveCb);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(
|
|
35
|
-
copiedOperation[
|
|
33
|
+
else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(operation[key].type)) {
|
|
34
|
+
copiedOperation[key] = recursiveCb(operation[key]);
|
|
36
35
|
}
|
|
37
36
|
else {
|
|
38
|
-
copiedOperation[
|
|
37
|
+
copiedOperation[key] = operation[key];
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
return copiedOperation;
|
|
@@ -51,9 +50,10 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
51
50
|
*/
|
|
52
51
|
static applyOperationDefaultGraph(algebraFactory, operation, defaultGraphs) {
|
|
53
52
|
// If the operation is a BGP or Path, change the graph.
|
|
54
|
-
if ((
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if ((operation.type === 'bgp' && operation.patterns.length > 0) ||
|
|
54
|
+
operation.type === 'path' ||
|
|
55
|
+
operation.type === 'pattern') {
|
|
56
|
+
if (operation.type === 'bgp') {
|
|
57
57
|
return ActorQueryOperationFromQuad
|
|
58
58
|
.joinOperations(algebraFactory, operation.patterns.map((pattern) => {
|
|
59
59
|
if (pattern.graph.termType !== 'DefaultGraph') {
|
|
@@ -68,7 +68,7 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
68
68
|
return operation;
|
|
69
69
|
}
|
|
70
70
|
const paths = defaultGraphs.map((graph) => {
|
|
71
|
-
if (
|
|
71
|
+
if (operation.type === 'path') {
|
|
72
72
|
return algebraFactory
|
|
73
73
|
.createPath(operation.subject, operation.predicate, operation.object, graph);
|
|
74
74
|
}
|
|
@@ -77,7 +77,7 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
77
77
|
});
|
|
78
78
|
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);
|
|
79
79
|
}
|
|
80
|
-
return ActorQueryOperationFromQuad.copyOperation(operation, subOperation => this.applyOperationDefaultGraph(algebraFactory, subOperation, defaultGraphs));
|
|
80
|
+
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this.applyOperationDefaultGraph(algebraFactory, subOperation, defaultGraphs));
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Recursively transform the given operation to use the given graphs as named graph
|
|
@@ -91,20 +91,21 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
91
91
|
*/
|
|
92
92
|
static applyOperationNamedGraph(algebraFactory, operation, namedGraphs, defaultGraphs) {
|
|
93
93
|
// If the operation is a BGP or Path, change the graph.
|
|
94
|
-
if ((
|
|
95
|
-
|
|
94
|
+
if ((operation.type === 'bgp' && operation.patterns.length > 0) ||
|
|
95
|
+
operation.type === 'path' ||
|
|
96
|
+
operation.type === 'pattern') {
|
|
96
97
|
const patternGraph = operation.type === 'bgp' ? operation.patterns[0].graph : operation.graph;
|
|
97
98
|
if (patternGraph.termType === 'DefaultGraph') {
|
|
98
99
|
// SPARQL spec (8.2) describes that when FROM NAMED's are used without a FROM, the default graph must be empty.
|
|
99
100
|
// The FROMs are transformed before this step to a named node, so this will not apply to this case anymore.
|
|
100
|
-
return
|
|
101
|
+
return { type: sparqlalgebrajs_1.Algebra.types.BGP, patterns: [] };
|
|
101
102
|
}
|
|
102
103
|
if (patternGraph.termType === 'Variable') {
|
|
103
104
|
if (namedGraphs.length === 1) {
|
|
104
105
|
const graph = namedGraphs[0];
|
|
105
106
|
// If the pattern graph is a variable, replace the graph and bind the variable using VALUES
|
|
106
107
|
const bindings = {};
|
|
107
|
-
bindings[patternGraph.value] = graph;
|
|
108
|
+
bindings[`?${patternGraph.value}`] = graph;
|
|
108
109
|
const values = algebraFactory
|
|
109
110
|
.createValues([patternGraph], [bindings]);
|
|
110
111
|
let pattern;
|
|
@@ -133,7 +134,7 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
133
134
|
return operation;
|
|
134
135
|
}
|
|
135
136
|
// No-op if the pattern's graph was not selected in a FROM NAMED.
|
|
136
|
-
return
|
|
137
|
+
return { type: sparqlalgebrajs_1.Algebra.types.BGP, patterns: [] };
|
|
137
138
|
}
|
|
138
139
|
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this
|
|
139
140
|
.applyOperationNamedGraph(algebraFactory, subOperation, namedGraphs, defaultGraphs));
|
|
@@ -200,11 +201,11 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
200
201
|
}
|
|
201
202
|
async runOperation(operationOriginal, context) {
|
|
202
203
|
const dataFactory = context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
203
|
-
const algebraFactory = new
|
|
204
|
+
const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
|
|
204
205
|
const operation = ActorQueryOperationFromQuad.createOperation(algebraFactory, operationOriginal);
|
|
205
206
|
return this.mediatorQueryOperation.mediate({ operation, context });
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
exports.ActorQueryOperationFromQuad = ActorQueryOperationFromQuad;
|
|
209
|
-
ActorQueryOperationFromQuad.ALGEBRA_TYPES = Object.keys(
|
|
210
|
+
ActorQueryOperationFromQuad.ALGEBRA_TYPES = Object.keys(sparqlalgebrajs_1.Algebra.types).map(key => sparqlalgebrajs_1.Algebra.types[key]);
|
|
210
211
|
//# sourceMappingURL=ActorQueryOperationFromQu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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;AAtPyB,yCAAa,GAAa,MAAM,CAAC,IAAI,CAAC,uBAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAQ,uBAAO,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC","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;AAG9C,qDAAmD;AAEnD;;GAEG;AACH,MAAa,2BAA4B,SAAQ,sDAA8C;IAG7F,YAAmB,IAA2C;QAC5D,KAA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AC,yBAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAQ,yBAAO,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC","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 type * as RDF from '@rdfjs/types';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\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, '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 of Object.keys(operation)) {\n if (Array.isArray(operation[key]) && 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[key] = operation[key];\n } else {\n copiedOperation[key] = operation[key].map(recursiveCb);\n }\n } else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(operation[key].type)) {\n copiedOperation[key] = recursiveCb(operation[key]);\n } else {\n copiedOperation[key] = operation[key];\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: Factory,\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 ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n if (operation.type === 'bgp') {\n return ActorQueryOperationFromQuad\n .joinOperations(algebraFactory, operation.patterns.map((pattern: Algebra.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 (operation.type === '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: Algebra.Operation) => 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: Factory,\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 ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === '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 { type: Algebra.types.BGP, patterns: []};\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 { type: Algebra.types.BGP, patterns: []};\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: Factory, 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: Factory, 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: Factory, 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 Factory(dataFactory);\n\n const operation: Algebra.Operation = ActorQueryOperationFromQuad.createOperation(algebraFactory, operationOriginal);\n return this.mediatorQueryOperation.mediate({ operation, context });\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
File without changes
|
package/lib/index.js
CHANGED
|
File without changes
|
package/lib/index.js.map
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-operation-from-quad",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.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": "4.
|
|
45
|
-
"@comunica/context-entries": "4.
|
|
46
|
-
"@comunica/core": "4.
|
|
47
|
-
"@comunica/types": "4.
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
44
|
+
"@comunica/bus-query-operation": "^4.5.0",
|
|
45
|
+
"@comunica/context-entries": "^4.5.0",
|
|
46
|
+
"@comunica/core": "^4.5.0",
|
|
47
|
+
"@comunica/types": "^4.5.0",
|
|
48
|
+
"@rdfjs/types": "*",
|
|
49
|
+
"sparqlalgebrajs": "^5.0.2"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "2bcd98c387a021fc5c08d375793c205ca3d1bf0d"
|
|
52
52
|
}
|