@faubulous/mentor-rdf 2.4.0 → 2.5.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/dist/index.js CHANGED
@@ -4223,6 +4223,7 @@ var DatasetView = class _DatasetView {
4223
4223
  this._p = options.predicate ?? null;
4224
4224
  this._o = options.object ?? null;
4225
4225
  this._scope = _DatasetView._resolveScope(store, options);
4226
+ this._excludeInferred = this._scope === void 0 && options.includeInferred === false && store.reasoner !== void 0;
4226
4227
  }
4227
4228
  static _resolveScope(store, options) {
4228
4229
  const graphs = options.graphs ?? options.graphUris?.map((uri) => store.dataFactory.namedNode(uri));
@@ -4257,6 +4258,9 @@ var DatasetView = class _DatasetView {
4257
4258
  let n = 0;
4258
4259
  if (this._scope === void 0) {
4259
4260
  n = this._store.countQuads(this._s, this._p, this._o, null);
4261
+ if (this._excludeInferred) {
4262
+ n -= this._countInferred();
4263
+ }
4260
4264
  } else {
4261
4265
  for (const graph of this._scope) {
4262
4266
  n += this._store.countQuads(this._s, this._p, this._o, graph);
@@ -4266,6 +4270,18 @@ var DatasetView = class _DatasetView {
4266
4270
  this._cachedSizeVersion = this._store.version;
4267
4271
  return n;
4268
4272
  }
4273
+ /**
4274
+ * Count the quads of the view's pattern in the inference graphs of the store.
4275
+ */
4276
+ _countInferred() {
4277
+ let n = 0;
4278
+ for (const graphUri of this._store.getGraphs()) {
4279
+ if (this._store.isInferenceGraph(graphUri)) {
4280
+ n += this._store.countQuads(this._s, this._p, this._o, this._store.dataFactory.namedNode(graphUri));
4281
+ }
4282
+ }
4283
+ return n;
4284
+ }
4269
4285
  /**
4270
4286
  * Not supported: the view is read-only.
4271
4287
  * @throws An error indicating that the view is read-only.
@@ -4298,6 +4314,9 @@ var DatasetView = class _DatasetView {
4298
4314
  if (this._scope !== void 0 && !this._scope.some((graph) => graph.equals(quad5.graph))) {
4299
4315
  return false;
4300
4316
  }
4317
+ if (this._excludeInferred && this._store.isInferenceGraph(quad5.graph)) {
4318
+ return false;
4319
+ }
4301
4320
  return this._store.has(quad5);
4302
4321
  }
4303
4322
  /**
@@ -4316,7 +4335,9 @@ var DatasetView = class _DatasetView {
4316
4335
  const o = _DatasetView._intersectTerm(this._o, object);
4317
4336
  let scope = this._scope;
4318
4337
  if (graph != null) {
4319
- if (scope === void 0 || scope.some((g) => g.equals(graph))) {
4338
+ if (this._excludeInferred && this._store.isInferenceGraph(graph)) {
4339
+ scope = [];
4340
+ } else if (scope === void 0 || scope.some((g) => g.equals(graph))) {
4320
4341
  scope = [graph];
4321
4342
  } else {
4322
4343
  scope = [];
@@ -4330,7 +4351,7 @@ var DatasetView = class _DatasetView {
4330
4351
  predicate: p ?? this._p,
4331
4352
  object: o ?? this._o,
4332
4353
  graphs: scope,
4333
- includeInferred: false
4354
+ includeInferred: scope !== void 0 || this._excludeInferred ? false : void 0
4334
4355
  });
4335
4356
  }
4336
4357
  /**
@@ -4351,7 +4372,11 @@ var DatasetView = class _DatasetView {
4351
4372
  }
4352
4373
  *_iterate() {
4353
4374
  if (this._scope === void 0) {
4354
- yield* this._store.matchQuads(this._s, this._p, this._o, null);
4375
+ for (const quad5 of this._store.matchQuads(this._s, this._p, this._o, null)) {
4376
+ if (!this._excludeInferred || !this._store.isInferenceGraph(quad5.graph)) {
4377
+ yield quad5;
4378
+ }
4379
+ }
4355
4380
  } else {
4356
4381
  for (const graph of this._scope) {
4357
4382
  yield* this._store.matchQuads(this._s, this._p, this._o, graph);
@@ -10074,6 +10099,24 @@ var Store = class {
10074
10099
  hasGraph(graphUri) {
10075
10100
  return this._hasTriples(graphUri);
10076
10101
  }
10102
+ /**
10103
+ * Indicates whether a graph holds the triples the reasoner inferred from another graph.
10104
+ * @param graph A graph term or URI.
10105
+ * @returns `true` if the graph is an inference graph of the reasoner of this store, `false` otherwise or without a reasoner.
10106
+ */
10107
+ isInferenceGraph(graph) {
10108
+ return this.reasoner !== void 0 && this.reasoner.targetUriGenerator.isInferenceGraphUri(graph);
10109
+ }
10110
+ /**
10111
+ * Indicates whether a quad was inferred by the reasoner, i.e. whether it is stored in an inference
10112
+ * graph. A triple that is asserted and inferred exists as two quads; only the quad in the inference
10113
+ * graph is inferred.
10114
+ * @param quad A quad.
10115
+ * @returns `true` if the quad is stored in an inference graph, `false` otherwise.
10116
+ */
10117
+ isInferred(quad5) {
10118
+ return this.isInferenceGraph(quad5.graph);
10119
+ }
10077
10120
  /**
10078
10121
  * Apply inference to the given graph and store the triples in the associated inference graph.
10079
10122
  * @param graphUri A graph URI.
@@ -10160,10 +10203,11 @@ var Store = class {
10160
10203
  }
10161
10204
  /**
10162
10205
  * Returns a lazy, read-only dataset view of the quads matching the given pattern.
10163
- * Implements the RDF/JS `DatasetCore.match` semantics: the result reflects the
10164
- * current contents of the store and does not copy any quads. Because the view
10165
- * iterates the live indexes, do not add or delete quads while iterating it;
10166
- * take a snapshot with `Array.from(...)` first.
10206
+ * Implements the RDF/JS `DatasetCore.match` semantics: a graph names exactly that
10207
+ * graph and no graph means every graph of the store, inference graphs included.
10208
+ * The result reflects the current contents of the store and does not copy any
10209
+ * quads. Because the view iterates the live indexes, do not add or delete quads
10210
+ * while iterating it; take a snapshot with `Array.from(...)` first.
10167
10211
  * @param subject The optional subject.
10168
10212
  * @param predicate The optional predicate.
10169
10213
  * @param object The optional object.
@@ -10176,7 +10220,7 @@ var Store = class {
10176
10220
  predicate: predicate ?? null,
10177
10221
  object: object ?? null,
10178
10222
  graphs: graph != null ? [graph] : void 0,
10179
- includeInferred: false
10223
+ includeInferred: graph != null ? false : void 0
10180
10224
  });
10181
10225
  }
10182
10226
  /**
@@ -10208,6 +10252,10 @@ var Store = class {
10208
10252
  * @param subject A subject URI or null to match any subject.
10209
10253
  * @param predicate A predicate URI or null to match any predicate.
10210
10254
  * @param object An object URI or null to match any object.
10255
+ * @param includeInferred Whether to read the inference graphs. With graphs given, `undefined` and
10256
+ * `true` add the inference graph of each graph when a reasoner is available and `false` reads only
10257
+ * the given graphs. Without graphs, `undefined` and `true` read every graph of the store and `false`
10258
+ * reads every graph except the inference graphs. `true` without a reasoner throws.
10211
10259
  */
10212
10260
  *matchAll(graphUris, subject, predicate, object, includeInferred) {
10213
10261
  if (includeInferred && !this.reasoner) {
@@ -10226,6 +10274,12 @@ var Store = class {
10226
10274
  yield* this._store.readQuads(s, p, o, inferenceGraph);
10227
10275
  }
10228
10276
  }
10277
+ } else if (includeInferred === false && this.reasoner) {
10278
+ for (const quad5 of this._store.readQuads(s, p, o, null)) {
10279
+ if (!this.isInferenceGraph(quad5.graph)) {
10280
+ yield quad5;
10281
+ }
10282
+ }
10229
10283
  } else {
10230
10284
  yield* this._store.readQuads(s, p, o, null);
10231
10285
  }
@@ -10246,9 +10300,11 @@ var Store = class {
10246
10300
  * The view is lazy and live: it reflects the current contents of the store without
10247
10301
  * copying any quads. If you need an immutable snapshot, copy the view into a new
10248
10302
  * dataset, e.g. `RdfStore.createDefault().asDataset()`.
10249
- * @param graphUris Optional graph URI or array of graph URIs. If undefined, all quads are included.
10303
+ * @param graphUris Optional graph URI or array of graph URIs. If undefined, all graphs are included.
10250
10304
  * @param includeInferred Whether to include inferred triples. If undefined, inferred triples
10251
- * are included when a reasoner is available. If `true` without a reasoner, an error is thrown.
10305
+ * are included when a reasoner is available. If `false`, the inference graphs of the given
10306
+ * graphs are left out, or, without graphs, every inference graph of the store. If `true`
10307
+ * without a reasoner, an error is thrown.
10252
10308
  * @returns A read-only dataset view of the matching quads.
10253
10309
  */
10254
10310
  getDataset(graphUris, includeInferred) {