@faubulous/mentor-rdf 2.1.5 → 2.1.7

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
@@ -3061,6 +3061,9 @@ var ConceptRepository = class extends ResourceRepository {
3061
3061
  /**
3062
3062
  * Get the concepts that are explicitly associated with a concept scheme, either via
3063
3063
  * `skos:inScheme` or via `skos:topConceptOf`.
3064
+ *
3065
+ * Note: Collections can be associated with a concept scheme via `skos:inScheme` as well. They
3066
+ * are not returned, because `skos:Collection` is disjoint with `skos:Concept`.
3064
3067
  * @param graphUris URIs of the graphs to search for concepts.
3065
3068
  * @param schemeUri URI of a concept scheme.
3066
3069
  * @returns An iterator of URIs of the concepts of the concept scheme.
@@ -3068,18 +3071,13 @@ var ConceptRepository = class extends ResourceRepository {
3068
3071
  *getConceptsOfScheme(graphUris, schemeUri) {
3069
3072
  const yielded = /* @__PURE__ */ new Set();
3070
3073
  const o = dataFactory.namedNode(schemeUri);
3071
- for (let q of this.store.matchAll(graphUris, null, skos.inScheme, o)) {
3072
- const s = q.subject;
3073
- if (!yielded.has(s.value)) {
3074
- yielded.add(s.value);
3075
- yield s.value;
3076
- }
3077
- }
3078
- for (let q of this.store.matchAll(graphUris, null, skos.topConceptOf, o)) {
3079
- const s = q.subject;
3080
- if (!yielded.has(s.value)) {
3081
- yielded.add(s.value);
3082
- yield s.value;
3074
+ for (let predicate of [skos.inScheme, skos.topConceptOf]) {
3075
+ for (let q of this.store.matchAll(graphUris, null, predicate, o)) {
3076
+ const s = q.subject.value;
3077
+ if (!yielded.has(s) && !this.isCollection(graphUris, s)) {
3078
+ yielded.add(s);
3079
+ yield s;
3080
+ }
3083
3081
  }
3084
3082
  }
3085
3083
  }
@@ -4625,11 +4623,40 @@ var SkosReasoner = class extends ReasonerBase {
4625
4623
  this.concepts = /* @__PURE__ */ new Set();
4626
4624
  this.conceptSchemes = /* @__PURE__ */ new Set();
4627
4625
  this.collections = /* @__PURE__ */ new Set();
4626
+ /**
4627
+ * Subjects of `skos:inScheme` triples, keyed by their value. Whether they are concepts can only
4628
+ * be decided once all triples of the graph were processed, see {@link afterInference}.
4629
+ */
4630
+ this._inSchemeSubjects = /* @__PURE__ */ new Map();
4628
4631
  }
4629
4632
  applyInference(quad5) {
4630
4633
  this.inferConceptAxioms(quad5);
4631
4634
  this.inferCollectionAxioms(quad5);
4632
4635
  }
4636
+ /**
4637
+ * Infers the subjects of `skos:inScheme` triples to be concepts, unless they are collections.
4638
+ * `skos:inScheme` has no domain, and `skos:Collection` is disjoint with `skos:Concept`. The
4639
+ * type of a collection may be processed after its `skos:inScheme` triple, so this is done after
4640
+ * all triples of the graph were processed.
4641
+ */
4642
+ afterInference() {
4643
+ super.afterInference();
4644
+ for (let [id, subject] of this._inSchemeSubjects) {
4645
+ if (!this.collections.has(id)) {
4646
+ this.assertConcept(subject);
4647
+ }
4648
+ }
4649
+ }
4650
+ /**
4651
+ * Clears the state that was collected for the graph, so it does not affect the next graph.
4652
+ */
4653
+ resetState() {
4654
+ super.resetState();
4655
+ this.concepts.clear();
4656
+ this.conceptSchemes.clear();
4657
+ this.collections.clear();
4658
+ this._inSchemeSubjects.clear();
4659
+ }
4633
4660
  assertConcept(subject) {
4634
4661
  this.store.add(quad(subject, rdf.type, skos.Concept, this.targetGraph));
4635
4662
  this.concepts.add(subject.value);
@@ -4658,7 +4685,7 @@ var SkosReasoner = class extends ReasonerBase {
4658
4685
  return;
4659
4686
  }
4660
4687
  case skos.inScheme.value: {
4661
- this.assertConcept(s);
4688
+ this._inSchemeSubjects.set(s.value, s);
4662
4689
  this.assertConceptScheme(o);
4663
4690
  return;
4664
4691
  }
@@ -4745,6 +4772,7 @@ var RdfsReasoner = class extends SkosReasoner {
4745
4772
  }
4746
4773
  }
4747
4774
  resetState() {
4775
+ super.resetState();
4748
4776
  this.ontologies.clear();
4749
4777
  this.classes.clear();
4750
4778
  this.properties.clear();