@faubulous/mentor-rdf 2.2.1 → 2.3.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
@@ -2603,13 +2603,13 @@ var DefaultGraph = class {
2603
2603
  }
2604
2604
  };
2605
2605
  var Quad = class {
2606
- constructor(subject, predicate, object, graph2) {
2606
+ constructor(subject, predicate, object, graph) {
2607
2607
  this.termType = "Quad";
2608
2608
  this.value = "";
2609
2609
  this.subject = subject;
2610
2610
  this.predicate = predicate;
2611
2611
  this.object = object;
2612
- this.graph = graph2 ?? new DefaultGraph();
2612
+ this.graph = graph ?? new DefaultGraph();
2613
2613
  }
2614
2614
  equals(other) {
2615
2615
  if (other?.termType !== this.termType) {
@@ -2673,8 +2673,8 @@ var DataFactory = class {
2673
2673
  * @param graph The graph of the quad (defaults to the default graph).
2674
2674
  * @returns A new Quad instance.
2675
2675
  */
2676
- quad(subject, predicate, object, graph2) {
2677
- return new Quad(subject, predicate, object, graph2);
2676
+ quad(subject, predicate, object, graph) {
2677
+ return new Quad(subject, predicate, object, graph);
2678
2678
  }
2679
2679
  /**
2680
2680
  * Creates a copy of an existing term.
@@ -4127,17 +4127,17 @@ var DatasetView = class _DatasetView {
4127
4127
  }
4128
4128
  const scope = [];
4129
4129
  const seen = /* @__PURE__ */ new Set();
4130
- const push = (graph2) => {
4131
- const key = graph2.termType + ":" + graph2.value;
4130
+ const push = (graph) => {
4131
+ const key = graph.termType + ":" + graph.value;
4132
4132
  if (!seen.has(key)) {
4133
4133
  seen.add(key);
4134
- scope.push(graph2);
4134
+ scope.push(graph);
4135
4135
  }
4136
4136
  };
4137
- for (const graph2 of graphs) {
4138
- push(graph2);
4139
- if (options.includeInferred !== false && store.reasoner && graph2.termType === "NamedNode") {
4140
- push(store.dataFactory.namedNode(store.reasoner.targetUriGenerator.getGraphUri(graph2.value)));
4137
+ for (const graph of graphs) {
4138
+ push(graph);
4139
+ if (options.includeInferred !== false && store.reasoner && graph.termType === "NamedNode") {
4140
+ push(store.dataFactory.namedNode(store.reasoner.targetUriGenerator.getGraphUri(graph.value)));
4141
4141
  }
4142
4142
  }
4143
4143
  return scope;
@@ -4154,8 +4154,8 @@ var DatasetView = class _DatasetView {
4154
4154
  if (this._scope === void 0) {
4155
4155
  n = this._store.countQuads(this._s, this._p, this._o, null);
4156
4156
  } else {
4157
- for (const graph2 of this._scope) {
4158
- n += this._store.countQuads(this._s, this._p, this._o, graph2);
4157
+ for (const graph of this._scope) {
4158
+ n += this._store.countQuads(this._s, this._p, this._o, graph);
4159
4159
  }
4160
4160
  }
4161
4161
  this._cachedSize = n;
@@ -4191,7 +4191,7 @@ var DatasetView = class _DatasetView {
4191
4191
  if (this._o && !this._o.equals(quad5.object)) {
4192
4192
  return false;
4193
4193
  }
4194
- if (this._scope !== void 0 && !this._scope.some((graph2) => graph2.equals(quad5.graph))) {
4194
+ if (this._scope !== void 0 && !this._scope.some((graph) => graph.equals(quad5.graph))) {
4195
4195
  return false;
4196
4196
  }
4197
4197
  return this._store.has(quad5);
@@ -4206,14 +4206,14 @@ var DatasetView = class _DatasetView {
4206
4206
  * @param graph The optional graph.
4207
4207
  * @returns A new read-only dataset view of the matching quads.
4208
4208
  */
4209
- match(subject, predicate, object, graph2) {
4209
+ match(subject, predicate, object, graph) {
4210
4210
  const s = _DatasetView._intersectTerm(this._s, subject);
4211
4211
  const p = _DatasetView._intersectTerm(this._p, predicate);
4212
4212
  const o = _DatasetView._intersectTerm(this._o, object);
4213
4213
  let scope = this._scope;
4214
- if (graph2 != null) {
4215
- if (scope === void 0 || scope.some((g) => g.equals(graph2))) {
4216
- scope = [graph2];
4214
+ if (graph != null) {
4215
+ if (scope === void 0 || scope.some((g) => g.equals(graph))) {
4216
+ scope = [graph];
4217
4217
  } else {
4218
4218
  scope = [];
4219
4219
  }
@@ -4249,8 +4249,8 @@ var DatasetView = class _DatasetView {
4249
4249
  if (this._scope === void 0) {
4250
4250
  yield* this._store.matchQuads(this._s, this._p, this._o, null);
4251
4251
  } else {
4252
- for (const graph2 of this._scope) {
4253
- yield* this._store.matchQuads(this._s, this._p, this._o, graph2);
4252
+ for (const graph of this._scope) {
4253
+ yield* this._store.matchQuads(this._s, this._p, this._o, graph);
4254
4254
  }
4255
4255
  }
4256
4256
  }
@@ -4632,11 +4632,11 @@ var ReasonerBase = class {
4632
4632
  throw new Error(`Invalid value for targetUriGenerator: ${targetUriGenerator}`);
4633
4633
  }
4634
4634
  }
4635
- getGraphNode(graph2) {
4636
- if (typeof graph2 === "string") {
4637
- return namedNode5(graph2);
4635
+ getGraphNode(graph) {
4636
+ if (typeof graph === "string") {
4637
+ return namedNode5(graph);
4638
4638
  } else {
4639
- return graph2;
4639
+ return graph;
4640
4640
  }
4641
4641
  }
4642
4642
  isW3CNode(term) {
@@ -4678,9 +4678,9 @@ var ReasonerBase = class {
4678
4678
  * @param object An object URI or null to match any object.
4679
4679
  * @todo Refactor and merge with the same method in the Mentor RDF Store class.
4680
4680
  */
4681
- *match(graph2, subject, predicate, object) {
4682
- if (graph2 !== void 0) {
4683
- yield* this.store.match(subject, predicate, object, graph2);
4681
+ *match(graph, subject, predicate, object) {
4682
+ if (graph !== void 0) {
4683
+ yield* this.store.match(subject, predicate, object, graph);
4684
4684
  } else {
4685
4685
  yield* this.store.match(subject, predicate, object);
4686
4686
  }
@@ -9384,11 +9384,9 @@ xsd:usignedByte a rdfs:Datatype ;
9384
9384
  // src/rdf/store.ts
9385
9385
  import { RdfStore as RdfStore2 } from "rdf-stores";
9386
9386
  import { RdfXmlParser } from "rdfxml-streaming-parser";
9387
- import { graph, serialize } from "rdflib";
9388
9387
 
9389
9388
  // src/rdf/utils.ts
9390
- import * as rdflib from "rdflib";
9391
- var toRdflibTerm = (term) => {
9389
+ var toRdflibTerm = (term, rdflib) => {
9392
9390
  switch (term.termType) {
9393
9391
  case "NamedNode":
9394
9392
  return rdflib.namedNode(term.value);
@@ -9490,6 +9488,9 @@ var Store = class {
9490
9488
  /**
9491
9489
  * Loads a set of W3C Standard ontologies into the store (RDF, RDFA, RDFS, OWL, SKOS, SHACL, XSD)
9492
9490
  * and the SPARQL Syntax Vocabulary.
9491
+ * @deprecated The ontology sources embedded in this package will be removed in the next major
9492
+ * release. Import the published Turtle files instead (e.g. `@faubulous/mentor-rdf/ontologies/rdfs.ttl`)
9493
+ * and load them with {@link loadTurtle}.
9493
9494
  */
9494
9495
  async loadFrameworkOntologies(executeInference = true) {
9495
9496
  this.loadTurtle(rdf2, _RDF, executeInference);
@@ -9543,18 +9544,18 @@ var Store = class {
9543
9544
  * Indicates if a graph holds at least one triple, without reading more than one.
9544
9545
  * @param graph The graph term, or its URI with an empty string for the default graph.
9545
9546
  */
9546
- _hasTriples(graph2) {
9547
- return !this._store.readQuads(null, null, null, this._getGraphTerm(graph2)).next().done;
9547
+ _hasTriples(graph) {
9548
+ return !this._store.readQuads(null, null, null, this._getGraphTerm(graph)).next().done;
9548
9549
  }
9549
9550
  /**
9550
9551
  * Resolves a graph URI to its term; an empty string denotes the default graph.
9551
9552
  * @param graph The graph term or URI.
9552
9553
  */
9553
- _getGraphTerm(graph2) {
9554
- if (typeof graph2 !== "string") {
9555
- return graph2;
9554
+ _getGraphTerm(graph) {
9555
+ if (typeof graph !== "string") {
9556
+ return graph;
9556
9557
  }
9557
- return graph2 === "" ? this.dataFactory.defaultGraph() : this.dataFactory.namedNode(graph2);
9558
+ return graph === "" ? this.dataFactory.defaultGraph() : this.dataFactory.namedNode(graph);
9558
9559
  }
9559
9560
  /**
9560
9561
  * Load a set of triples into the store.
@@ -9587,17 +9588,17 @@ var Store = class {
9587
9588
  ));
9588
9589
  }
9589
9590
  _loadQuads(quads, graphUri, executeInference = true, clearGraph = true, onQuad) {
9590
- const graph2 = this.dataFactory.namedNode(graphUri.replace("\\", "/"));
9591
+ const graph = this.dataFactory.namedNode(graphUri.replace("\\", "/"));
9591
9592
  if (clearGraph) {
9592
9593
  this.deleteGraphs([graphUri], true);
9593
9594
  }
9594
9595
  for (let q of quads) {
9595
- this._ds.add(this.dataFactory.quad(q.subject, q.predicate, q.object, graph2));
9596
+ this._ds.add(this.dataFactory.quad(q.subject, q.predicate, q.object, graph));
9596
9597
  if (onQuad) {
9597
9598
  onQuad(q);
9598
9599
  }
9599
9600
  }
9600
- this._touchGraph(graph2.value);
9601
+ this._touchGraph(graph.value);
9601
9602
  if (this.reasoner && executeInference) {
9602
9603
  this._expand(graphUri);
9603
9604
  }
@@ -9703,15 +9704,16 @@ var Store = class {
9703
9704
  * @returns A string serialization of the triples in the graph in the specified format.
9704
9705
  */
9705
9706
  async serializeGraph(sourceGraphUri, targetFormat = "text/turtle", targetGraphUri, prefixes) {
9707
+ const rdflib = await import("rdflib");
9706
9708
  return new Promise((resolve, reject) => {
9707
9709
  const sourceGraph = this.dataFactory.namedNode(sourceGraphUri);
9708
9710
  const targetGraph = targetGraphUri ? this.dataFactory.namedNode(targetGraphUri) : void 0;
9709
- const store = graph();
9710
- const g = targetGraph ? toRdflibTerm(targetGraph) : void 0;
9711
+ const store = rdflib.graph();
9712
+ const g = targetGraph ? toRdflibTerm(targetGraph, rdflib) : void 0;
9711
9713
  for (const q of this._store.readQuads(null, null, null, sourceGraph)) {
9712
- const s = toRdflibTerm(q.subject);
9713
- const p = toRdflibTerm(q.predicate);
9714
- const o = toRdflibTerm(q.object);
9714
+ const s = toRdflibTerm(q.subject, rdflib);
9715
+ const p = toRdflibTerm(q.predicate, rdflib);
9716
+ const o = toRdflibTerm(q.object, rdflib);
9715
9717
  store.add(s, p, o, g);
9716
9718
  }
9717
9719
  const callback = (error, result) => {
@@ -9721,7 +9723,7 @@ var Store = class {
9721
9723
  resolve(result ?? "");
9722
9724
  }
9723
9725
  };
9724
- serialize(null, store, null, targetFormat, callback, prefixes);
9726
+ rdflib.serialize(null, store, null, targetFormat, callback, prefixes);
9725
9727
  });
9726
9728
  }
9727
9729
  /**
@@ -9813,8 +9815,8 @@ var Store = class {
9813
9815
  * @param object The optional object.
9814
9816
  * @param graph The optional graph.
9815
9817
  */
9816
- countQuads(subject, predicate, object, graph2) {
9817
- return this._store.countQuads(subject, predicate, object, graph2);
9818
+ countQuads(subject, predicate, object, graph) {
9819
+ return this._store.countQuads(subject, predicate, object, graph);
9818
9820
  }
9819
9821
  /**
9820
9822
  * Returns a lazy, read-only dataset view of the quads matching the given pattern.
@@ -9828,12 +9830,12 @@ var Store = class {
9828
9830
  * @param graph The optional graph.
9829
9831
  * @returns A read-only dataset view of the matching quads.
9830
9832
  */
9831
- match(subject, predicate, object, graph2) {
9833
+ match(subject, predicate, object, graph) {
9832
9834
  return new DatasetView(this, {
9833
9835
  subject: subject ?? null,
9834
9836
  predicate: predicate ?? null,
9835
9837
  object: object ?? null,
9836
- graphs: graph2 != null ? [graph2] : void 0,
9838
+ graphs: graph != null ? [graph] : void 0,
9837
9839
  includeInferred: false
9838
9840
  });
9839
9841
  }
@@ -9845,8 +9847,8 @@ var Store = class {
9845
9847
  * @param object The optional object.
9846
9848
  * @param graph The optional graph.
9847
9849
  */
9848
- *matchQuads(subject, predicate, object, graph2) {
9849
- yield* this._store.readQuads(subject, predicate, object, graph2);
9850
+ *matchQuads(subject, predicate, object, graph) {
9851
+ yield* this._store.readQuads(subject, predicate, object, graph);
9850
9852
  }
9851
9853
  /**
9852
9854
  * Get an RDF/JS `Source` interface for the store that streams matching quads.
@@ -9855,7 +9857,7 @@ var Store = class {
9855
9857
  */
9856
9858
  asSource() {
9857
9859
  return {
9858
- match: (subject, predicate, object, graph2) => this._store.match(subject, predicate, object, graph2)
9860
+ match: (subject, predicate, object, graph) => this._store.match(subject, predicate, object, graph)
9859
9861
  };
9860
9862
  }
9861
9863
  /**
@@ -9876,10 +9878,10 @@ var Store = class {
9876
9878
  const o = object;
9877
9879
  if (graphUris !== void 0) {
9878
9880
  const graphs = Array.isArray(graphUris) ? graphUris : [graphUris];
9879
- for (const graph2 of graphs.map((g) => this.dataFactory.namedNode(g))) {
9880
- yield* this._store.readQuads(s, p, o, graph2);
9881
+ for (const graph of graphs.map((g) => this.dataFactory.namedNode(g))) {
9882
+ yield* this._store.readQuads(s, p, o, graph);
9881
9883
  if (includeInferred !== false && this.reasoner) {
9882
- const inferenceGraphUri = this.reasoner.targetUriGenerator.getGraphUri(graph2.value);
9884
+ const inferenceGraphUri = this.reasoner.targetUriGenerator.getGraphUri(graph.value);
9883
9885
  const inferenceGraph = this.dataFactory.namedNode(inferenceGraphUri);
9884
9886
  yield* this._store.readQuads(s, p, o, inferenceGraph);
9885
9887
  }
@@ -9934,7 +9936,7 @@ var Store = class {
9934
9936
  };
9935
9937
 
9936
9938
  // src/rdf/vocabulary-repository.ts
9937
- var { namedNode: namedNode8 } = dataFactory;
9939
+ var { namedNode: namedNode7 } = dataFactory;
9938
9940
  var VocabularyRepository = class extends ShapeRepository {
9939
9941
  /**
9940
9942
  * Get all concept schemes in the repository.
@@ -10001,7 +10003,7 @@ var VocabularyRepository = class extends ShapeRepository {
10001
10003
  * @returns The version of the ontology, or undefined if it is not found.
10002
10004
  */
10003
10005
  getOntologyVersionInfo(graphUris, ontologyUri) {
10004
- const s = namedNode8(ontologyUri);
10006
+ const s = namedNode7(ontologyUri);
10005
10007
  for (const q of this.store.matchAll(graphUris, s, owl.versionInfo, null)) {
10006
10008
  const match = q.object.value.match(/(\d{4}[\/-]\d{2}[\/-]\d{2})/);
10007
10009
  if (match && match.length > 1) {