@faubulous/mentor-rdf 2.1.6 → 2.1.8
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 +137 -13
- package/dist/index.js.map +2 -2
- package/dist/rdf/concept-repository.d.ts +39 -0
- package/dist/rdf/reasoners/skos-reasoner.d.ts +16 -0
- package/package.json +1 -1
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
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
yielded.
|
|
3075
|
-
|
|
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
|
}
|
|
@@ -3231,6 +3229,102 @@ var ConceptRepository = class extends ResourceRepository {
|
|
|
3231
3229
|
}
|
|
3232
3230
|
return result;
|
|
3233
3231
|
}
|
|
3232
|
+
/**
|
|
3233
|
+
* Get the concepts that are not displayed below any concept scheme, i.e. the concepts that are
|
|
3234
|
+
* neither associated with a concept scheme nor reachable from the top concepts of one.
|
|
3235
|
+
* @param graphUris URIs of the graphs to search for concepts.
|
|
3236
|
+
* @param options Optional query options. `definedBy` and `notDefinedBy` filter the concepts by
|
|
3237
|
+
* their definition source.
|
|
3238
|
+
* @returns An iterator of URIs of the concepts outside of all concept schemes.
|
|
3239
|
+
*/
|
|
3240
|
+
*getUnscopedConcepts(graphUris, options) {
|
|
3241
|
+
const scopedConcepts = /* @__PURE__ */ new Set();
|
|
3242
|
+
for (let scheme of this.getConceptSchemes(graphUris)) {
|
|
3243
|
+
for (let c of this.getAllConceptsInScheme(graphUris, scheme)) {
|
|
3244
|
+
scopedConcepts.add(c);
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
const yielded = /* @__PURE__ */ new Set();
|
|
3248
|
+
for (let q of this.store.matchAll(graphUris, null, rdf.type, skos.Concept)) {
|
|
3249
|
+
const s = q.subject;
|
|
3250
|
+
if (yielded.has(s.value) || scopedConcepts.has(s.value)) {
|
|
3251
|
+
continue;
|
|
3252
|
+
}
|
|
3253
|
+
yielded.add(s.value);
|
|
3254
|
+
if (!this.skip(graphUris, s, options, { includeBlankNodes: true, includeReferenced: true })) {
|
|
3255
|
+
yield s.value;
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
/**
|
|
3260
|
+
* Get the root concepts of the concepts that are not displayed below any concept scheme, see
|
|
3261
|
+
* {@link getUnscopedConcepts}. These are the concepts without a broader concept among them,
|
|
3262
|
+
* plus one concept of every group of concepts that can only be reached through a cycle of
|
|
3263
|
+
* broader concepts, so that every unscoped concept can be reached from one of the roots.
|
|
3264
|
+
*
|
|
3265
|
+
* Note: A concept that is its own broader concept is not excluded, as in {@link getTopConcepts}.
|
|
3266
|
+
* @param graphUris URIs of the graphs to search for concepts.
|
|
3267
|
+
* @param options Optional query options, see {@link getUnscopedConcepts}.
|
|
3268
|
+
* @returns An iterator of URIs of the root concepts outside of all concept schemes.
|
|
3269
|
+
*/
|
|
3270
|
+
*getUnscopedRootConcepts(graphUris, options) {
|
|
3271
|
+
const concepts = new Set(this.getUnscopedConcepts(graphUris, options));
|
|
3272
|
+
const narrowerConcepts = this._getNarrowerConceptIndex(graphUris);
|
|
3273
|
+
const nested = this._getNestedConcepts(concepts, narrowerConcepts);
|
|
3274
|
+
const reachable = /* @__PURE__ */ new Set();
|
|
3275
|
+
for (let c of concepts) {
|
|
3276
|
+
if (!nested.has(c)) {
|
|
3277
|
+
this._markReachableConcepts(c, concepts, narrowerConcepts, reachable);
|
|
3278
|
+
yield c;
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
for (let c of concepts) {
|
|
3282
|
+
if (!reachable.has(c)) {
|
|
3283
|
+
this._markReachableConcepts(c, concepts, narrowerConcepts, reachable);
|
|
3284
|
+
yield c;
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
/**
|
|
3289
|
+
* Get the concepts of a set that have a broader concept within the same set.
|
|
3290
|
+
* @param concepts The set of concepts.
|
|
3291
|
+
* @param narrowerConcepts The narrower concept index of the graphs, see {@link _getNarrowerConceptIndex}.
|
|
3292
|
+
* @returns The concepts that are nested below another concept of the set.
|
|
3293
|
+
*/
|
|
3294
|
+
_getNestedConcepts(concepts, narrowerConcepts) {
|
|
3295
|
+
const result = /* @__PURE__ */ new Set();
|
|
3296
|
+
for (let [broader, narrower] of narrowerConcepts) {
|
|
3297
|
+
if (!concepts.has(broader)) {
|
|
3298
|
+
continue;
|
|
3299
|
+
}
|
|
3300
|
+
for (let n of narrower) {
|
|
3301
|
+
if (n !== broader && concepts.has(n)) {
|
|
3302
|
+
result.add(n);
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
return result;
|
|
3307
|
+
}
|
|
3308
|
+
/**
|
|
3309
|
+
* Mark a concept and the concepts of a set that can be reached from it via narrower concepts.
|
|
3310
|
+
* @param conceptUri The concept to start from.
|
|
3311
|
+
* @param concepts The set of concepts that can be marked.
|
|
3312
|
+
* @param narrowerConcepts The narrower concept index of the graphs, see {@link _getNarrowerConceptIndex}.
|
|
3313
|
+
* @param reachable The set of reachable concepts, which is extended in place.
|
|
3314
|
+
*/
|
|
3315
|
+
_markReachableConcepts(conceptUri, concepts, narrowerConcepts, reachable) {
|
|
3316
|
+
const stack = [conceptUri];
|
|
3317
|
+
reachable.add(conceptUri);
|
|
3318
|
+
while (stack.length) {
|
|
3319
|
+
const current = stack.pop();
|
|
3320
|
+
for (let n of narrowerConcepts.get(current) ?? []) {
|
|
3321
|
+
if (concepts.has(n) && !reachable.has(n)) {
|
|
3322
|
+
reachable.add(n);
|
|
3323
|
+
stack.push(n);
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3234
3328
|
/**
|
|
3235
3329
|
* Get the members of a collection. This includes both `skos:member` and `skos:memberList` properties.
|
|
3236
3330
|
* @param graphUris URI of the graphs to search for collections.
|
|
@@ -4625,11 +4719,40 @@ var SkosReasoner = class extends ReasonerBase {
|
|
|
4625
4719
|
this.concepts = /* @__PURE__ */ new Set();
|
|
4626
4720
|
this.conceptSchemes = /* @__PURE__ */ new Set();
|
|
4627
4721
|
this.collections = /* @__PURE__ */ new Set();
|
|
4722
|
+
/**
|
|
4723
|
+
* Subjects of `skos:inScheme` triples, keyed by their value. Whether they are concepts can only
|
|
4724
|
+
* be decided once all triples of the graph were processed, see {@link afterInference}.
|
|
4725
|
+
*/
|
|
4726
|
+
this._inSchemeSubjects = /* @__PURE__ */ new Map();
|
|
4628
4727
|
}
|
|
4629
4728
|
applyInference(quad5) {
|
|
4630
4729
|
this.inferConceptAxioms(quad5);
|
|
4631
4730
|
this.inferCollectionAxioms(quad5);
|
|
4632
4731
|
}
|
|
4732
|
+
/**
|
|
4733
|
+
* Infers the subjects of `skos:inScheme` triples to be concepts, unless they are collections.
|
|
4734
|
+
* `skos:inScheme` has no domain, and `skos:Collection` is disjoint with `skos:Concept`. The
|
|
4735
|
+
* type of a collection may be processed after its `skos:inScheme` triple, so this is done after
|
|
4736
|
+
* all triples of the graph were processed.
|
|
4737
|
+
*/
|
|
4738
|
+
afterInference() {
|
|
4739
|
+
super.afterInference();
|
|
4740
|
+
for (let [id, subject] of this._inSchemeSubjects) {
|
|
4741
|
+
if (!this.collections.has(id)) {
|
|
4742
|
+
this.assertConcept(subject);
|
|
4743
|
+
}
|
|
4744
|
+
}
|
|
4745
|
+
}
|
|
4746
|
+
/**
|
|
4747
|
+
* Clears the state that was collected for the graph, so it does not affect the next graph.
|
|
4748
|
+
*/
|
|
4749
|
+
resetState() {
|
|
4750
|
+
super.resetState();
|
|
4751
|
+
this.concepts.clear();
|
|
4752
|
+
this.conceptSchemes.clear();
|
|
4753
|
+
this.collections.clear();
|
|
4754
|
+
this._inSchemeSubjects.clear();
|
|
4755
|
+
}
|
|
4633
4756
|
assertConcept(subject) {
|
|
4634
4757
|
this.store.add(quad(subject, rdf.type, skos.Concept, this.targetGraph));
|
|
4635
4758
|
this.concepts.add(subject.value);
|
|
@@ -4658,7 +4781,7 @@ var SkosReasoner = class extends ReasonerBase {
|
|
|
4658
4781
|
return;
|
|
4659
4782
|
}
|
|
4660
4783
|
case skos.inScheme.value: {
|
|
4661
|
-
this.
|
|
4784
|
+
this._inSchemeSubjects.set(s.value, s);
|
|
4662
4785
|
this.assertConceptScheme(o);
|
|
4663
4786
|
return;
|
|
4664
4787
|
}
|
|
@@ -4745,6 +4868,7 @@ var RdfsReasoner = class extends SkosReasoner {
|
|
|
4745
4868
|
}
|
|
4746
4869
|
}
|
|
4747
4870
|
resetState() {
|
|
4871
|
+
super.resetState();
|
|
4748
4872
|
this.ontologies.clear();
|
|
4749
4873
|
this.classes.clear();
|
|
4750
4874
|
this.properties.clear();
|