@comunica/actor-query-operation-construct 4.5.0 → 5.0.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/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/^4.0.0/components/context.jsonld"
25
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^5.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.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"
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^5.0.0/components/context.jsonld",
4
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^5.0.0/components/context.jsonld",
5
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^5.0.0/components/context.jsonld"
6
6
  ],
7
7
  "@id": "npmd:@comunica/actor-query-operation-construct",
8
8
  "components": [
@@ -15,7 +15,17 @@
15
15
  "@type": "GenericComponentExtension",
16
16
  "component": "cbqo:components/ActorQueryOperationTypedMediated.jsonld#ActorQueryOperationTypedMediated",
17
17
  "genericTypeInstances": [
18
- "urn:npm:sparqlalgebrajs:Construct"
18
+ {
19
+ "@type": "ParameterRangeIntersection",
20
+ "parameterRangeElements": [
21
+ {
22
+ "@type": "ParameterRangeWildcard"
23
+ },
24
+ {
25
+ "@type": "ParameterRangeWildcard"
26
+ }
27
+ ]
28
+ }
19
29
  ]
20
30
  }
21
31
  ],
@@ -45,37 +55,37 @@
45
55
  "genericTypeInstances": [
46
56
  {
47
57
  "@type": "ParameterRangeGenericTypeReference",
48
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
58
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
49
59
  },
50
60
  {
51
61
  "@type": "ParameterRangeGenericTypeReference",
52
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
62
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
53
63
  },
54
64
  {
55
65
  "@type": "ParameterRangeGenericTypeReference",
56
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
66
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
57
67
  },
58
68
  {
59
69
  "@type": "ParameterRangeGenericTypeReference",
60
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
70
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
61
71
  }
62
72
  ]
63
73
  },
64
74
  {
65
75
  "@type": "ParameterRangeGenericTypeReference",
66
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
76
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
67
77
  },
68
78
  {
69
79
  "@type": "ParameterRangeGenericTypeReference",
70
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
80
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
71
81
  },
72
82
  {
73
83
  "@type": "ParameterRangeGenericTypeReference",
74
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
84
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
75
85
  },
76
86
  {
77
87
  "@type": "ParameterRangeGenericTypeReference",
78
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
88
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
79
89
  }
80
90
  ]
81
91
  },
@@ -112,19 +122,19 @@
112
122
  "genericTypeInstances": [
113
123
  {
114
124
  "@type": "ParameterRangeGenericTypeReference",
115
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
125
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
116
126
  },
117
127
  {
118
128
  "@type": "ParameterRangeGenericTypeReference",
119
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
129
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
120
130
  },
121
131
  {
122
132
  "@type": "ParameterRangeGenericTypeReference",
123
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
133
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
124
134
  },
125
135
  {
126
136
  "@type": "ParameterRangeGenericTypeReference",
127
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
137
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
128
138
  }
129
139
  ]
130
140
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "@context": [
3
- "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^4.0.0/components/context.jsonld"
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-construct/^5.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/^4.0.0/",
6
+ "caqoc": "npmd:@comunica/actor-query-operation-construct/^5.0.0/",
7
7
  "ActorQueryOperationConstruct": {
8
8
  "@id": "caqoc:components/ActorQueryOperationConstruct.jsonld#ActorQueryOperationConstruct",
9
9
  "@prefix": true,
@@ -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 } from '@comunica/utils-algebra';
5
6
  import type * as RDF from '@rdfjs/types';
6
- import { Algebra } from 'sparqlalgebrajs';
7
7
  /**
8
8
  * A comunica Construct Query Operation Actor.
9
9
  */
@@ -4,16 +4,16 @@ exports.ActorQueryOperationConstruct = 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 utils_algebra_1 = require("@comunica/utils-algebra");
7
8
  const utils_query_operation_1 = require("@comunica/utils-query-operation");
8
9
  const rdf_terms_1 = require("rdf-terms");
9
- const sparqlalgebrajs_1 = require("sparqlalgebrajs");
10
10
  const BindingsToQuadsIterator_1 = require("./BindingsToQuadsIterator");
11
11
  /**
12
12
  * A comunica Construct Query Operation Actor.
13
13
  */
14
14
  class ActorQueryOperationConstruct extends bus_query_operation_1.ActorQueryOperationTypedMediated {
15
15
  constructor(args) {
16
- super(args, 'construct');
16
+ super(args, utils_algebra_1.Algebra.Types.CONSTRUCT);
17
17
  }
18
18
  /**
19
19
  * Find all variables in a list of triple patterns.
@@ -29,9 +29,10 @@ class ActorQueryOperationConstruct extends bus_query_operation_1.ActorQueryOpera
29
29
  }
30
30
  async runOperation(operationOriginal, context) {
31
31
  const dataFactory = context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
32
+ const algebraFactory = new utils_algebra_1.AlgebraFactory(dataFactory);
32
33
  // Apply a projection on our CONSTRUCT variables first, as the query may contain other variables as well.
33
34
  const variables = ActorQueryOperationConstruct.getVariables(operationOriginal.template);
34
- const operation = { type: sparqlalgebrajs_1.Algebra.types.PROJECT, input: operationOriginal.input, variables };
35
+ const operation = algebraFactory.createProject(operationOriginal.input, variables);
35
36
  // Evaluate the input query
36
37
  const output = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ operation, context }));
37
38
  // Construct triples using the result based on the pattern.
@@ -1 +1 @@
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
+ {"version":3,"file":"ActorQueryOperationConstruct.js","sourceRoot":"","sources":["ActorQueryOperationConstruct.ts"],"names":[],"mappings":";;;AACA,uEAEuC;AACvC,+DAA0D;AAE1D,yCAA8C;AAQ9C,2DAAkE;AAClE,2EAAkE;AAGlE,yCAAoE;AACpE,uEAAoE;AAEpE;;GAEG;AACH,MAAa,4BAA6B,SAAQ,sDAAmD;IACnG,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,uBAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACvC,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;QACpF,MAAM,cAAc,GAAG,IAAI,8BAAc,CAAC,WAAW,CAAC,CAAC;QAEvD,yGAAyG;QACzG,MAAM,SAAS,GAAmB,4BAA4B,CAAC,YAAY,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACxG,MAAM,SAAS,GAAG,cAAc,CAAC,aAAa,CAAC,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAEnF,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;AA1DD,oEA0DC","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 { Algebra, AlgebraFactory } from '@comunica/utils-algebra';\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 { 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, Algebra.Types.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 const algebraFactory = new AlgebraFactory(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 = algebraFactory.createProject(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"]}
File without changes
@@ -10,6 +10,9 @@ const rdf_terms_1 = require("rdf-terms");
10
10
  * https://www.w3.org/TR/sparql11-query/#rConstructTriples
11
11
  */
12
12
  class BindingsToQuadsIterator extends asynciterator_1.MultiTransformIterator {
13
+ dataFactory;
14
+ template;
15
+ blankNodeCounter;
13
16
  constructor(dataFactory, template, bindingsStream) {
14
17
  super(bindingsStream, { autoStart: false });
15
18
  this.dataFactory = dataFactory;
@@ -1 +1 @@
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;gB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,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"]}
1
+ {"version":3,"file":"BindingsToQuadsIterator.js","sourceRoot":"","sources":["BindingsToQuadsIterator.ts"],"names":[],"mappings":";;;AAGA,iDAAsE;AACtE,yCAA2C;AAE3C;;;;;GAKG;AACH,MAAa,uBAAwB,SAAQ,sCAA0C;IAClE,WAAW,CAAsB;IACjC,QAAQ,CAAiB;IAClC,gBAAgB,CAAS;IAEnC,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,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ACxB,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/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-construct",
3
- "version": "4.5.0",
3
+ "version": "5.0.0",
4
4
  "description": "A construct query-operation actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -41,15 +41,15 @@
41
41
  "build:components": "componentsjs-generator"
42
42
  },
43
43
  "dependencies": {
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
- "@comunica/utils-query-operation": "^4.5.0",
44
+ "@comunica/bus-query-operation": "^5.0.0",
45
+ "@comunica/context-entries": "^5.0.0",
46
+ "@comunica/core": "^5.0.0",
47
+ "@comunica/types": "^5.0.0",
48
+ "@comunica/utils-algebra": "^5.0.0",
49
+ "@comunica/utils-query-operation": "^5.0.0",
49
50
  "@rdfjs/types": "*",
50
- "asynciterator": "^3.9.0",
51
- "rdf-terms": "^1.11.0",
52
- "sparqlalgebrajs": "^5.0.2"
51
+ "asynciterator": "^3.10.0",
52
+ "rdf-terms": "^2.0.0"
53
53
  },
54
- "gitHead": "2bcd98c387a021fc5c08d375793c205ca3d1bf0d"
54
+ "gitHead": "0b1756fdb9bef014133432489627c1bd71779bd0"
55
55
  }