@comunica/actor-query-source-identify-rdfjs 5.1.0 → 5.2.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.
@@ -21,6 +21,22 @@
21
21
  {
22
22
  "@id": "caqsir:components/IRdfJsSourceExtended.jsonld#IRdfJsSourceExtended__member_matchBindings",
23
23
  "memberFieldName": "matchBindings"
24
+ },
25
+ {
26
+ "@id": "caqsir:components/IRdfJsSourceExtended.jsonld#IRdfJsSourceExtended__member_matchNodes",
27
+ "memberFieldName": "matchNodes"
28
+ },
29
+ {
30
+ "@id": "caqsir:components/IRdfJsSourceExtended.jsonld#IRdfJsSourceExtended__member_countNodes",
31
+ "memberFieldName": "countNodes"
32
+ },
33
+ {
34
+ "@id": "caqsir:components/IRdfJsSourceExtended.jsonld#IRdfJsSourceExtended__member_matchDistinctTerms",
35
+ "memberFieldName": "matchDistinctTerms"
36
+ },
37
+ {
38
+ "@id": "caqsir:components/IRdfJsSourceExtended.jsonld#IRdfJsSourceExtended__member_countDistinctTerms",
39
+ "memberFieldName": "countDistinctTerms"
24
40
  }
25
41
  ],
26
42
  "constructorArguments": []
@@ -1,5 +1,6 @@
1
1
  import type { EventEmitter } from 'node:events';
2
2
  import type * as RDF from '@rdfjs/types';
3
+ import type { QuadTermName } from 'rdf-terms';
3
4
  export interface IRdfJsSourceExtended extends RDF.Source {
4
5
  /**
5
6
  * A record indicating supported features of this source.
@@ -11,6 +12,14 @@ export interface IRdfJsSourceExtended extends RDF.Source {
11
12
  * and must be replaced by `undefined` and filtered by the caller afterwards.
12
13
  */
13
14
  quotedTripleFiltering?: boolean;
15
+ /**
16
+ * If this is true, matchNodes and countNodes must be available.
17
+ */
18
+ indexNodes?: boolean;
19
+ /**
20
+ * If this is true, matchDistinctTerms and countDistinctTerms must be available.
21
+ */
22
+ indexDistinctTerms?: boolean;
14
23
  };
15
24
  /**
16
25
  * Return an estimated count of the number of quads matching the given pattern.
@@ -32,4 +41,31 @@ export interface IRdfJsSourceExtended extends RDF.Source {
32
41
  * @param graph The graph, which can be a variable.
33
42
  */
34
43
  matchBindings?: (bindingsFactory: RDF.BindingsFactory, subject: RDF.Term, predicate: RDF.Term, object: RDF.Term, graph: RDF.Term) => EventEmitter;
44
+ /**
45
+ * Returns a stream that produces all nodes as terms in the given graph.
46
+ * Nodes are all terms that are either a subject or object within the graph.
47
+ *
48
+ * This will only be used if `features.indexNodes` is true.
49
+ */
50
+ matchNodes?: (graph: RDF.Term) => EventEmitter;
51
+ /**
52
+ * Returns the number of nodes in the given graph.
53
+ * Nodes are all terms that are either a subject or object within the graph.
54
+ *
55
+ * This will only be used if `features.indexNodes` is true.
56
+ */
57
+ countNodes?: (graph: RDF.Term) => number;
58
+ /**
59
+ * Returns a stream that produces all distinct combinations of the specified terms.
60
+ * The stream produces arrays where each element corresponds to a term in the termNames array.
61
+ *
62
+ * This will only be used if `features.indexDistinctTerms` is true.
63
+ */
64
+ matchDistinctTerms?: (termNames: QuadTermName[]) => EventEmitter;
65
+ /**
66
+ * Returns the number of distinct combinations of the specified terms.
67
+ *
68
+ * This will only be used if `features.indexDistinctTerms` is true.
69
+ */
70
+ countDistinctTerms?: (termNames: QuadTermName[]) => number;
35
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IRdfJsSourceExtended.js","sourceRoot":"","sources":["IRdfJsSourceExtended.ts"],"names":[],"mappings":"","sourcesContent":["// eslint-disable-next-line import/no-nodejs-modules\nimport type { EventEmitter } from 'node:events';\nimport type * as RDF from '@rdfjs/types';\n\nexport interface IRdfJsSourceExtended extends RDF.Source {\n /**\n * A record indicating supported features of this source.\n */\n features?: {\n /**\n * If true, this source supports passing quad patterns with quoted quad patterns in the `match` method.\n * If false (or if `features` is `undefined`), such quoted quad patterns can not be passed,\n * and must be replaced by `undefined` and filtered by the caller afterwards.\n */\n quotedTripleFiltering?: boolean;\n };\n\n /**\n * Return an estimated count of the number of quads matching the given pattern.\n *\n * The better the estimate, the better the query engine will be able to optimize the query.\n *\n * @param subject An optional subject.\n * @param predicate An optional predicate.\n * @param object An optional object.\n * @param graph An optional graph.\n */\n countQuads?: (\n subject?: RDF.Term,\n predicate?: RDF.Term,\n object?: RDF.Term,\n graph?: RDF.Term,\n ) => Promise<number> | number;\n\n /**\n * Returns a stream that produces all bindings matching the pattern.\n * @param bindingsFactory The factory that will be used to create bindings.\n * @param subject The subject, which can be a variable.\n * @param predicate The predicate, which can be a variable.\n * @param object The object, which can be a variable.\n * @param graph The graph, which can be a variable.\n */\n matchBindings?: (\n bindingsFactory: RDF.BindingsFactory,\n subject: RDF.Term,\n predicate: RDF.Term,\n object: RDF.Term,\n graph: RDF.Term,\n ) => EventEmitter;\n}\n"]}
1
+ {"version":3,"file":"IRdfJsSourceExtended.js","sourceRoot":"","sources":["IRdfJsSourceExtended.ts"],"names":[],"mappings":"","sourcesContent":["// eslint-disable-next-line import/no-nodejs-modules\nimport type { EventEmitter } from 'node:events';\nimport type * as RDF from '@rdfjs/types';\nimport type { QuadTermName } from 'rdf-terms';\n\nexport interface IRdfJsSourceExtended extends RDF.Source {\n /**\n * A record indicating supported features of this source.\n */\n features?: {\n /**\n * If true, this source supports passing quad patterns with quoted quad patterns in the `match` method.\n * If false (or if `features` is `undefined`), such quoted quad patterns can not be passed,\n * and must be replaced by `undefined` and filtered by the caller afterwards.\n */\n quotedTripleFiltering?: boolean;\n /**\n * If this is true, matchNodes and countNodes must be available.\n */\n indexNodes?: boolean;\n /**\n * If this is true, matchDistinctTerms and countDistinctTerms must be available.\n */\n indexDistinctTerms?: boolean;\n };\n\n /**\n * Return an estimated count of the number of quads matching the given pattern.\n *\n * The better the estimate, the better the query engine will be able to optimize the query.\n *\n * @param subject An optional subject.\n * @param predicate An optional predicate.\n * @param object An optional object.\n * @param graph An optional graph.\n */\n countQuads?: (\n subject?: RDF.Term,\n predicate?: RDF.Term,\n object?: RDF.Term,\n graph?: RDF.Term,\n ) => Promise<number> | number;\n\n /**\n * Returns a stream that produces all bindings matching the pattern.\n * @param bindingsFactory The factory that will be used to create bindings.\n * @param subject The subject, which can be a variable.\n * @param predicate The predicate, which can be a variable.\n * @param object The object, which can be a variable.\n * @param graph The graph, which can be a variable.\n */\n matchBindings?: (\n bindingsFactory: RDF.BindingsFactory,\n subject: RDF.Term,\n predicate: RDF.Term,\n object: RDF.Term,\n graph: RDF.Term,\n ) => EventEmitter;\n\n /**\n * Returns a stream that produces all nodes as terms in the given graph.\n * Nodes are all terms that are either a subject or object within the graph.\n *\n * This will only be used if `features.indexNodes` is true.\n */\n matchNodes?: (graph: RDF.Term) => EventEmitter;\n\n /**\n * Returns the number of nodes in the given graph.\n * Nodes are all terms that are either a subject or object within the graph.\n *\n * This will only be used if `features.indexNodes` is true.\n */\n countNodes?: (graph: RDF.Term) => number;\n\n /**\n * Returns a stream that produces all distinct combinations of the specified terms.\n * The stream produces arrays where each element corresponds to a term in the termNames array.\n *\n * This will only be used if `features.indexDistinctTerms` is true.\n */\n matchDistinctTerms?: (termNames: QuadTermName[]) => EventEmitter;\n\n /**\n * Returns the number of distinct combinations of the specified terms.\n *\n * This will only be used if `features.indexDistinctTerms` is true.\n */\n countDistinctTerms?: (termNames: QuadTermName[]) => number;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { IQuerySource, BindingsStream, IActionContext, FragmentSelectorShape, ComunicaDataFactory, QuerySourceReference } from '@comunica/types';
1
+ import type { BindingsStream, ComunicaDataFactory, FragmentSelectorShape, IActionContext, IQuerySource, QuerySourceReference } from '@comunica/types';
2
2
  import { Algebra } from '@comunica/utils-algebra';
3
3
  import type { BindingsFactory } from '@comunica/utils-bindings-factory';
4
4
  import type * as RDF from '@rdfjs/types';
@@ -20,7 +20,7 @@ class QuerySourceRdfJs {
20
20
  this.dataFactory = dataFactory;
21
21
  this.bindingsFactory = bindingsFactory;
22
22
  const AF = new utils_algebra_1.AlgebraFactory(this.dataFactory);
23
- this.selectorShape = {
23
+ let selectorShape = {
24
24
  type: 'operation',
25
25
  operation: {
26
26
  operationType: 'pattern',
@@ -32,6 +32,35 @@ class QuerySourceRdfJs {
32
32
  this.dataFactory.variable('o'),
33
33
  ],
34
34
  };
35
+ const additionalShapes = [];
36
+ if ('features' in this.source && this.source.features?.indexNodes) {
37
+ additionalShapes.push({
38
+ type: 'operation',
39
+ operation: {
40
+ operationType: 'type',
41
+ type: utils_algebra_1.TypesComunica.NODES,
42
+ },
43
+ });
44
+ }
45
+ if ('features' in this.source && this.source.features?.indexDistinctTerms) {
46
+ additionalShapes.push({
47
+ type: 'operation',
48
+ operation: {
49
+ operationType: 'type',
50
+ type: utils_algebra_1.TypesComunica.DISTINCT_TERMS,
51
+ },
52
+ });
53
+ }
54
+ if (additionalShapes.length > 0) {
55
+ selectorShape = {
56
+ type: 'disjunction',
57
+ children: [
58
+ selectorShape,
59
+ ...additionalShapes,
60
+ ],
61
+ };
62
+ }
63
+ this.selectorShape = selectorShape;
35
64
  this.dummyDefaultGraph = this.dataFactory.variable('__comunica:defaultGraph');
36
65
  }
37
66
  static nullifyVariables(term, quotedTripleFiltering) {
@@ -51,6 +80,53 @@ class QuerySourceRdfJs {
51
80
  return 0;
52
81
  }
53
82
  queryBindings(operation, context) {
83
+ if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.TypesComunica.NODES) &&
84
+ 'matchNodes' in this.source && this.source.matchNodes) {
85
+ const rawStream = this.source.matchNodes(operation.graph);
86
+ const isGraphVariable = operation.graph.termType === 'Variable';
87
+ const it = rawStream instanceof asynciterator_1.AsyncIterator ?
88
+ rawStream :
89
+ (0, asynciterator_1.wrap)(rawStream, { autoStart: false });
90
+ const bs = it.map(tuple => this.bindingsFactory.bindings([
91
+ ...(isGraphVariable ? [[operation.graph, tuple[0]]] : []),
92
+ [operation.variable, tuple[1]],
93
+ ]));
94
+ bs.setProperty('metadata', {
95
+ state: new utils_metadata_1.MetadataValidationState(),
96
+ cardinality: {
97
+ type: 'exact',
98
+ value: this.source.countNodes(operation.graph),
99
+ },
100
+ // Force requestTime to zero, since this will be free for future calls, as we're fully indexed at this stage.
101
+ requestTime: 0,
102
+ variables: [
103
+ ...(isGraphVariable ? [{ variable: operation.graph, canBeUndef: false }] : []),
104
+ { variable: operation.variable, canBeUndef: false },
105
+ ],
106
+ });
107
+ return bs;
108
+ }
109
+ if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.TypesComunica.DISTINCT_TERMS) &&
110
+ 'matchDistinctTerms' in this.source && this.source.matchDistinctTerms) {
111
+ // Convert the terms mapping to an array of QuadTermName in the order of variables
112
+ const termNames = operation.variables.map(variable => operation.terms[variable.value]);
113
+ const rawStream = this.source.matchDistinctTerms(termNames);
114
+ const it = rawStream instanceof asynciterator_1.AsyncIterator ?
115
+ rawStream :
116
+ (0, asynciterator_1.wrap)(rawStream, { autoStart: false });
117
+ const bs = it.map(terms => this.bindingsFactory.bindings(operation.variables.map((variable, index) => [variable, terms[index]])));
118
+ bs.setProperty('metadata', {
119
+ state: new utils_metadata_1.MetadataValidationState(),
120
+ cardinality: {
121
+ type: 'exact',
122
+ value: this.source.countDistinctTerms(termNames),
123
+ },
124
+ // Force requestTime to zero, since this will be free for future calls, as we're fully indexed at this stage.
125
+ requestTime: 0,
126
+ variables: operation.variables.map(variable => ({ variable, canBeUndef: false })),
127
+ });
128
+ return bs;
129
+ }
54
130
  if (!(0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATTERN)) {
55
131
  throw new Error(`Attempted to pass non-pattern operation '${operation.type}' to QuerySourceRdfJs`);
56
132
  }
@@ -133,7 +209,7 @@ class QuerySourceRdfJs {
133
209
  let matches = this.source.match(QuerySourceRdfJs.nullifyVariables(operation.subject, quotedTripleFiltering), QuerySourceRdfJs.nullifyVariables(operation.predicate, quotedTripleFiltering), QuerySourceRdfJs.nullifyVariables(operation.object, quotedTripleFiltering), QuerySourceRdfJs.nullifyVariables(operation.graph, quotedTripleFiltering));
134
210
  // If it's not a stream, turn it into one
135
211
  if (typeof matches.on !== 'function') {
136
- matches = (new asynciterator_1.ArrayIterator(matches));
212
+ matches = (new asynciterator_1.ArrayIterator(matches, { autoStart: false }));
137
213
  }
138
214
  matches.on('error', reject);
139
215
  matches.on('end', () => resolve(i));
@@ -1 +1 @@
1
- {"version":3,"file":"QuerySourceRdfJs.js","sourceRoot":"","sources":["QuerySourceRdfJs.ts"],"names":[],"mappings":";;;AAAA,mFAA+G;AAC/G,+DAA+D;AAS/D,2DAAoF;AAEpF,6DAAmE;AAEnE,iDAAwF;AACxF,yCAAqF;AAGrF,MAAa,gBAAgB;IACR,aAAa,CAAwB;IACjD,cAAc,CAAuB;IACzB,MAAM,CAAyC;IACjD,WAAW,CAAsB;IACjC,eAAe,CAAkB;IACjC,iBAAiB,CAAe;IAEjD,YACE,MAAoC,EACpC,WAAgC,EAChC,eAAgC;QAEhC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,MAAM,EAAE,GAAG,IAAI,8BAAc,CAAmB,IAAI,CAAC,WAAW,CAAC,CAAC;QAClE,IAAI,CAAC,aAAa,GAAG;YACnB,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE;gBACT,aAAa,EAAE,SAAS;gBACxB,OAAO,EAAE,EAAE,CAAC,aAAa,CACvB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC9B,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC9B,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAC/B;aACF;YACD,iBAAiB,EAAE;gBACjB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAC9B,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAC9B,IAAI,CAAC,WAAW,CAAC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AE,SAAS,CAAC,KAAK,CAAC,EAC5F,EAAE,SAAS,EAAE,KAAK,EAAE,CACrB,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAEM,YAAY,CACjB,UAAuB,EACvB,QAAwB;QAExB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAEM,SAAS,CACd,UAA6B,EAC7B,QAAwB;QAExB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAEM,QAAQ;QACb,OAAO,oBAAoB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC;IAC7D,CAAC;CACF;AApPD,4CAoPC","sourcesContent":["import { filterMatchingQuotedQuads, getVariables, quadsToBindings } from '@comunica/bus-query-source-identify';\nimport { KeysQueryOperation } from '@comunica/context-entries';\nimport type {\n IQuerySource,\n BindingsStream,\n IActionContext,\n FragmentSelectorShape,\n ComunicaDataFactory,\n QuerySourceReference,\n} from '@comunica/types';\nimport { Algebra, AlgebraFactory, isKnownOperation } from '@comunica/utils-algebra';\nimport type { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { MetadataValidationState } from '@comunica/utils-metadata';\nimport type * as RDF from '@rdfjs/types';\nimport { ArrayIterator, AsyncIterator, wrap as wrapAsyncIterator } from 'asynciterator';\nimport { someTermsNested, filterTermsNested, someTerms, uniqTerms } from 'rdf-terms';\nimport type { IRdfJsSourceExtended } from './IRdfJsSourceExtended';\n\nexport class QuerySourceRdfJs implements IQuerySource {\n protected readonly selectorShape: FragmentSelectorShape;\n public referenceValue: QuerySourceReference;\n protected readonly source: IRdfJsSourceExtended | RDF.DatasetCore;\n private readonly dataFactory: ComunicaDataFactory;\n private readonly bindingsFactory: BindingsFactory;\n private readonly dummyDefaultGraph: RDF.Variable;\n\n public constructor(\n source: RDF.Source | RDF.DatasetCore,\n dataFactory: ComunicaDataFactory,\n bindingsFactory: BindingsFactory,\n ) {\n this.source = source;\n this.referenceValue = source;\n this.dataFactory = dataFactory;\n this.bindingsFactory = bindingsFactory;\n const AF = new AlgebraFactory(<RDF.DataFactory> this.dataFactory);\n this.selectorShape = {\n type: 'operation',\n operation: {\n operationType: 'pattern',\n pattern: AF.createPattern(\n this.dataFactory.variable('s'),\n this.dataFactory.variable('p'),\n this.dataFactory.variable('o'),\n ),\n },\n variablesOptional: [\n this.dataFactory.variable('s'),\n this.dataFactory.variable('p'),\n this.dataFactory.variable('o'),\n ],\n };\n this.dummyDefaultGraph = this.dataFactory.variable('__comunica:defaultGraph');\n }\n\n public static nullifyVariables(term: RDF.Term | undefined, quotedTripleFiltering: boolean): RDF.Term | undefined {\n return !term || term.termType === 'Variable' || (!quotedTripleFiltering &&\n term.termType === 'Quad' && someTermsNested(term, value => value.termType === 'Variable')) ?\n undefined :\n term;\n }\n\n public static hasDuplicateVariables(pattern: RDF.BaseQuad): boolean {\n const variables = filterTermsNested(pattern, term => term.termType === 'Variable');\n return variables.length > 1 && uniqTerms(variables).length < variables.length;\n }\n\n public async getSelectorShape(): Promise<FragmentSelectorShape> {\n return this.selectorShape;\n }\n\n public async getFilterFactor(): Promise<number> {\n return 0;\n }\n\n public queryBindings(operation: Algebra.Operation, context: IActionContext): BindingsStream {\n if (!isKnownOperation(operation, Algebra.Types.PATTERN)) {\n throw new Error(`Attempted to pass non-pattern operation '${operation.type}' to QuerySourceRdfJs`);\n }\n\n // Check if we're running in union default graph mode\n const unionDefaultGraph = Boolean(context.get(KeysQueryOperation.unionDefaultGraph));\n if (operation.graph.termType === 'DefaultGraph' && unionDefaultGraph) {\n operation.graph = this.dummyDefaultGraph;\n }\n\n // Get bindings directly if the source allows it\n // This will be more efficient, as it avoids the intermediary quads translation and representation.\n if ('matchBindings' in this.source && this.source.matchBindings) {\n const rawStream = this.source.matchBindings(\n this.bindingsFactory,\n operation.subject,\n operation.predicate,\n operation.object,\n operation.graph,\n );\n let it: AsyncIterator<RDF.Bindings> = rawStream instanceof AsyncIterator ?\n rawStream :\n wrapAsyncIterator<RDF.Bindings>(rawStream, { autoStart: false });\n\n // Check if non-default-graph triples need to be filtered out.\n // SPARQL query semantics allow graph variables to only match with named graphs, excluding the default graph\n // But this is not the case when using union default graph semantics\n let forceEstimateCardinality = false;\n if (operation.graph.termType === 'Variable' && !unionDefaultGraph) {\n forceEstimateCardinality = true;\n const variable = operation.graph;\n it = it.filter(bindings => bindings.get(variable)!.termType !== 'DefaultGraph');\n }\n\n // Remove bindings to the dummy __comunica:defaultGraph variable if needed\n if (operation.graph.equals(this.dummyDefaultGraph)) {\n it = it.map(bindings => bindings.delete(this.dummyDefaultGraph));\n // Restore graph for determining variable metadata\n operation.graph = this.dataFactory.defaultGraph();\n }\n\n // Determine metadata\n if (!it.getProperty('metadata')) {\n const variables = getVariables(operation).map(variable => ({ variable, canBeUndef: false }));\n this.setMetadata(it, operation, context, forceEstimateCardinality, { variables })\n .catch(error => it.destroy(error));\n }\n\n return it;\n }\n\n // Check if the source supports quoted triple filtering\n const quotedTripleFiltering = Boolean('features' in this.source && this.source.features?.quotedTripleFiltering);\n\n // Create an async iterator from the matched quad stream\n const rawStream = this.source.match(\n QuerySourceRdfJs.nullifyVariables(operation.subject, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.predicate, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.object, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.graph, quotedTripleFiltering),\n );\n let it: AsyncIterator<RDF.Quad> = rawStream instanceof AsyncIterator ?\n rawStream :\n wrapAsyncIterator<RDF.Quad>(rawStream, { autoStart: false });\n\n // Perform post-match-filtering if the source does not support quoted triple filtering.\n if (!quotedTripleFiltering) {\n it = filterMatchingQuotedQuads(operation, it);\n }\n\n // Determine metadata\n if (!it.getProperty('metadata')) {\n this.setMetadata(it, operation, context)\n .catch(error => it.destroy(error));\n }\n\n // Restore graph for determining variable metadata\n if (operation.graph.equals(this.dummyDefaultGraph)) {\n operation.graph = this.dataFactory.defaultGraph();\n }\n\n return quadsToBindings(\n it,\n operation,\n this.dataFactory,\n this.bindingsFactory,\n Boolean(context.get(KeysQueryOperation.unionDefaultGraph)),\n );\n }\n\n protected async setMetadata(\n it: AsyncIterator<any>,\n operation: Algebra.Pattern,\n context: IActionContext,\n forceEstimateCardinality = false,\n extraMetadata: Record<string, any> = {},\n ): Promise<void> {\n // Check if the source supports quoted triple filtering\n const quotedTripleFiltering = Boolean('features' in this.source && this.source.features?.quotedTripleFiltering);\n\n // Check if we're running in union default graph mode\n const unionDefaultGraph = Boolean(context.get(KeysQueryOperation.unionDefaultGraph));\n if (operation.graph.termType === 'DefaultGraph' && unionDefaultGraph) {\n operation.graph = this.dummyDefaultGraph;\n }\n\n let cardinality: number;\n if ('countQuads' in this.source && this.source.countQuads) {\n // If the source provides a dedicated method for determining cardinality, use that.\n cardinality = await this.source.countQuads(\n QuerySourceRdfJs.nullifyVariables(operation.subject, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.predicate, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.object, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.graph, quotedTripleFiltering),\n );\n } else {\n // Otherwise, fallback to a sub-optimal alternative where we just call match again to count the quads.\n // WARNING: we can NOT reuse the original data stream here,\n // because we may lose data elements due to things happening async.\n let i = 0;\n cardinality = await new Promise((resolve, reject) => {\n let matches = this.source.match(\n QuerySourceRdfJs.nullifyVariables(operation.subject, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.predicate, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.object, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.graph, quotedTripleFiltering),\n );\n\n // If it's not a stream, turn it into one\n if (typeof (<any> matches).on !== 'function') {\n matches = <RDF.Stream>(new ArrayIterator(<RDF.DatasetCore> matches));\n }\n\n (<RDF.Stream>matches).on('error', reject);\n (<RDF.Stream>matches).on('end', () => resolve(i));\n (<RDF.Stream>matches).on('data', () => i++);\n });\n }\n\n // If `match` would require filtering afterwards, our count will be an over-estimate.\n const wouldRequirePostFiltering = (!quotedTripleFiltering &&\n someTerms(operation, term => term.termType === 'Quad')) ||\n QuerySourceRdfJs.hasDuplicateVariables(operation);\n\n it.setProperty('metadata', {\n state: new MetadataValidationState(),\n cardinality: {\n type: wouldRequirePostFiltering || forceEstimateCardinality ? 'estimate' : 'exact',\n value: cardinality,\n },\n // Force requestTime to zero, since this will be free for future calls, as we're fully indexed at this stage.\n requestTime: 0,\n ...extraMetadata,\n });\n }\n\n public queryQuads(\n operation: Algebra.Operation,\n _context: IActionContext,\n ): AsyncIterator<RDF.Quad> {\n if (isKnownOperation(operation, Algebra.Types.PATTERN)) {\n return wrapAsyncIterator<RDF.Quad>(\n this.source.match(operation.subject, operation.predicate, operation.object, operation.graph),\n { autoStart: false },\n );\n }\n throw new Error('queryQuads is not implemented in QuerySourceRdfJs');\n }\n\n public queryBoolean(\n _operation: Algebra.Ask,\n _context: IActionContext,\n ): Promise<boolean> {\n throw new Error('queryBoolean is not implemented in QuerySourceRdfJs');\n }\n\n public queryVoid(\n _operation: Algebra.Operation,\n _context: IActionContext,\n ): Promise<void> {\n throw new Error('queryVoid is not implemented in QuerySourceRdfJs');\n }\n\n public toString(): string {\n return `QuerySourceRdfJs(${this.source.constructor.name})`;\n }\n}\n"]}
1
+ {"version":3,"file":"QuerySourceRdfJs.js","sourceRoot":"","sources":["QuerySourceRdfJs.ts"],"names":[],"mappings":";;;AAAA,mFAA+G;AAC/G,+DAA+D;AAS/D,2DAAmG;AAEnG,6DAAmE;AAEnE,iDAAwF;AACxF,yCAAqF;AAGrF,MAAa,gBAAgB;IACR,aAAa,CAAwB;IACjD,cAAc,CAAuB;IACzB,MAAM,CAAyC;IACjD,WAAW,CAAsB;IACjC,eAAe,CAAkB;IACjC,iBAAiB,CAAe;IAEjD,YACE,MAAoC,EACp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C,WAAW,CAAC,UAAU,EAAE;YACzB,KAAK,EAAE,IAAI,wCAAuB,EAAE;YACpC,WAAW,EAAE;gBACX,IAAI,EAAE,yBAAyB,IAAI,wBAAwB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO;gBAClF,KAAK,EAAE,WAAW;aACnB;YACD,6GAA6G;YAC7G,WAAW,EAAE,CAAC;YACd,GAAG,aAAa;SACjB,CAAC,CAAC;IACL,CAAC;IAEM,UAAU,CACf,SAA4B,EAC5B,QAAwB;QAExB,IAAI,IAAA,gCAAgB,EAAC,SAAS,EAAE,uBAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACvD,OAAO,IAAA,oBAAiB,EACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,EAC5F,EAAE,SAAS,EAAE,KAAK,EAAE,CACrB,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAEM,YAAY,CACjB,UAAuB,EACvB,QAAwB;QAExB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAEM,SAAS,CACd,UAA6B,EAC7B,QAAwB;QAExB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAEM,QAAQ;QACb,OAAO,oBAAoB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC;IAC7D,CAAC;CACF;AArUD,4CAqUC","sourcesContent":["import { filterMatchingQuotedQuads, getVariables, quadsToBindings } from '@comunica/bus-query-source-identify';\nimport { KeysQueryOperation } from '@comunica/context-entries';\nimport type {\n BindingsStream,\n ComunicaDataFactory,\n FragmentSelectorShape,\n IActionContext,\n IQuerySource,\n QuerySourceReference,\n} from '@comunica/types';\nimport { Algebra, AlgebraFactory, isKnownOperation, TypesComunica } from '@comunica/utils-algebra';\nimport type { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { MetadataValidationState } from '@comunica/utils-metadata';\nimport type * as RDF from '@rdfjs/types';\nimport { ArrayIterator, AsyncIterator, wrap as wrapAsyncIterator } from 'asynciterator';\nimport { filterTermsNested, someTerms, someTermsNested, uniqTerms } from 'rdf-terms';\nimport type { IRdfJsSourceExtended } from './IRdfJsSourceExtended';\n\nexport class QuerySourceRdfJs implements IQuerySource {\n protected readonly selectorShape: FragmentSelectorShape;\n public referenceValue: QuerySourceReference;\n protected readonly source: IRdfJsSourceExtended | RDF.DatasetCore;\n private readonly dataFactory: ComunicaDataFactory;\n private readonly bindingsFactory: BindingsFactory;\n private readonly dummyDefaultGraph: RDF.Variable;\n\n public constructor(\n source: RDF.Source | RDF.DatasetCore,\n dataFactory: ComunicaDataFactory,\n bindingsFactory: BindingsFactory,\n ) {\n this.source = source;\n this.referenceValue = source;\n this.dataFactory = dataFactory;\n this.bindingsFactory = bindingsFactory;\n const AF = new AlgebraFactory(<RDF.DataFactory> this.dataFactory);\n let selectorShape: FragmentSelectorShape = {\n type: 'operation',\n operation: {\n operationType: 'pattern',\n pattern: AF.createPattern(\n this.dataFactory.variable('s'),\n this.dataFactory.variable('p'),\n this.dataFactory.variable('o'),\n ),\n },\n variablesOptional: [\n this.dataFactory.variable('s'),\n this.dataFactory.variable('p'),\n this.dataFactory.variable('o'),\n ],\n };\n const additionalShapes: FragmentSelectorShape[] = [];\n if ('features' in this.source && this.source.features?.indexNodes) {\n additionalShapes.push({\n type: 'operation',\n operation: {\n operationType: 'type',\n type: TypesComunica.NODES,\n },\n });\n }\n if ('features' in this.source && this.source.features?.indexDistinctTerms) {\n additionalShapes.push({\n type: 'operation',\n operation: {\n operationType: 'type',\n type: TypesComunica.DISTINCT_TERMS,\n },\n });\n }\n if (additionalShapes.length > 0) {\n selectorShape = {\n type: 'disjunction',\n children: [\n selectorShape,\n ...additionalShapes,\n ],\n };\n }\n this.selectorShape = selectorShape;\n this.dummyDefaultGraph = this.dataFactory.variable('__comunica:defaultGraph');\n }\n\n public static nullifyVariables(term: RDF.Term | undefined, quotedTripleFiltering: boolean): RDF.Term | undefined {\n return !term || term.termType === 'Variable' || (!quotedTripleFiltering &&\n term.termType === 'Quad' && someTermsNested(term, value => value.termType === 'Variable')) ?\n undefined :\n term;\n }\n\n public static hasDuplicateVariables(pattern: RDF.BaseQuad): boolean {\n const variables = filterTermsNested(pattern, term => term.termType === 'Variable');\n return variables.length > 1 && uniqTerms(variables).length < variables.length;\n }\n\n public async getSelectorShape(): Promise<FragmentSelectorShape> {\n return this.selectorShape;\n }\n\n public async getFilterFactor(): Promise<number> {\n return 0;\n }\n\n public queryBindings(operation: Algebra.Operation, context: IActionContext): BindingsStream {\n if (isKnownOperation(operation, TypesComunica.NODES) &&\n 'matchNodes' in this.source && this.source.matchNodes) {\n const rawStream = this.source.matchNodes(operation.graph);\n const isGraphVariable = operation.graph.termType === 'Variable';\n const it: AsyncIterator<[ RDF.Term, RDF.Term ]> = rawStream instanceof AsyncIterator ?\n rawStream :\n wrapAsyncIterator<[ RDF.Term, RDF.Term ]>(rawStream, { autoStart: false });\n const bs = it.map<RDF.Bindings>(tuple => this.bindingsFactory.bindings([\n ...(isGraphVariable ? [ <[RDF.Variable, RDF.Term]> [ <RDF.Variable> operation.graph, tuple[0] ] ] : []),\n [ operation.variable, tuple[1] ],\n ]));\n bs.setProperty('metadata', {\n state: new MetadataValidationState(),\n cardinality: {\n type: 'exact',\n value: this.source.countNodes!(operation.graph),\n },\n // Force requestTime to zero, since this will be free for future calls, as we're fully indexed at this stage.\n requestTime: 0,\n variables: [\n ...(isGraphVariable ? [{ variable: operation.graph, canBeUndef: false }] : []),\n { variable: operation.variable, canBeUndef: false },\n ],\n });\n return bs;\n }\n\n if (isKnownOperation(operation, TypesComunica.DISTINCT_TERMS) &&\n 'matchDistinctTerms' in this.source && this.source.matchDistinctTerms) {\n // Convert the terms mapping to an array of QuadTermName in the order of variables\n const termNames: any[] = operation.variables.map(variable => operation.terms[variable.value]);\n\n const rawStream = this.source.matchDistinctTerms(termNames);\n const it: AsyncIterator<RDF.Term[]> = rawStream instanceof AsyncIterator ?\n rawStream :\n wrapAsyncIterator<RDF.Term[]>(rawStream, { autoStart: false });\n const bs = it.map<RDF.Bindings>(terms => this.bindingsFactory.bindings(\n operation.variables.map((variable, index) => [ variable, terms[index] ]),\n ));\n bs.setProperty('metadata', {\n state: new MetadataValidationState(),\n cardinality: {\n type: 'exact',\n value: this.source.countDistinctTerms!(termNames),\n },\n // Force requestTime to zero, since this will be free for future calls, as we're fully indexed at this stage.\n requestTime: 0,\n variables: operation.variables.map(variable => ({ variable, canBeUndef: false })),\n });\n return bs;\n }\n\n if (!isKnownOperation(operation, Algebra.Types.PATTERN)) {\n throw new Error(`Attempted to pass non-pattern operation '${operation.type}' to QuerySourceRdfJs`);\n }\n\n // Check if we're running in union default graph mode\n const unionDefaultGraph = Boolean(context.get(KeysQueryOperation.unionDefaultGraph));\n if (operation.graph.termType === 'DefaultGraph' && unionDefaultGraph) {\n operation.graph = this.dummyDefaultGraph;\n }\n\n // Get bindings directly if the source allows it\n // This will be more efficient, as it avoids the intermediary quads translation and representation.\n if ('matchBindings' in this.source && this.source.matchBindings) {\n const rawStream = this.source.matchBindings(\n this.bindingsFactory,\n operation.subject,\n operation.predicate,\n operation.object,\n operation.graph,\n );\n let it: AsyncIterator<RDF.Bindings> = rawStream instanceof AsyncIterator ?\n rawStream :\n wrapAsyncIterator<RDF.Bindings>(rawStream, { autoStart: false });\n\n // Check if non-default-graph triples need to be filtered out.\n // SPARQL query semantics allow graph variables to only match with named graphs, excluding the default graph\n // But this is not the case when using union default graph semantics\n let forceEstimateCardinality = false;\n if (operation.graph.termType === 'Variable' && !unionDefaultGraph) {\n forceEstimateCardinality = true;\n const variable = operation.graph;\n it = it.filter(bindings => bindings.get(variable)!.termType !== 'DefaultGraph');\n }\n\n // Remove bindings to the dummy __comunica:defaultGraph variable if needed\n if (operation.graph.equals(this.dummyDefaultGraph)) {\n it = it.map(bindings => bindings.delete(this.dummyDefaultGraph));\n // Restore graph for determining variable metadata\n operation.graph = this.dataFactory.defaultGraph();\n }\n\n // Determine metadata\n if (!it.getProperty('metadata')) {\n const variables = getVariables(operation).map(variable => ({ variable, canBeUndef: false }));\n this.setMetadata(it, operation, context, forceEstimateCardinality, { variables })\n .catch(error => it.destroy(error));\n }\n\n return it;\n }\n\n // Check if the source supports quoted triple filtering\n const quotedTripleFiltering = Boolean('features' in this.source && this.source.features?.quotedTripleFiltering);\n\n // Create an async iterator from the matched quad stream\n const rawStream = this.source.match(\n QuerySourceRdfJs.nullifyVariables(operation.subject, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.predicate, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.object, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.graph, quotedTripleFiltering),\n );\n let it: AsyncIterator<RDF.Quad> = rawStream instanceof AsyncIterator ?\n rawStream :\n wrapAsyncIterator<RDF.Quad>(rawStream, { autoStart: false });\n\n // Perform post-match-filtering if the source does not support quoted triple filtering.\n if (!quotedTripleFiltering) {\n it = filterMatchingQuotedQuads(operation, it);\n }\n\n // Determine metadata\n if (!it.getProperty('metadata')) {\n this.setMetadata(it, operation, context)\n .catch(error => it.destroy(error));\n }\n\n // Restore graph for determining variable metadata\n if (operation.graph.equals(this.dummyDefaultGraph)) {\n operation.graph = this.dataFactory.defaultGraph();\n }\n\n return quadsToBindings(\n it,\n operation,\n this.dataFactory,\n this.bindingsFactory,\n Boolean(context.get(KeysQueryOperation.unionDefaultGraph)),\n );\n }\n\n protected async setMetadata(\n it: AsyncIterator<any>,\n operation: Algebra.Pattern,\n context: IActionContext,\n forceEstimateCardinality = false,\n extraMetadata: Record<string, any> = {},\n ): Promise<void> {\n // Check if the source supports quoted triple filtering\n const quotedTripleFiltering = Boolean('features' in this.source && this.source.features?.quotedTripleFiltering);\n\n // Check if we're running in union default graph mode\n const unionDefaultGraph = Boolean(context.get(KeysQueryOperation.unionDefaultGraph));\n if (operation.graph.termType === 'DefaultGraph' && unionDefaultGraph) {\n operation.graph = this.dummyDefaultGraph;\n }\n\n let cardinality: number;\n if ('countQuads' in this.source && this.source.countQuads) {\n // If the source provides a dedicated method for determining cardinality, use that.\n cardinality = await this.source.countQuads(\n QuerySourceRdfJs.nullifyVariables(operation.subject, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.predicate, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.object, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.graph, quotedTripleFiltering),\n );\n } else {\n // Otherwise, fallback to a sub-optimal alternative where we just call match again to count the quads.\n // WARNING: we can NOT reuse the original data stream here,\n // because we may lose data elements due to things happening async.\n let i = 0;\n cardinality = await new Promise((resolve, reject) => {\n let matches = this.source.match(\n QuerySourceRdfJs.nullifyVariables(operation.subject, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.predicate, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.object, quotedTripleFiltering),\n QuerySourceRdfJs.nullifyVariables(operation.graph, quotedTripleFiltering),\n );\n\n // If it's not a stream, turn it into one\n if (typeof (<any> matches).on !== 'function') {\n matches = <RDF.Stream>(new ArrayIterator(<RDF.DatasetCore> matches, { autoStart: false }));\n }\n\n (<RDF.Stream>matches).on('error', reject);\n (<RDF.Stream>matches).on('end', () => resolve(i));\n (<RDF.Stream>matches).on('data', () => i++);\n });\n }\n\n // If `match` would require filtering afterwards, our count will be an over-estimate.\n const wouldRequirePostFiltering = (!quotedTripleFiltering &&\n someTerms(operation, term => term.termType === 'Quad')) ||\n QuerySourceRdfJs.hasDuplicateVariables(operation);\n\n it.setProperty('metadata', {\n state: new MetadataValidationState(),\n cardinality: {\n type: wouldRequirePostFiltering || forceEstimateCardinality ? 'estimate' : 'exact',\n value: cardinality,\n },\n // Force requestTime to zero, since this will be free for future calls, as we're fully indexed at this stage.\n requestTime: 0,\n ...extraMetadata,\n });\n }\n\n public queryQuads(\n operation: Algebra.Operation,\n _context: IActionContext,\n ): AsyncIterator<RDF.Quad> {\n if (isKnownOperation(operation, Algebra.Types.PATTERN)) {\n return wrapAsyncIterator<RDF.Quad>(\n this.source.match(operation.subject, operation.predicate, operation.object, operation.graph),\n { autoStart: false },\n );\n }\n throw new Error('queryQuads is not implemented in QuerySourceRdfJs');\n }\n\n public queryBoolean(\n _operation: Algebra.Ask,\n _context: IActionContext,\n ): Promise<boolean> {\n throw new Error('queryBoolean is not implemented in QuerySourceRdfJs');\n }\n\n public queryVoid(\n _operation: Algebra.Operation,\n _context: IActionContext,\n ): Promise<void> {\n throw new Error('queryVoid is not implemented in QuerySourceRdfJs');\n }\n\n public toString(): string {\n return `QuerySourceRdfJs(${this.source.constructor.name})`;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-query-source-identify-rdfjs",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "A rdfjs query-source-identify actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -41,17 +41,17 @@
41
41
  "build:components": "componentsjs-generator"
42
42
  },
43
43
  "dependencies": {
44
- "@comunica/bus-merge-bindings-context": "^5.1.0",
45
- "@comunica/bus-query-source-identify": "^5.1.0",
46
- "@comunica/context-entries": "^5.1.0",
47
- "@comunica/core": "^5.1.0",
48
- "@comunica/types": "^5.1.0",
49
- "@comunica/utils-algebra": "^5.0.0",
50
- "@comunica/utils-bindings-factory": "^5.1.0",
51
- "@comunica/utils-metadata": "^5.1.0",
44
+ "@comunica/bus-merge-bindings-context": "^5.2.0",
45
+ "@comunica/bus-query-source-identify": "^5.2.0",
46
+ "@comunica/context-entries": "^5.2.0",
47
+ "@comunica/core": "^5.2.0",
48
+ "@comunica/types": "^5.2.0",
49
+ "@comunica/utils-algebra": "^5.2.0",
50
+ "@comunica/utils-bindings-factory": "^5.2.0",
51
+ "@comunica/utils-metadata": "^5.2.0",
52
52
  "@rdfjs/types": "*",
53
53
  "asynciterator": "^3.10.0",
54
54
  "rdf-terms": "^2.0.0"
55
55
  },
56
- "gitHead": "e13930973fd305fd6b233e2535ed4e636de7ebeb"
56
+ "gitHead": "ebb0e79bddcd850fcb8d0fb5b422af88e67fa283"
57
57
  }