@comunica/actor-query-operation-construct 3.3.0 → 4.0.1
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/README.md +1 -1
- package/components/ActorQueryOperationConstruct.jsonld +44 -12
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +7 -1
- package/lib/ActorQueryOperationConstruct.d.ts +2 -2
- package/lib/ActorQueryOperationConstruct.js +7 -4
- package/lib/ActorQueryOperationConstruct.js.map +1 -1
- package/lib/BindingsToQuadsIterator.d.ts +7 -4
- package/lib/BindingsToQuadsIterator.js +9 -8
- package/lib/BindingsToQuadsIterator.js.map +1 -1
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ After installing, this package can be added to your engine's configuration as fo
|
|
|
22
22
|
{
|
|
23
23
|
"@context": [
|
|
24
24
|
...
|
|
25
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^
|
|
25
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^4.0.0/components/context.jsonld"
|
|
26
26
|
],
|
|
27
27
|
"actors": [
|
|
28
28
|
...
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^4.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^4.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^4.0.0/components/context.jsonld"
|
|
6
6
|
],
|
|
7
7
|
"@id": "npmd:@comunica/actor-query-operation-construct",
|
|
8
8
|
"components": [
|
|
@@ -45,29 +45,37 @@
|
|
|
45
45
|
"genericTypeInstances": [
|
|
46
46
|
{
|
|
47
47
|
"@type": "ParameterRangeGenericTypeReference",
|
|
48
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
48
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"@type": "ParameterRangeGenericTypeReference",
|
|
52
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
52
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
"@type": "ParameterRangeGenericTypeReference",
|
|
56
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
56
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
60
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
57
61
|
}
|
|
58
62
|
]
|
|
59
63
|
},
|
|
60
64
|
{
|
|
61
65
|
"@type": "ParameterRangeGenericTypeReference",
|
|
62
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
66
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
70
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
63
71
|
},
|
|
64
72
|
{
|
|
65
73
|
"@type": "ParameterRangeGenericTypeReference",
|
|
66
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
74
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
67
75
|
},
|
|
68
76
|
{
|
|
69
77
|
"@type": "ParameterRangeGenericTypeReference",
|
|
70
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
78
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
71
79
|
}
|
|
72
80
|
]
|
|
73
81
|
},
|
|
@@ -77,6 +85,20 @@
|
|
|
77
85
|
},
|
|
78
86
|
"comment": "The bus this actor subscribes to."
|
|
79
87
|
},
|
|
88
|
+
{
|
|
89
|
+
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_busFailMessage",
|
|
90
|
+
"range": {
|
|
91
|
+
"@type": "ParameterRangeUnion",
|
|
92
|
+
"parameterRangeElements": [
|
|
93
|
+
"xsd:string",
|
|
94
|
+
{
|
|
95
|
+
"@type": "ParameterRangeUndefined"
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
"default": "Query operation processing failed: none of the configured actors were able to handle the operation type ${action.operation.type}",
|
|
100
|
+
"comment": "The message that will be configured in the bus for reporting failures. This message may be a template string that contains references to the executed `action`. For example, the following templated string is allowed: \"RDF dereferencing failed: no actors could handle ${action.handle.mediaType}\""
|
|
101
|
+
},
|
|
80
102
|
{
|
|
81
103
|
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_beforeActors",
|
|
82
104
|
"range": {
|
|
@@ -90,15 +112,19 @@
|
|
|
90
112
|
"genericTypeInstances": [
|
|
91
113
|
{
|
|
92
114
|
"@type": "ParameterRangeGenericTypeReference",
|
|
93
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
115
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
94
116
|
},
|
|
95
117
|
{
|
|
96
118
|
"@type": "ParameterRangeGenericTypeReference",
|
|
97
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
119
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
98
120
|
},
|
|
99
121
|
{
|
|
100
122
|
"@type": "ParameterRangeGenericTypeReference",
|
|
101
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
123
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
127
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
102
128
|
}
|
|
103
129
|
]
|
|
104
130
|
}
|
|
@@ -151,6 +177,12 @@
|
|
|
151
177
|
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_bus"
|
|
152
178
|
}
|
|
153
179
|
},
|
|
180
|
+
{
|
|
181
|
+
"keyRaw": "busFailMessage",
|
|
182
|
+
"value": {
|
|
183
|
+
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_busFailMessage"
|
|
184
|
+
}
|
|
185
|
+
},
|
|
154
186
|
{
|
|
155
187
|
"keyRaw": "beforeActors",
|
|
156
188
|
"value": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^4.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/actor-query-operation-construct",
|
|
6
6
|
"@type": "Module",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^6.0.0/components/context.jsonld",
|
|
4
4
|
{
|
|
5
5
|
"npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
|
|
6
|
-
"caqoc": "npmd:@comunica/actor-query-operation-construct/^
|
|
6
|
+
"caqoc": "npmd:@comunica/actor-query-operation-construct/^4.0.0/",
|
|
7
7
|
"ActorQueryOperationConstruct": {
|
|
8
8
|
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct",
|
|
9
9
|
"@prefix": true,
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"args_bus": {
|
|
18
18
|
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_bus"
|
|
19
19
|
},
|
|
20
|
+
"args_busFailMessage": {
|
|
21
|
+
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_busFailMessage"
|
|
22
|
+
},
|
|
20
23
|
"args_beforeActors": {
|
|
21
24
|
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_beforeActors",
|
|
22
25
|
"@container": "@list"
|
|
@@ -30,6 +33,9 @@
|
|
|
30
33
|
"bus": {
|
|
31
34
|
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_bus"
|
|
32
35
|
},
|
|
36
|
+
"busFailMessage": {
|
|
37
|
+
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_busFailMessage"
|
|
38
|
+
},
|
|
33
39
|
"beforeActors": {
|
|
34
40
|
"@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct_args_beforeActors",
|
|
35
41
|
"@container": "@list"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';
|
|
2
2
|
import { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';
|
|
3
|
-
import type { IActorTest } from '@comunica/core';
|
|
3
|
+
import type { IActorTest, TestResult } from '@comunica/core';
|
|
4
4
|
import type { IActionContext, IQueryOperationResult } from '@comunica/types';
|
|
5
5
|
import type * as RDF from '@rdfjs/types';
|
|
6
6
|
import { Algebra } from 'sparqlalgebrajs';
|
|
@@ -15,6 +15,6 @@ export declare class ActorQueryOperationConstruct extends ActorQueryOperationTyp
|
|
|
15
15
|
* @return {RDF.Variable[]} The variables in the triple patterns.
|
|
16
16
|
*/
|
|
17
17
|
static getVariables(patterns: RDF.BaseQuad[]): RDF.Variable[];
|
|
18
|
-
testOperation(_operation: Algebra.Construct, _context: IActionContext): Promise<IActorTest
|
|
18
|
+
testOperation(_operation: Algebra.Construct, _context: IActionContext): Promise<TestResult<IActorTest>>;
|
|
19
19
|
runOperation(operationOriginal: Algebra.Construct, context: IActionContext): Promise<IQueryOperationResult>;
|
|
20
20
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActorQueryOperationConstruct = void 0;
|
|
4
4
|
const bus_query_operation_1 = require("@comunica/bus-query-operation");
|
|
5
|
+
const context_entries_1 = require("@comunica/context-entries");
|
|
6
|
+
const core_1 = require("@comunica/core");
|
|
7
|
+
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
5
8
|
const rdf_terms_1 = require("rdf-terms");
|
|
6
9
|
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
7
10
|
const BindingsToQuadsIterator_1 = require("./BindingsToQuadsIterator");
|
|
@@ -22,17 +25,18 @@ class ActorQueryOperationConstruct extends bus_query_operation_1.ActorQueryOpera
|
|
|
22
25
|
.apply([], patterns.map(pattern => (0, rdf_terms_1.getVariables)((0, rdf_terms_1.getTermsNested)(pattern)))));
|
|
23
26
|
}
|
|
24
27
|
async testOperation(_operation, _context) {
|
|
25
|
-
return
|
|
28
|
+
return (0, core_1.passTestVoid)();
|
|
26
29
|
}
|
|
27
30
|
async runOperation(operationOriginal, context) {
|
|
31
|
+
const dataFactory = context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
28
32
|
// Apply a projection on our CONSTRUCT variables first, as the query may contain other variables as well.
|
|
29
33
|
const variables = ActorQueryOperationConstruct.getVariables(operationOriginal.template);
|
|
30
34
|
const operation = { type: sparqlalgebrajs_1.Algebra.types.PROJECT, input: operationOriginal.input, variables };
|
|
31
35
|
// Evaluate the input query
|
|
32
|
-
const output =
|
|
36
|
+
const output = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ operation, context }));
|
|
33
37
|
// Construct triples using the result based on the pattern.
|
|
34
38
|
// If it's a DESCRIBE query don't apply the blank node localisation.
|
|
35
|
-
const quadStream = new BindingsToQuadsIterator_1.BindingsToQuadsIterator(operationOriginal.template, output.bindingsStream);
|
|
39
|
+
const quadStream = new BindingsToQuadsIterator_1.BindingsToQuadsIterator(dataFactory, operationOriginal.template, output.bindingsStream);
|
|
36
40
|
// Let the final metadata contain the estimated number of triples
|
|
37
41
|
const metadata = () => output.metadata().then(meta => ({
|
|
38
42
|
...meta,
|
|
@@ -41,7 +45,6 @@ class ActorQueryOperationConstruct extends bus_query_operation_1.ActorQueryOpera
|
|
|
41
45
|
type: meta.cardinality.type,
|
|
42
46
|
value: meta.cardinality.value * operationOriginal.template.length,
|
|
43
47
|
},
|
|
44
|
-
canContainUndefs: false,
|
|
45
48
|
availableOrders: undefined,
|
|
46
49
|
}));
|
|
47
50
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryOperationConstruct.js","sourceRoot":"","sources":["ActorQueryOperationConstruct.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"ActorQueryOperationConstruct.js","sourceRoot":"","sources":["ActorQueryOperationConstruct.ts"],"names":[],"mappings":";;;AACA,uEAEuC;AACvC,+DAA0D;AAE1D,yCAA8C;AAQ9C,2EAAkE;AAGlE,yCAAoE;AACpE,qDAA0C;AAC1C,uEAAoE;AAEpE;;GAEG;AACH,MAAa,4BAA6B,SAAQ,sDAAmD;IACnG,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,QAAwB;QACjD,OAAO,IAAA,qBAAS,EAAmB,EAAG,CAAC,MAAM;aAC1C,KAAK,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAA,wBAAY,EAAC,IAAA,0BAAc,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,UAA6B,EAAE,QAAwB;QAChF,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,iBAAoC,EAAE,OAAuB;QAErF,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QAEpF,yGAAyG;QACzG,MAAM,SAAS,GAAmB,4BAA4B,CAAC,YAAY,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACxG,MAAM,SAAS,GAAsB,EAAE,IAAI,EAAE,yBAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC;QAEhH,2BAA2B;QAC3B,MAAM,MAAM,GAAkC,IAAA,uCAAe,EAC3D,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAClE,CAAC;QAEF,2DAA2D;QAC3D,oEAAoE;QACpE,MAAM,UAAU,GAA4B,IAAI,iDAAuB,CACrE,WAAW,EACX,iBAAiB,CAAC,QAAQ,EAC1B,MAAM,CAAC,cAAc,CACtB,CAAC;QAEF,iEAAiE;QACjE,MAAM,QAAQ,GAAmC,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACrF,GAAG,IAAI;YACP,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;gBAC3B,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,iBAAiB,CAAC,QAAQ,CAAC,MAAM;aAClE;YACD,eAAe,EAAE,SAAS;SAC3B,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,QAAQ;YACR,UAAU;YACV,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF;AAzDD,oEAyDC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport {\n ActorQueryOperationTypedMediated,\n} 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 {\n IQueryOperationResultBindings,\n IActionContext,\n IQueryOperationResult,\n MetadataQuads,\n ComunicaDataFactory,\n} from '@comunica/types';\nimport { getSafeBindings } from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\nimport type { AsyncIterator } from 'asynciterator';\nimport { getTermsNested, getVariables, uniqTerms } from 'rdf-terms';\nimport { Algebra } from 'sparqlalgebrajs';\nimport { BindingsToQuadsIterator } from './BindingsToQuadsIterator';\n\n/**\n * A comunica Construct Query Operation Actor.\n */\nexport class ActorQueryOperationConstruct extends ActorQueryOperationTypedMediated<Algebra.Construct> {\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, 'construct');\n }\n\n /**\n * Find all variables in a list of triple patterns.\n * @param {Algebra.Pattern[]} patterns An array of triple patterns.\n * @return {RDF.Variable[]} The variables in the triple patterns.\n */\n public static getVariables(patterns: RDF.BaseQuad[]): RDF.Variable[] {\n return uniqTerms((<RDF.Variable[]> []).concat\n .apply([], patterns.map(pattern => getVariables(getTermsNested(pattern)))));\n }\n\n public async testOperation(_operation: Algebra.Construct, _context: IActionContext): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async runOperation(operationOriginal: Algebra.Construct, context: IActionContext):\n Promise<IQueryOperationResult> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n\n // Apply a projection on our CONSTRUCT variables first, as the query may contain other variables as well.\n const variables: RDF.Variable[] = ActorQueryOperationConstruct.getVariables(operationOriginal.template);\n const operation: Algebra.Operation = { type: Algebra.types.PROJECT, input: operationOriginal.input, variables };\n\n // Evaluate the input query\n const output: IQueryOperationResultBindings = getSafeBindings(\n await this.mediatorQueryOperation.mediate({ operation, context }),\n );\n\n // Construct triples using the result based on the pattern.\n // If it's a DESCRIBE query don't apply the blank node localisation.\n const quadStream: AsyncIterator<RDF.Quad> = new BindingsToQuadsIterator(\n dataFactory,\n operationOriginal.template,\n output.bindingsStream,\n );\n\n // Let the final metadata contain the estimated number of triples\n const metadata: (() => Promise<MetadataQuads>) = () => output.metadata().then(meta => ({\n ...meta,\n order: undefined,\n cardinality: {\n type: meta.cardinality.type,\n value: meta.cardinality.value * operationOriginal.template.length,\n },\n availableOrders: undefined,\n }));\n\n return {\n metadata,\n quadStream,\n type: 'quads',\n };\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Bindings, BindingsStream } from '@comunica/types';
|
|
1
|
+
import type { Bindings, BindingsStream, ComunicaDataFactory } from '@comunica/types';
|
|
2
2
|
import type * as RDF from '@rdfjs/types';
|
|
3
3
|
import type { AsyncIterator } from 'asynciterator';
|
|
4
4
|
import { MultiTransformIterator } from 'asynciterator';
|
|
@@ -9,9 +9,10 @@ import { MultiTransformIterator } from 'asynciterator';
|
|
|
9
9
|
* https://www.w3.org/TR/sparql11-query/#rConstructTriples
|
|
10
10
|
*/
|
|
11
11
|
export declare class BindingsToQuadsIterator extends MultiTransformIterator<Bindings, RDF.Quad> {
|
|
12
|
+
protected readonly dataFactory: ComunicaDataFactory;
|
|
12
13
|
protected readonly template: RDF.BaseQuad[];
|
|
13
14
|
protected blankNodeCounter: number;
|
|
14
|
-
constructor(template: RDF.BaseQuad[], bindingsStream: BindingsStream);
|
|
15
|
+
constructor(dataFactory: ComunicaDataFactory, template: RDF.BaseQuad[], bindingsStream: BindingsStream);
|
|
15
16
|
/**
|
|
16
17
|
* Bind the given term.
|
|
17
18
|
* If the term is a variable and the variable is bound in the bindings object,
|
|
@@ -38,18 +39,20 @@ export declare class BindingsToQuadsIterator extends MultiTransformIterator<Bind
|
|
|
38
39
|
/**
|
|
39
40
|
* Convert a blank node to a unique blank node in the given context.
|
|
40
41
|
* If the given term is not a blank node, the term itself will be returned.
|
|
42
|
+
* @param dataFactory The data factory.
|
|
41
43
|
* @param blankNodeCounter A counter value for the blank node.
|
|
42
44
|
* @param {RDF.Term} term The term that should be localized.
|
|
43
45
|
* @return {RDF.Term} A term.
|
|
44
46
|
*/
|
|
45
|
-
static localizeBlankNode(blankNodeCounter: number, term: RDF.Term): RDF.Term;
|
|
47
|
+
static localizeBlankNode(dataFactory: ComunicaDataFactory, blankNodeCounter: number, term: RDF.Term): RDF.Term;
|
|
46
48
|
/**
|
|
47
49
|
* Convert the given quad to a quad that only contains unique blank nodes.
|
|
50
|
+
* @param dataFactory The data factory.
|
|
48
51
|
* @param blankNodeCounter A counter value for the blank node.
|
|
49
52
|
* @param {RDF.BaseQuad} pattern The pattern that should be localized.
|
|
50
53
|
* @return {RDF.BaseQuad} A quad.
|
|
51
54
|
*/
|
|
52
|
-
static localizeQuad(blankNodeCounter: number, pattern: RDF.BaseQuad): RDF.BaseQuad;
|
|
55
|
+
static localizeQuad(dataFactory: ComunicaDataFactory, blankNodeCounter: number, pattern: RDF.BaseQuad): RDF.BaseQuad;
|
|
53
56
|
/**
|
|
54
57
|
* Convert the given template to a list of quads based on the given bindings.
|
|
55
58
|
* @param {Bindings} bindings A bindings object.
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindingsToQuadsIterator = void 0;
|
|
4
4
|
const asynciterator_1 = require("asynciterator");
|
|
5
|
-
const rdf_data_factory_1 = require("rdf-data-factory");
|
|
6
5
|
const rdf_terms_1 = require("rdf-terms");
|
|
7
|
-
const DF = new rdf_data_factory_1.DataFactory();
|
|
8
6
|
/**
|
|
9
7
|
* Transforms a bindings stream into a quad stream given a quad template.
|
|
10
8
|
*
|
|
@@ -12,8 +10,9 @@ const DF = new rdf_data_factory_1.DataFactory();
|
|
|
12
10
|
* https://www.w3.org/TR/sparql11-query/#rConstructTriples
|
|
13
11
|
*/
|
|
14
12
|
class BindingsToQuadsIterator extends asynciterator_1.MultiTransformIterator {
|
|
15
|
-
constructor(template, bindingsStream) {
|
|
13
|
+
constructor(dataFactory, template, bindingsStream) {
|
|
16
14
|
super(bindingsStream, { autoStart: false });
|
|
15
|
+
this.dataFactory = dataFactory;
|
|
17
16
|
this.template = template;
|
|
18
17
|
this.blankNodeCounter = 0;
|
|
19
18
|
}
|
|
@@ -61,24 +60,26 @@ class BindingsToQuadsIterator extends asynciterator_1.MultiTransformIterator {
|
|
|
61
60
|
/**
|
|
62
61
|
* Convert a blank node to a unique blank node in the given context.
|
|
63
62
|
* If the given term is not a blank node, the term itself will be returned.
|
|
63
|
+
* @param dataFactory The data factory.
|
|
64
64
|
* @param blankNodeCounter A counter value for the blank node.
|
|
65
65
|
* @param {RDF.Term} term The term that should be localized.
|
|
66
66
|
* @return {RDF.Term} A term.
|
|
67
67
|
*/
|
|
68
|
-
static localizeBlankNode(blankNodeCounter, term) {
|
|
68
|
+
static localizeBlankNode(dataFactory, blankNodeCounter, term) {
|
|
69
69
|
if (term.termType === 'BlankNode') {
|
|
70
|
-
return
|
|
70
|
+
return dataFactory.blankNode(`${term.value}${blankNodeCounter}`);
|
|
71
71
|
}
|
|
72
72
|
return term;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Convert the given quad to a quad that only contains unique blank nodes.
|
|
76
|
+
* @param dataFactory The data factory.
|
|
76
77
|
* @param blankNodeCounter A counter value for the blank node.
|
|
77
78
|
* @param {RDF.BaseQuad} pattern The pattern that should be localized.
|
|
78
79
|
* @return {RDF.BaseQuad} A quad.
|
|
79
80
|
*/
|
|
80
|
-
static localizeQuad(blankNodeCounter, pattern) {
|
|
81
|
-
return (0, rdf_terms_1.mapTermsNested)(pattern, term => BindingsToQuadsIterator.localizeBlankNode(blankNodeCounter, term));
|
|
81
|
+
static localizeQuad(dataFactory, blankNodeCounter, pattern) {
|
|
82
|
+
return (0, rdf_terms_1.mapTermsNested)(pattern, term => BindingsToQuadsIterator.localizeBlankNode(dataFactory, blankNodeCounter, term));
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
85
|
* Convert the given template to a list of quads based on the given bindings.
|
|
@@ -90,7 +91,7 @@ class BindingsToQuadsIterator extends asynciterator_1.MultiTransformIterator {
|
|
|
90
91
|
bindTemplate(bindings, template, blankNodeCounter) {
|
|
91
92
|
const quads = template
|
|
92
93
|
// Make sure the multiple instantiations of the template contain different blank nodes, as required by SPARQL 1.1.
|
|
93
|
-
.map(BindingsToQuadsIterator.localizeQuad.bind(null, blankNodeCounter))
|
|
94
|
+
.map(BindingsToQuadsIterator.localizeQuad.bind(null, this.dataFactory, blankNodeCounter))
|
|
94
95
|
// Bind variables to bound terms
|
|
95
96
|
.map(x => BindingsToQuadsIterator.bindQuad.bind(null, bindings)(x))
|
|
96
97
|
// Remove quads that contained unbound terms, i.e., variables.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BindingsToQuadsIterator.js","sourceRoot":"","sources":["BindingsToQuadsIterator.ts"],"names":[],"mappings":";;;AAGA,iDAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"BindingsToQuadsIterator.js","sourceRoot":"","sources":["BindingsToQuadsIterator.ts"],"names":[],"mappings":";;;AAGA,iDAAsE;AACtE,yCAA2C;AAE3C;;;;;GAKG;AACH,MAAa,uBAAwB,SAAQ,sCAA0C;IAKrF,YAAmB,WAAgC,EAAE,QAAwB,EAAE,cAA8B;QAC3G,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,QAAQ,CAAC,QAAkB,EAAE,IAAc;QACvD,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,QAAQ,CAAC,QAAkB,EAAE,OAAqB;QAC9D,IAAI,CAAC;YACH,OAAO,IAAA,0BAAc,EAAY,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBACjD,MAAM,SAAS,GAAG,uBAAuB,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACnE,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;gBAClC,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,aAAa;QACf,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,iBAAiB,CAC7B,WAAgC,EAChC,gBAAwB,EACxB,IAAc;QAEd,IAAI,IAAI,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,gBAAgB,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,YAAY,CACxB,WAAgC,EAChC,gBAAwB,EACxB,OAAqB;QAErB,OAAO,IAAA,0BAAc,EACnB,OAAO,EACP,IAAI,CAAC,EAAE,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,EAAE,IAAI,CAAC,CACvF,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,YAAY,CAAC,QAAkB,EAAE,QAAwB,EAAE,gBAAwB;QACxF,MAAM,KAAK,GAAoC,QAAQ;YACrD,kHAAkH;aACjH,GAAG,CAAC,uBAAuB,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;YACzF,gCAAgC;aAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,uBAAuB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACnE,8DAA8D;aAC7D,MAAM,CAAC,OAAO,CAAC,CAAC;QACnB,OAAoB,KAAK,CAAC;IAC5B,CAAC;IAEe,kBAAkB,CAAC,QAAkB;QACnD,OAAO,IAAI,6BAAa,CAAC,IAAI,CAAC,YAAY,CACxC,QAAQ,EACR,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,gBAAgB,EAAE,CACxB,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3B,CAAC;CACF;AApHD,0DAoHC","sourcesContent":["import type { Bindings, BindingsStream, ComunicaDataFactory } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { AsyncIterator } from 'asynciterator';\nimport { ArrayIterator, MultiTransformIterator } from 'asynciterator';\nimport { mapTermsNested } from 'rdf-terms';\n\n/**\n * Transforms a bindings stream into a quad stream given a quad template.\n *\n * This conforms to the SPARQL 1.1 spec on constructing triples:\n * https://www.w3.org/TR/sparql11-query/#rConstructTriples\n */\nexport class BindingsToQuadsIterator extends MultiTransformIterator<Bindings, RDF.Quad> {\n protected readonly dataFactory: ComunicaDataFactory;\n protected readonly template: RDF.BaseQuad[];\n protected blankNodeCounter: number;\n\n public constructor(dataFactory: ComunicaDataFactory, template: RDF.BaseQuad[], bindingsStream: BindingsStream) {\n super(bindingsStream, { autoStart: false });\n this.dataFactory = dataFactory;\n this.template = template;\n this.blankNodeCounter = 0;\n }\n\n /**\n * Bind the given term.\n * If the term is a variable and the variable is bound in the bindings object,\n * return the bindings value.\n * If the term is a variable and the variable is not bound in the bindings object,\n * a falsy value is returned..\n * Otherwise, the term itself is returned.\n * @param {Bindings} bindings A bindings object.\n * @param {RDF.Term} term An RDF term.\n * @return {RDF.Term} If the given term is not a variable, the term itself is returned.\n * If the given term is a variable, then the bound term is returned,\n * or a falsy value if it did not exist in the bindings.\n */\n public static bindTerm(bindings: Bindings, term: RDF.Term): RDF.Term | undefined {\n if (term.termType === 'Variable') {\n return bindings.get(term);\n }\n return term;\n }\n\n /**\n * Bind the given quad pattern.\n * If one of the terms was a variable AND is not bound in the bindings,\n * a falsy value will be returned.\n * @param {Bindings} bindings A bindings object.\n * @param {RDF.Quad} pattern An RDF quad.\n * @return {RDF.Quad} A bound RDF quad or undefined.\n */\n public static bindQuad(bindings: Bindings, pattern: RDF.BaseQuad): RDF.Quad | undefined {\n try {\n return mapTermsNested(<RDF.Quad> pattern, (term) => {\n const boundTerm = BindingsToQuadsIterator.bindTerm(bindings, term);\n if (!boundTerm) {\n throw new Error('Unbound term');\n }\n return boundTerm;\n });\n } catch {\n // Do nothing\n }\n }\n\n /**\n * Convert a blank node to a unique blank node in the given context.\n * If the given term is not a blank node, the term itself will be returned.\n * @param dataFactory The data factory.\n * @param blankNodeCounter A counter value for the blank node.\n * @param {RDF.Term} term The term that should be localized.\n * @return {RDF.Term} A term.\n */\n public static localizeBlankNode(\n dataFactory: ComunicaDataFactory,\n blankNodeCounter: number,\n term: RDF.Term,\n ): RDF.Term {\n if (term.termType === 'BlankNode') {\n return dataFactory.blankNode(`${term.value}${blankNodeCounter}`);\n }\n return term;\n }\n\n /**\n * Convert the given quad to a quad that only contains unique blank nodes.\n * @param dataFactory The data factory.\n * @param blankNodeCounter A counter value for the blank node.\n * @param {RDF.BaseQuad} pattern The pattern that should be localized.\n * @return {RDF.BaseQuad} A quad.\n */\n public static localizeQuad(\n dataFactory: ComunicaDataFactory,\n blankNodeCounter: number,\n pattern: RDF.BaseQuad,\n ): RDF.BaseQuad {\n return mapTermsNested(\n pattern,\n term => BindingsToQuadsIterator.localizeBlankNode(dataFactory, blankNodeCounter, term),\n );\n }\n\n /**\n * Convert the given template to a list of quads based on the given bindings.\n * @param {Bindings} bindings A bindings object.\n * @param {RDF.Quad[]} template A list of quad patterns.\n * @param blankNodeCounter A counter value for the blank node.\n * @return {RDF.Quad[]} A list of quads.\n */\n public bindTemplate(bindings: Bindings, template: RDF.BaseQuad[], blankNodeCounter: number): RDF.Quad[] {\n const quads: RDF.BaseQuad[] = <RDF.BaseQuad[]> template\n // Make sure the multiple instantiations of the template contain different blank nodes, as required by SPARQL 1.1.\n .map(BindingsToQuadsIterator.localizeQuad.bind(null, this.dataFactory, blankNodeCounter))\n // Bind variables to bound terms\n .map(x => BindingsToQuadsIterator.bindQuad.bind(null, bindings)(x))\n // Remove quads that contained unbound terms, i.e., variables.\n .filter(Boolean);\n return <RDF.Quad[]> quads;\n }\n\n public override _createTransformer(bindings: Bindings): AsyncIterator<RDF.Quad> {\n return new ArrayIterator(this.bindTemplate(\n bindings,\n this.template,\n this.blankNodeCounter++,\n ), { autoStart: false });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-operation-construct",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "A construct query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"funding": {
|
|
8
|
+
"type": "opencollective",
|
|
9
|
+
"url": "https://opencollective.com/comunica-association"
|
|
10
|
+
},
|
|
7
11
|
"homepage": "https://comunica.dev/",
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
@@ -37,14 +41,15 @@
|
|
|
37
41
|
"build:components": "componentsjs-generator"
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@comunica/bus-query-operation": "^
|
|
41
|
-
"@comunica/
|
|
42
|
-
"@comunica/
|
|
44
|
+
"@comunica/bus-query-operation": "^4.0.1",
|
|
45
|
+
"@comunica/context-entries": "^4.0.1",
|
|
46
|
+
"@comunica/core": "^4.0.1",
|
|
47
|
+
"@comunica/types": "^4.0.1",
|
|
48
|
+
"@comunica/utils-query-operation": "^4.0.1",
|
|
43
49
|
"@rdfjs/types": "*",
|
|
44
50
|
"asynciterator": "^3.9.0",
|
|
45
|
-
"rdf-data-factory": "^1.1.1",
|
|
46
51
|
"rdf-terms": "^1.11.0",
|
|
47
|
-
"sparqlalgebrajs": "^4.3.
|
|
52
|
+
"sparqlalgebrajs": "^4.3.8"
|
|
48
53
|
},
|
|
49
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "67831ba79e45ea1ced41fe3f83c5d6e8802dbeaa"
|
|
50
55
|
}
|