@oslo-flanders/core 1.0.11 → 1.0.12
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/lib/store/QuadStore.d.ts +15 -1
- package/lib/store/QuadStore.js +23 -1
- package/lib/utils/storeUtils.d.ts +2 -0
- package/lib/utils/storeUtils.js +62 -38
- package/package.json +1 -1
package/lib/store/QuadStore.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare class QuadStore {
|
|
|
4
4
|
constructor();
|
|
5
5
|
addQuads(quads: RDF.Quad[]): void;
|
|
6
6
|
addQuad(quad: RDF.Quad): void;
|
|
7
|
+
removeQuads(quad: RDF.Quad[]): void;
|
|
8
|
+
removeQuad(quad: RDF.Quad): void;
|
|
7
9
|
addQuadsFromFile(file: string): Promise<void>;
|
|
8
10
|
findQuads(subject: RDF.Term | null, predicate: RDF.Term | null, object: RDF.Term | null, graph?: RDF.Term | null): RDF.Quad[];
|
|
9
11
|
findQuad(subject: RDF.Term | null, predicate: RDF.Term | null, object: RDF.Term | null, graph?: RDF.Term | null): RDF.Quad | undefined;
|
|
@@ -208,8 +210,20 @@ export declare class QuadStore {
|
|
|
208
210
|
/**
|
|
209
211
|
* Finds the oslo:value of a given RDF.Term
|
|
210
212
|
* @param subject The RDF.Term to find the oslo:key of
|
|
211
|
-
* @param
|
|
213
|
+
* @param graph The RDF.Term of the named graph
|
|
212
214
|
* @returns An RDF.Term or undefined if not found
|
|
213
215
|
*/
|
|
214
216
|
getOsloExtensionValue(subject: RDF.Term, graph?: RDF.Term | null): RDF.NamedNode | undefined;
|
|
217
|
+
/**
|
|
218
|
+
* Find the parent attribute of an attribute
|
|
219
|
+
* @param subject The RDF.Term to find the parent attribute of
|
|
220
|
+
* @param graph The RDF.Term of the named graph
|
|
221
|
+
*/
|
|
222
|
+
getParentAttribute(subject: RDF.Term, graph?: RDF.Term | null): RDF.Term | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Find the child attribute of an attribute
|
|
225
|
+
* @param subject The RDF.Term to find the parent attribute of
|
|
226
|
+
* @param graph The RDF.Term of the named graph
|
|
227
|
+
*/
|
|
228
|
+
getChildAttribute(subject: RDF.Term, graph?: RDF.Term | null): RDF.Term | undefined;
|
|
215
229
|
}
|
package/lib/store/QuadStore.js
CHANGED
|
@@ -51,6 +51,12 @@ let QuadStore = class QuadStore {
|
|
|
51
51
|
addQuad(quad) {
|
|
52
52
|
this.store.addQuad(quad);
|
|
53
53
|
}
|
|
54
|
+
removeQuads(quad) {
|
|
55
|
+
this.store.removeQuads(quad);
|
|
56
|
+
}
|
|
57
|
+
removeQuad(quad) {
|
|
58
|
+
this.store.removeQuad(quad);
|
|
59
|
+
}
|
|
54
60
|
async addQuadsFromFile(file) {
|
|
55
61
|
const buffer = await (0, fetchFileOrUrl_1.fetchFileOrUrl)(file);
|
|
56
62
|
const textStream = require('streamify-string')(buffer.toString());
|
|
@@ -361,12 +367,28 @@ let QuadStore = class QuadStore {
|
|
|
361
367
|
/**
|
|
362
368
|
* Finds the oslo:value of a given RDF.Term
|
|
363
369
|
* @param subject The RDF.Term to find the oslo:key of
|
|
364
|
-
* @param
|
|
370
|
+
* @param graph The RDF.Term of the named graph
|
|
365
371
|
* @returns An RDF.Term or undefined if not found
|
|
366
372
|
*/
|
|
367
373
|
getOsloExtensionValue(subject, graph = null) {
|
|
368
374
|
return (this.store.getObjects(subject, namespaces_1.ns.oslo('value'), graph).shift());
|
|
369
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Find the parent attribute of an attribute
|
|
378
|
+
* @param subject The RDF.Term to find the parent attribute of
|
|
379
|
+
* @param graph The RDF.Term of the named graph
|
|
380
|
+
*/
|
|
381
|
+
getParentAttribute(subject, graph = null) {
|
|
382
|
+
return (this.findObject(subject, namespaces_1.ns.oslo('parentAttribute')));
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Find the child attribute of an attribute
|
|
386
|
+
* @param subject The RDF.Term to find the parent attribute of
|
|
387
|
+
* @param graph The RDF.Term of the named graph
|
|
388
|
+
*/
|
|
389
|
+
getChildAttribute(subject, graph = null) {
|
|
390
|
+
return (this.findObject(subject, namespaces_1.ns.oslo('childAttribute')));
|
|
391
|
+
}
|
|
370
392
|
};
|
|
371
393
|
QuadStore = __decorate([
|
|
372
394
|
(0, inversify_1.injectable)(),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as RDF from '@rdfjs/types';
|
|
2
|
+
import type { DataFactory } from 'rdf-data-factory';
|
|
2
3
|
import type { QuadStore } from '../store/QuadStore';
|
|
3
4
|
export declare function getApplicationProfileLabel(subject: RDF.Term, store: QuadStore, language?: string | null): RDF.Literal | undefined;
|
|
4
5
|
export declare function getVocabularyLabel(subject: RDF.Term, store: QuadStore, language?: string | null): RDF.Literal | undefined;
|
|
@@ -8,4 +9,5 @@ export declare function getApplicationProfileUsageNote(subject: RDF.Term, store:
|
|
|
8
9
|
export declare function getVocabularyUsageNote(subject: RDF.Term, store: QuadStore, language?: string | null): RDF.Literal | undefined;
|
|
9
10
|
export declare function getMinCount(subject: RDF.Term, store: QuadStore): string | undefined;
|
|
10
11
|
export declare function getMaxCount(subject: RDF.Term, store: QuadStore): string | undefined;
|
|
12
|
+
export declare function createList(items: RDF.Term[], store: QuadStore, df: DataFactory): RDF.BlankNode | RDF.NamedNode;
|
|
11
13
|
export declare function findAllAttributes(subject: RDF.Term, attributeIds: RDF.Term[], store: QuadStore): RDF.Term[];
|
package/lib/utils/storeUtils.js
CHANGED
|
@@ -1,45 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findAllAttributes = exports.getMaxCount = exports.getMinCount = exports.getVocabularyUsageNote = exports.getApplicationProfileUsageNote = exports.getVocabularyDefinition = exports.getApplicationProfileDefinition = exports.getVocabularyLabel = exports.getApplicationProfileLabel = void 0;
|
|
3
|
+
exports.findAllAttributes = exports.createList = exports.getMaxCount = exports.getMinCount = exports.getVocabularyUsageNote = exports.getApplicationProfileUsageNote = exports.getVocabularyDefinition = exports.getApplicationProfileDefinition = exports.getVocabularyLabel = exports.getApplicationProfileLabel = void 0;
|
|
4
4
|
const namespaces_1 = require("./namespaces");
|
|
5
5
|
function getApplicationProfileLabel(subject, store, language = null) {
|
|
6
6
|
var _a, _b, _c;
|
|
7
7
|
const labels = store.getLabels(subject);
|
|
8
|
-
if (labels.some(x => x.predicate.equals(namespaces_1.ns.oslo('apLabel')))) {
|
|
9
|
-
return (_a = labels
|
|
10
|
-
.
|
|
11
|
-
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
|
|
8
|
+
if (labels.some((x) => x.predicate.equals(namespaces_1.ns.oslo('apLabel')))) {
|
|
9
|
+
return ((_a = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('apLabel')) &&
|
|
10
|
+
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
|
|
12
11
|
}
|
|
13
|
-
if (labels.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
|
|
14
|
-
return (_b = labels.find(x => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')) &&
|
|
15
|
-
x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object;
|
|
12
|
+
if (labels.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
|
|
13
|
+
return ((_b = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')) &&
|
|
14
|
+
x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object);
|
|
16
15
|
}
|
|
17
|
-
return (_c = labels.find(x => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _c === void 0 ? void 0 : _c.object;
|
|
16
|
+
return ((_c = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _c === void 0 ? void 0 : _c.object);
|
|
18
17
|
}
|
|
19
18
|
exports.getApplicationProfileLabel = getApplicationProfileLabel;
|
|
20
19
|
function getVocabularyLabel(subject, store, language = null) {
|
|
21
20
|
var _a, _b;
|
|
22
21
|
const labels = store.getLabels(subject);
|
|
23
|
-
if (labels.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
|
|
24
|
-
return (_a = labels
|
|
25
|
-
.
|
|
26
|
-
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
|
|
22
|
+
if (labels.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
|
|
23
|
+
return ((_a = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')) &&
|
|
24
|
+
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
|
|
27
25
|
}
|
|
28
|
-
return (_b = labels.find(x => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _b === void 0 ? void 0 : _b.object;
|
|
26
|
+
return ((_b = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _b === void 0 ? void 0 : _b.object);
|
|
29
27
|
}
|
|
30
28
|
exports.getVocabularyLabel = getVocabularyLabel;
|
|
31
29
|
function getApplicationProfileDefinition(subject, store, language = null) {
|
|
32
30
|
var _a, _b;
|
|
33
31
|
const definitions = store.getDefinitions(subject);
|
|
34
|
-
if (definitions.some(x => x.predicate.equals(namespaces_1.ns.oslo('apDefinition')))) {
|
|
35
|
-
return (_a = definitions
|
|
36
|
-
.
|
|
37
|
-
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
|
|
32
|
+
if (definitions.some((x) => x.predicate.equals(namespaces_1.ns.oslo('apDefinition')))) {
|
|
33
|
+
return ((_a = definitions.find((x) => x.predicate.equals(namespaces_1.ns.oslo('apDefinition')) &&
|
|
34
|
+
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
|
|
38
35
|
}
|
|
39
|
-
if (definitions.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
|
|
40
|
-
return (_b = definitions
|
|
41
|
-
.
|
|
42
|
-
x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object;
|
|
36
|
+
if (definitions.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
|
|
37
|
+
return ((_b = definitions.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')) &&
|
|
38
|
+
x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object);
|
|
43
39
|
}
|
|
44
40
|
return undefined;
|
|
45
41
|
}
|
|
@@ -47,10 +43,9 @@ exports.getApplicationProfileDefinition = getApplicationProfileDefinition;
|
|
|
47
43
|
function getVocabularyDefinition(subject, store, language = null) {
|
|
48
44
|
var _a;
|
|
49
45
|
const definitions = store.getDefinitions(subject);
|
|
50
|
-
if (definitions.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
|
|
51
|
-
return (_a = definitions
|
|
52
|
-
.
|
|
53
|
-
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
|
|
46
|
+
if (definitions.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
|
|
47
|
+
return ((_a = definitions.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')) &&
|
|
48
|
+
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
|
|
54
49
|
}
|
|
55
50
|
return undefined;
|
|
56
51
|
}
|
|
@@ -58,15 +53,13 @@ exports.getVocabularyDefinition = getVocabularyDefinition;
|
|
|
58
53
|
function getApplicationProfileUsageNote(subject, store, language = null) {
|
|
59
54
|
var _a, _b;
|
|
60
55
|
const usageNotes = store.getUsageNotes(subject);
|
|
61
|
-
if (usageNotes.some(x => x.predicate.equals(namespaces_1.ns.oslo('apUsageNote')))) {
|
|
62
|
-
return (_a = usageNotes
|
|
63
|
-
.
|
|
64
|
-
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
|
|
56
|
+
if (usageNotes.some((x) => x.predicate.equals(namespaces_1.ns.oslo('apUsageNote')))) {
|
|
57
|
+
return ((_a = usageNotes.find((x) => x.predicate.equals(namespaces_1.ns.oslo('apUsageNote')) &&
|
|
58
|
+
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
|
|
65
59
|
}
|
|
66
|
-
if (usageNotes.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
|
|
67
|
-
return (_b = usageNotes
|
|
68
|
-
.
|
|
69
|
-
x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object;
|
|
60
|
+
if (usageNotes.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
|
|
61
|
+
return ((_b = usageNotes.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')) &&
|
|
62
|
+
x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object);
|
|
70
63
|
}
|
|
71
64
|
return undefined;
|
|
72
65
|
}
|
|
@@ -74,10 +67,9 @@ exports.getApplicationProfileUsageNote = getApplicationProfileUsageNote;
|
|
|
74
67
|
function getVocabularyUsageNote(subject, store, language = null) {
|
|
75
68
|
var _a;
|
|
76
69
|
const usageNotes = store.getUsageNotes(subject);
|
|
77
|
-
if (usageNotes.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
|
|
78
|
-
return (_a = usageNotes
|
|
79
|
-
.
|
|
80
|
-
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
|
|
70
|
+
if (usageNotes.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
|
|
71
|
+
return ((_a = usageNotes.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')) &&
|
|
72
|
+
x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
|
|
81
73
|
}
|
|
82
74
|
return undefined;
|
|
83
75
|
}
|
|
@@ -92,6 +84,38 @@ function getMaxCount(subject, store) {
|
|
|
92
84
|
return (_a = store.findObject(subject, namespaces_1.ns.shacl('maxCount'))) === null || _a === void 0 ? void 0 : _a.value;
|
|
93
85
|
}
|
|
94
86
|
exports.getMaxCount = getMaxCount;
|
|
87
|
+
function createList(items, store, df) {
|
|
88
|
+
const list = [df.blankNode()];
|
|
89
|
+
const quads = [];
|
|
90
|
+
/* Empty list has a single NamedNode RDF:nil */
|
|
91
|
+
if (items.length === 0)
|
|
92
|
+
return df.namedNode(namespaces_1.ns.rdf('nil'));
|
|
93
|
+
items.forEach((entry, index) => {
|
|
94
|
+
const subject = list[index];
|
|
95
|
+
const object = entry;
|
|
96
|
+
/* Items must be identifiers */
|
|
97
|
+
if (object.termType !== 'NamedNode' && object.termType !== 'BlankNode')
|
|
98
|
+
return;
|
|
99
|
+
/* Current list item */
|
|
100
|
+
quads.push(df.quad(subject, namespaces_1.ns.rdf('first'), object));
|
|
101
|
+
if (index === items.length - 1) {
|
|
102
|
+
/* End of list */
|
|
103
|
+
quads.push(df.quad(subject, namespaces_1.ns.rdf('rest'), namespaces_1.ns.rdf('nil')));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
/* Next item of the list */
|
|
107
|
+
list.push(df.blankNode());
|
|
108
|
+
const nextSubject = list[index + 1];
|
|
109
|
+
/* Items must be identifiers */
|
|
110
|
+
if (nextSubject.termType !== 'BlankNode')
|
|
111
|
+
return;
|
|
112
|
+
quads.push(df.quad(subject, namespaces_1.ns.rdf('rest'), nextSubject));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
store.addQuads(quads);
|
|
116
|
+
return list[0];
|
|
117
|
+
}
|
|
118
|
+
exports.createList = createList;
|
|
95
119
|
function findAllAttributes(subject, attributeIds, store) {
|
|
96
120
|
const parentIds = store.findObjects(subject, namespaces_1.ns.rdfs('subClassOf'));
|
|
97
121
|
attributeIds = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslo-flanders/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Core interfaces and utilities",
|
|
5
5
|
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
|
|
6
6
|
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-core#readme",
|