@comunica/actor-query-source-identify-rdfjs 4.4.0 → 4.4.2-alpha.49.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.
File without changes
File without changes
@@ -95,6 +95,10 @@
95
95
  "@id": "caqsir:components/QuerySourceRdfJs.jsonld#QuerySourceRdfJs__member_getSelectorShape",
96
96
  "memberFieldName": "getSelectorShape"
97
97
  },
98
+ {
99
+ "@id": "caqsir:components/QuerySourceRdfJs.jsonld#QuerySourceRdfJs__member_getFilterFactor",
100
+ "memberFieldName": "getFilterFactor"
101
+ },
98
102
  {
99
103
  "@id": "caqsir:components/QuerySourceRdfJs.jsonld#QuerySourceRdfJs__member_queryBindings",
100
104
  "memberFieldName": "queryBindings"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,8 +1,8 @@
1
1
  import type { IQuerySource, BindingsStream, IActionContext, FragmentSelectorShape, ComunicaDataFactory, QuerySourceReference } from '@comunica/types';
2
+ import { Algebra } from '@comunica/utils-algebra';
2
3
  import type { BindingsFactory } from '@comunica/utils-bindings-factory';
3
4
  import type * as RDF from '@rdfjs/types';
4
5
  import { AsyncIterator } from 'asynciterator';
5
- import type { Algebra } from 'sparqlalgebrajs';
6
6
  import type { IRdfJsSourceExtended } from './IRdfJsSourceExtended';
7
7
  export declare class QuerySourceRdfJs implements IQuerySource {
8
8
  protected readonly selectorShape: FragmentSelectorShape;
@@ -15,10 +15,11 @@ export declare class QuerySourceRdfJs implements IQuerySource {
15
15
  static nullifyVariables(term: RDF.Term | undefined, quotedTripleFiltering: boolean): RDF.Term | undefined;
16
16
  static hasDuplicateVariables(pattern: RDF.BaseQuad): boolean;
17
17
  getSelectorShape(): Promise<FragmentSelectorShape>;
18
+ getFilterFactor(): Promise<number>;
18
19
  queryBindings(operation: Algebra.Operation, context: IActionContext): BindingsStream;
19
20
  protected setMetadata(it: AsyncIterator<any>, operation: Algebra.Pattern, context: IActionContext, forceEstimateCardinality?: boolean, extraMetadata?: Record<string, any>): Promise<void>;
20
- queryQuads(_operation: Algebra.Operation, _context: IActionContext): AsyncIterator<RDF.Quad>;
21
+ queryQuads(operation: Algebra.Operation, _context: IActionContext): AsyncIterator<RDF.Quad>;
21
22
  queryBoolean(_operation: Algebra.Ask, _context: IActionContext): Promise<boolean>;
22
- queryVoid(_operation: Algebra.Update, _context: IActionContext): Promise<void>;
23
+ queryVoid(_operation: Algebra.Operation, _context: IActionContext): Promise<void>;
23
24
  toString(): string;
24
25
  }
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QuerySourceRdfJs = void 0;
4
4
  const bus_query_source_identify_1 = require("@comunica/bus-query-source-identify");
5
5
  const context_entries_1 = require("@comunica/context-entries");
6
+ const utils_algebra_1 = require("@comunica/utils-algebra");
6
7
  const utils_metadata_1 = require("@comunica/utils-metadata");
7
8
  const asynciterator_1 = require("asynciterator");
8
9
  const rdf_terms_1 = require("rdf-terms");
9
- const sparqlalgebrajs_1 = require("sparqlalgebrajs");
10
10
  class QuerySourceRdfJs {
11
11
  constructor(source, dataFactory, bindingsFactory) {
12
12
  this.source = source;
13
13
  this.referenceValue = source;
14
14
  this.dataFactory = dataFactory;
15
15
  this.bindingsFactory = bindingsFactory;
16
- const AF = new sparqlalgebrajs_1.Factory(this.dataFactory);
16
+ const AF = new utils_algebra_1.AlgebraFactory(this.dataFactory);
17
17
  this.selectorShape = {
18
18
  type: 'operation',
19
19
  operation: {
@@ -41,8 +41,11 @@ class QuerySourceRdfJs {
41
41
  async getSelectorShape() {
42
42
  return this.selectorShape;
43
43
  }
44
+ async getFilterFactor() {
45
+ return 0;
46
+ }
44
47
  queryBindings(operation, context) {
45
- if (operation.type !== 'pattern') {
48
+ if (!(0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATTERN)) {
46
49
  throw new Error(`Attempted to pass non-pattern operation '${operation.type}' to QuerySourceRdfJs`);
47
50
  }
48
51
  // Check if we're running in union default graph mode
@@ -146,7 +149,10 @@ class QuerySourceRdfJs {
146
149
  ...extraMetadata,
147
150
  });
148
151
  }
149
- queryQuads(_operation, _context) {
152
+ queryQuads(operation, _context) {
153
+ if ((0, utils_algebra_1.isKnownOperation)(operation, utils_algebra_1.Algebra.Types.PATTERN)) {
154
+ return (0, asynciterator_1.wrap)(this.source.match(operation.subject, operation.predicate, operation.object, operation.graph), { autoStart: false });
155
+ }
150
156
  throw new Error('queryQuads is not implemented in QuerySourceRdfJs');
151
157
  }
152
158
  queryBoolean(_operation, _context) {
@@ -1 +1 @@
1
- {"version":3,"file":"QuerySourceRdfJs.js","sourceRoot":"","sources":["QuerySourceRdfJs.ts"],"names":[],"mappings":";;;AAAA,mFAA+G;AAC/G,+DAA+D;AAU/D,6DAAmE;AAEnE,iDAAwF;AACxF,yCAAqF;AAErF,qDAA0C;AAG1C,MAAa,gBAAgB;IAQ3B,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,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,QA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,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAEM,QAAQ;QACb,OAAO,oBAAoB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC;IAC7D,CAAC;CACF;AA1OD,4CA0OC","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 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 { 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: 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 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 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 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 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 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,2DAAoF;AAEpF,6DAAmE;AAEnE,iDAAwF;AACxF,yCAAqF;AAGrF,MAAa,gBAAgB;IAQ3B,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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AE,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;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"]}
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.4.0",
3
+ "version": "4.4.2-alpha.49.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.4.0",
45
- "@comunica/bus-query-source-identify": "^4.4.0",
46
- "@comunica/context-entries": "^4.4.0",
47
- "@comunica/core": "^4.4.0",
48
- "@comunica/types": "^4.4.0",
49
- "@comunica/utils-bindings-factory": "^4.4.0",
50
- "@comunica/utils-metadata": "^4.4.0",
44
+ "@comunica/bus-merge-bindings-context": "4.4.2-alpha.49.0",
45
+ "@comunica/bus-query-source-identify": "4.4.2-alpha.49.0",
46
+ "@comunica/context-entries": "4.4.2-alpha.49.0",
47
+ "@comunica/core": "4.4.2-alpha.49.0",
48
+ "@comunica/types": "4.4.2-alpha.49.0",
49
+ "@comunica/utils-algebra": "4.4.2-alpha.49.0",
50
+ "@comunica/utils-bindings-factory": "4.4.2-alpha.49.0",
51
+ "@comunica/utils-metadata": "4.4.2-alpha.49.0",
51
52
  "@rdfjs/types": "*",
52
- "asynciterator": "^3.9.0",
53
- "rdf-terms": "^1.11.0",
54
- "sparqlalgebrajs": "^4.3.8"
53
+ "asynciterator": "^3.10.0",
54
+ "rdf-terms": "^2.0.0"
55
55
  },
56
- "gitHead": "27acde56dfe0c1ff1162c1f46818ad752296ca88"
56
+ "gitHead": "ef6f96cfd8faf7c37955bb7e0fe9f6fc6a994bdf"
57
57
  }