@comunica/actor-query-source-identify-rdfjs 4.0.2 → 4.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.
- package/components/ActorQuerySourceIdentifyRdfJs.jsonld +0 -0
- package/components/IRdfJsSourceExtended.jsonld +4 -0
- package/components/QuerySourceRdfJs.jsonld +0 -0
- package/components/components.jsonld +0 -0
- package/components/context.jsonld +0 -0
- package/lib/ActorQuerySourceIdentifyRdfJs.d.ts +0 -0
- package/lib/ActorQuerySourceIdentifyRdfJs.js +0 -0
- package/lib/ActorQuerySourceIdentifyRdfJs.js.map +0 -0
- package/lib/IRdfJsSourceExtended.d.ts +11 -0
- package/lib/IRdfJsSourceExtended.js +0 -0
- package/lib/IRdfJsSourceExtended.js.map +1 -1
- package/lib/QuerySourceRdfJs.d.ts +1 -1
- package/lib/QuerySourceRdfJs.js +32 -2
- package/lib/QuerySourceRdfJs.js.map +1 -1
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/index.js.map +0 -0
- package/package.json +9 -9
|
File without changes
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
{
|
|
18
18
|
"@id": "caqsir:components/IRdfJsSourceExtended.jsonld#IRdfJsSourceExtended__member_countQuads",
|
|
19
19
|
"memberFieldName": "countQuads"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"@id": "caqsir:components/IRdfJsSourceExtended.jsonld#IRdfJsSourceExtended__member_matchBindings",
|
|
23
|
+
"memberFieldName": "matchBindings"
|
|
20
24
|
}
|
|
21
25
|
],
|
|
22
26
|
"constructorArguments": []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { EventEmitter } from 'node:events';
|
|
1
3
|
import type * as RDF from '@rdfjs/types';
|
|
2
4
|
export interface IRdfJsSourceExtended extends RDF.Source {
|
|
3
5
|
/**
|
|
@@ -22,4 +24,13 @@ export interface IRdfJsSourceExtended extends RDF.Source {
|
|
|
22
24
|
* @param graph An optional graph.
|
|
23
25
|
*/
|
|
24
26
|
countQuads?: (subject?: RDF.Term, predicate?: RDF.Term, object?: RDF.Term, graph?: RDF.Term) => Promise<number> | number;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a stream that produces all bindings matching the pattern.
|
|
29
|
+
* @param bindingsFactory The factory that will be used to create bindings.
|
|
30
|
+
* @param subject The subject, which can be a variable.
|
|
31
|
+
* @param predicate The predicate, which can be a variable.
|
|
32
|
+
* @param object The object, which can be a variable.
|
|
33
|
+
* @param graph The graph, which can be a variable.
|
|
34
|
+
*/
|
|
35
|
+
matchBindings?: (bindingsFactory: RDF.BindingsFactory, subject: RDF.Term, predicate: RDF.Term, object: RDF.Term, graph: RDF.Term) => EventEmitter;
|
|
25
36
|
}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IRdfJsSourceExtended.js","sourceRoot":"","sources":["IRdfJsSourceExtended.ts"],"names":[],"mappings":"","sourcesContent":["import 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"]}
|
|
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"]}
|
|
@@ -15,7 +15,7 @@ export declare class QuerySourceRdfJs implements IQuerySource {
|
|
|
15
15
|
static hasDuplicateVariables(pattern: RDF.BaseQuad): boolean;
|
|
16
16
|
getSelectorShape(): Promise<FragmentSelectorShape>;
|
|
17
17
|
queryBindings(operation: Algebra.Operation, context: IActionContext): BindingsStream;
|
|
18
|
-
protected setMetadata(it: AsyncIterator<
|
|
18
|
+
protected setMetadata(it: AsyncIterator<any>, operation: Algebra.Pattern, forceEstimateCardinality?: boolean, extraMetadata?: Record<string, any>): Promise<void>;
|
|
19
19
|
queryQuads(_operation: Algebra.Operation, _context: IActionContext): AsyncIterator<RDF.Quad>;
|
|
20
20
|
queryBoolean(_operation: Algebra.Ask, _context: IActionContext): Promise<boolean>;
|
|
21
21
|
queryVoid(_operation: Algebra.Update, _context: IActionContext): Promise<void>;
|
package/lib/QuerySourceRdfJs.js
CHANGED
|
@@ -44,6 +44,30 @@ class QuerySourceRdfJs {
|
|
|
44
44
|
if (operation.type !== 'pattern') {
|
|
45
45
|
throw new Error(`Attempted to pass non-pattern operation '${operation.type}' to QuerySourceRdfJs`);
|
|
46
46
|
}
|
|
47
|
+
// Get bindings directly if the source allows it
|
|
48
|
+
// This will be more efficient, as it avoids the intermediary quads translation and representation.
|
|
49
|
+
if (this.source.matchBindings) {
|
|
50
|
+
const rawStream = this.source.matchBindings(this.bindingsFactory, operation.subject, operation.predicate, operation.object, operation.graph);
|
|
51
|
+
let it = rawStream instanceof asynciterator_1.AsyncIterator ?
|
|
52
|
+
rawStream :
|
|
53
|
+
(0, asynciterator_1.wrap)(rawStream, { autoStart: false });
|
|
54
|
+
// Check if non-default-graph triples need to be filtered out.
|
|
55
|
+
// SPARQL query semantics allow graph variables to only match with named graphs, excluding the default graph
|
|
56
|
+
// But this is not the case when using union default graph semantics
|
|
57
|
+
let forceEstimateCardinality = false;
|
|
58
|
+
if (operation.graph.termType === 'Variable' && !context.get(context_entries_1.KeysQueryOperation.unionDefaultGraph)) {
|
|
59
|
+
forceEstimateCardinality = true;
|
|
60
|
+
const variable = operation.graph;
|
|
61
|
+
it = it.filter(bindings => bindings.get(variable).termType !== 'DefaultGraph');
|
|
62
|
+
}
|
|
63
|
+
// Determine metadata
|
|
64
|
+
if (!it.getProperty('metadata')) {
|
|
65
|
+
const variables = (0, bus_query_source_identify_1.getVariables)(operation).map(variable => ({ variable, canBeUndef: false }));
|
|
66
|
+
this.setMetadata(it, operation, forceEstimateCardinality, { variables })
|
|
67
|
+
.catch(error => it.destroy(error));
|
|
68
|
+
}
|
|
69
|
+
return it;
|
|
70
|
+
}
|
|
47
71
|
// Check if the source supports quoted triple filtering
|
|
48
72
|
const quotedTripleFiltering = Boolean(this.source.features?.quotedTripleFiltering);
|
|
49
73
|
// Create an async iterator from the matched quad stream
|
|
@@ -62,7 +86,7 @@ class QuerySourceRdfJs {
|
|
|
62
86
|
}
|
|
63
87
|
return (0, bus_query_source_identify_1.quadsToBindings)(it, operation, this.dataFactory, this.bindingsFactory, Boolean(context.get(context_entries_1.KeysQueryOperation.unionDefaultGraph)));
|
|
64
88
|
}
|
|
65
|
-
async setMetadata(it, operation) {
|
|
89
|
+
async setMetadata(it, operation, forceEstimateCardinality = false, extraMetadata = {}) {
|
|
66
90
|
// Check if the source supports quoted triple filtering
|
|
67
91
|
const quotedTripleFiltering = Boolean(this.source.features?.quotedTripleFiltering);
|
|
68
92
|
let cardinality;
|
|
@@ -88,7 +112,13 @@ class QuerySourceRdfJs {
|
|
|
88
112
|
QuerySourceRdfJs.hasDuplicateVariables(operation);
|
|
89
113
|
it.setProperty('metadata', {
|
|
90
114
|
state: new utils_metadata_1.MetadataValidationState(),
|
|
91
|
-
cardinality: {
|
|
115
|
+
cardinality: {
|
|
116
|
+
type: wouldRequirePostFiltering || forceEstimateCardinality ? 'estimate' : 'exact',
|
|
117
|
+
value: cardinality,
|
|
118
|
+
},
|
|
119
|
+
// Force requestTime to zero, since this will be free for future calls, as we're fully indexed at this stage.
|
|
120
|
+
requestTime: 0,
|
|
121
|
+
...extraMetadata,
|
|
92
122
|
});
|
|
93
123
|
}
|
|
94
124
|
queryQuads(_operation, _context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuerySourceRdfJs.js","sourceRoot":"","sources":["QuerySourceRdfJs.ts"],"names":[],"mappings":";;;AAAA,mFAAiG;AACjG,+DAA+D;AAS/D,6DAAmE;AAEnE,iDAAyE;AACzE,yCAAqF;AAErF,qDAA0C;AAG1C,MAAa,gBAAgB;IAO3B,YAAmB,MAAkB,EAAE,WAAgC,EAAE,eAAgC;QACvG,IAAI,CAAC,MAAM,GA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AAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAEM,SAAS,CACd,UAA0B,EAC1B,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;AA3JD,4CA2JC","sourcesContent":["import { filterMatchingQuotedQuads, 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} from '@comunica/types';\nimport type { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { MetadataValidationState } from '@comunica/utils-metadata';\nimport type * as RDF from '@rdfjs/types';\nimport { AsyncIterator, wrap as wrapAsyncIterator } from 'asynciterator';\nimport { someTermsNested, filterTermsNested, someTerms, uniqTerms } from 'rdf-terms';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport { Factory } from 'sparqlalgebrajs';\nimport type { IRdfJsSourceExtended } from './IRdfJsSourceExtended';\n\nexport class QuerySourceRdfJs implements IQuerySource {\n protected readonly selectorShape: FragmentSelectorShape;\n public referenceValue: string | RDF.Source;\n protected readonly source: IRdfJsSourceExtended;\n private readonly dataFactory: ComunicaDataFactory;\n private readonly bindingsFactory: BindingsFactory;\n\n public constructor(source: RDF.Source, dataFactory: ComunicaDataFactory, bindingsFactory: BindingsFactory) {\n this.source = source;\n this.referenceValue = source;\n this.dataFactory = dataFactory;\n this.bindingsFactory = bindingsFactory;\n const AF = new Factory(<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 }\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 queryBindings(operation: Algebra.Operation, context: IActionContext): BindingsStream {\n if (operation.type !== 'pattern') {\n throw new Error(`Attempted to pass non-pattern operation '${operation.type}' to QuerySourceRdfJs`);\n }\n\n // Check if the source supports quoted triple filtering\n const quotedTripleFiltering = Boolean(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)\n .catch(error => it.destroy(error));\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<RDF.Quad>,\n operation: Algebra.Pattern,\n ): Promise<void> {\n // Check if the source supports quoted triple filtering\n const quotedTripleFiltering = Boolean(this.source.features?.quotedTripleFiltering);\n\n let cardinality: number;\n if (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 const 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 matches.on('error', reject);\n matches.on('end', () => resolve(i));\n 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: { type: wouldRequirePostFiltering ? 'estimate' : 'exact', value: cardinality },\n });\n }\n\n public queryQuads(\n _operation: Algebra.Operation,\n _context: IActionContext,\n ): AsyncIterator<RDF.Quad> {\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.Update,\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,6DAAmE;AAEnE,iDAAyE;AACzE,yCAAqF;AAErF,qDAA0C;AAG1C,MAAa,gBAAgB;IAO3B,YAAmB,MAAkB,EAAE,WAAgC,EAAE,eAAgC;QACvG,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,yBAAO,CAAmB,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3D,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,QAAQ,CAAC,GAAG,CAAC;aAC/B;SACF,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,gBAAgB,CAAC,IAA0B,EAAE,qBAA8B;QACvF,OAAO,CAAC,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F;QACrF,MAAM,yBAAyB,GAAG,CAAC,CAAC,qBAAqB;YACrD,IAAA,qBAAS,EAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC;YACzD,gBAAgB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;QAEpD,EAAE,CAAC,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,UAA6B,EAC7B,QAAwB;QAExB,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,UAA0B,EAC1B,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;AArMD,4CAqMC","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} from '@comunica/types';\nimport type { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { MetadataValidationState } from '@comunica/utils-metadata';\nimport type * as RDF from '@rdfjs/types';\nimport { AsyncIterator, wrap as wrapAsyncIterator } from 'asynciterator';\nimport { someTermsNested, filterTermsNested, someTerms, uniqTerms } from 'rdf-terms';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport { Factory } from 'sparqlalgebrajs';\nimport type { IRdfJsSourceExtended } from './IRdfJsSourceExtended';\n\nexport class QuerySourceRdfJs implements IQuerySource {\n protected readonly selectorShape: FragmentSelectorShape;\n public referenceValue: string | RDF.Source;\n protected readonly source: IRdfJsSourceExtended;\n private readonly dataFactory: ComunicaDataFactory;\n private readonly bindingsFactory: BindingsFactory;\n\n public constructor(source: RDF.Source, dataFactory: ComunicaDataFactory, bindingsFactory: BindingsFactory) {\n this.source = source;\n this.referenceValue = source;\n this.dataFactory = dataFactory;\n this.bindingsFactory = bindingsFactory;\n const AF = new Factory(<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 }\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 queryBindings(operation: Algebra.Operation, context: IActionContext): BindingsStream {\n if (operation.type !== 'pattern') {\n throw new Error(`Attempted to pass non-pattern operation '${operation.type}' to QuerySourceRdfJs`);\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 (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' && !context.get(KeysQueryOperation.unionDefaultGraph)) {\n forceEstimateCardinality = true;\n const variable = operation.graph;\n it = it.filter(bindings => bindings.get(variable)!.termType !== '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, 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(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)\n .catch(error => it.destroy(error));\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 forceEstimateCardinality = false,\n extraMetadata: Record<string, any> = {},\n ): Promise<void> {\n // Check if the source supports quoted triple filtering\n const quotedTripleFiltering = Boolean(this.source.features?.quotedTripleFiltering);\n\n let cardinality: number;\n if (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 const 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 matches.on('error', reject);\n matches.on('end', () => resolve(i));\n 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 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.Update,\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/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-source-identify-rdfjs",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.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": "^4.0
|
|
45
|
-
"@comunica/bus-query-source-identify": "^4.0
|
|
46
|
-
"@comunica/context-entries": "^4.0
|
|
47
|
-
"@comunica/core": "^4.0
|
|
48
|
-
"@comunica/types": "^4.0
|
|
49
|
-
"@comunica/utils-bindings-factory": "^4.0
|
|
50
|
-
"@comunica/utils-metadata": "^4.0
|
|
44
|
+
"@comunica/bus-merge-bindings-context": "^4.2.0",
|
|
45
|
+
"@comunica/bus-query-source-identify": "^4.2.0",
|
|
46
|
+
"@comunica/context-entries": "^4.2.0",
|
|
47
|
+
"@comunica/core": "^4.2.0",
|
|
48
|
+
"@comunica/types": "^4.2.0",
|
|
49
|
+
"@comunica/utils-bindings-factory": "^4.2.0",
|
|
50
|
+
"@comunica/utils-metadata": "^4.2.0",
|
|
51
51
|
"@rdfjs/types": "*",
|
|
52
52
|
"asynciterator": "^3.9.0",
|
|
53
53
|
"rdf-terms": "^1.11.0",
|
|
54
54
|
"sparqlalgebrajs": "^4.3.8"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "94e1eacab069551590cc250074b36bce08720c4c"
|
|
57
57
|
}
|