@faubulous/mentor-rdf 2.1.7 → 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 +96 -0
- package/dist/index.js.map +2 -2
- package/dist/rdf/concept-repository.d.ts +36 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3229,6 +3229,102 @@ var ConceptRepository = class extends ResourceRepository {
|
|
|
3229
3229
|
}
|
|
3230
3230
|
return result;
|
|
3231
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
|
+
}
|
|
3232
3328
|
/**
|
|
3233
3329
|
* Get the members of a collection. This includes both `skos:member` and `skos:memberList` properties.
|
|
3234
3330
|
* @param graphUris URI of the graphs to search for collections.
|