@oslo-flanders/core 1.0.16 → 1.0.19
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/enums/DataTypes.d.ts +1 -0
- package/lib/enums/DataTypes.js +4 -4
- package/lib/enums/OutputFormat.d.ts +1 -0
- package/lib/enums/OutputFormat.js +1 -0
- package/lib/utils/fileSystem.js +1 -1
- package/lib/utils/storeUtils.d.ts +2 -1
- package/lib/utils/storeUtils.js +29 -7
- package/package.json +1 -1
- package/lib/types/splitUri.d.ts +0 -6
- package/lib/types/splitUri.js +0 -35
- package/lib/utils/quadSort.d.ts +0 -8
- package/lib/utils/quadSort.js +0 -17
package/lib/enums/DataTypes.d.ts
CHANGED
package/lib/enums/DataTypes.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isStandardDatatype = exports.datatypeIdentifierToHash = exports.getDataType = void 0;
|
|
3
|
+
exports.isStandardDatatype = exports.datatypeIdentifierToHash = exports.getDataType = exports.DataTypes = void 0;
|
|
4
4
|
const rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns';
|
|
5
5
|
const rdfs = 'http://www.w3.org/2000/01/rdf-schema';
|
|
6
6
|
const xsd = 'http://www.w3.org/2001/XMLSchema';
|
|
7
|
-
|
|
7
|
+
exports.DataTypes = new Map([
|
|
8
8
|
['string', `${xsd}#string`],
|
|
9
9
|
['date', `${xsd}#date`],
|
|
10
10
|
['time', `${xsd}#time`],
|
|
@@ -38,7 +38,7 @@ const DataTypes = new Map([
|
|
|
38
38
|
['unsignedshort', `${xsd}#unsignedShort`],
|
|
39
39
|
['unsignedbyte', `${xsd}#unsignedByte`],
|
|
40
40
|
]);
|
|
41
|
-
const getDataType = (key) => DataTypes.get(key.toLowerCase());
|
|
41
|
+
const getDataType = (key) => exports.DataTypes.get(key.toLowerCase());
|
|
42
42
|
exports.getDataType = getDataType;
|
|
43
43
|
const datatypeIdentifierToHash = (uri) => {
|
|
44
44
|
let hash = 0;
|
|
@@ -48,6 +48,6 @@ const datatypeIdentifierToHash = (uri) => {
|
|
|
48
48
|
return hash > 0 ? hash : hash * -1;
|
|
49
49
|
};
|
|
50
50
|
exports.datatypeIdentifierToHash = datatypeIdentifierToHash;
|
|
51
|
-
const isStandardDatatype = (uri) => Array.from(DataTypes.values()).includes(uri);
|
|
51
|
+
const isStandardDatatype = (uri) => Array.from(exports.DataTypes.values()).includes(uri);
|
|
52
52
|
exports.isStandardDatatype = isStandardDatatype;
|
|
53
53
|
//# sourceMappingURL=DataTypes.js.map
|
|
@@ -4,6 +4,7 @@ exports.OutputFormat = void 0;
|
|
|
4
4
|
var OutputFormat;
|
|
5
5
|
(function (OutputFormat) {
|
|
6
6
|
OutputFormat["JsonLd"] = "application/ld+json";
|
|
7
|
+
OutputFormat["JsonProblem"] = "application/problem+json";
|
|
7
8
|
OutputFormat["Json"] = "application/json";
|
|
8
9
|
OutputFormat["trig"] = "application/trig";
|
|
9
10
|
OutputFormat["turtle"] = "text/turtle";
|
package/lib/utils/fileSystem.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.ensureOutputDirectory = void 0;
|
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
function ensureOutputDirectory(directory) {
|
|
11
11
|
if (!fs_1.default.existsSync(directory)) {
|
|
12
|
-
fs_1.default.mkdirSync(directory);
|
|
12
|
+
fs_1.default.mkdirSync(directory, { recursive: true });
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.ensureOutputDirectory = ensureOutputDirectory;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Logger } from '@oslo-flanders/core';
|
|
1
2
|
import type * as RDF from '@rdfjs/types';
|
|
2
3
|
import type { DataFactory } from 'rdf-data-factory';
|
|
3
4
|
import type { QuadStore } from '../store/QuadStore';
|
|
@@ -10,5 +11,5 @@ export declare function getVocabularyUsageNote(subject: RDF.Term, store: QuadSto
|
|
|
10
11
|
export declare function getMinCount(subject: RDF.Term, store: QuadStore): string | undefined;
|
|
11
12
|
export declare function getMaxCount(subject: RDF.Term, store: QuadStore): string | undefined;
|
|
12
13
|
export declare function createList(items: RDF.Term[], store: QuadStore, df: DataFactory): RDF.BlankNode | RDF.NamedNode;
|
|
13
|
-
export declare function findAllAttributes(subject: RDF.Term, attributeIds: RDF.Term[], store: QuadStore): RDF.Term[];
|
|
14
|
+
export declare function findAllAttributes(subject: RDF.Term, attributeIds: RDF.Term[], store: QuadStore, logger: Logger, visited?: Set<string>): RDF.Term[];
|
|
14
15
|
export declare function areStoresEqual(store1: QuadStore, store2: QuadStore): boolean;
|
package/lib/utils/storeUtils.js
CHANGED
|
@@ -116,15 +116,37 @@ function createList(items, store, df) {
|
|
|
116
116
|
return list[0];
|
|
117
117
|
}
|
|
118
118
|
exports.createList = createList;
|
|
119
|
-
function findAllAttributes(subject, attributeIds, store) {
|
|
120
|
-
|
|
119
|
+
function findAllAttributes(subject, attributeIds, store, logger, visited = new Set()) {
|
|
120
|
+
let parentIds = store.findObjects(subject, namespaces_1.ns.rdfs('subClassOf'));
|
|
121
|
+
if (visited.has(subject.value)) {
|
|
122
|
+
logger.warn(`[QuadStore]: Circular reference detected for ${subject.value}`);
|
|
123
|
+
return attributeIds;
|
|
124
|
+
}
|
|
125
|
+
visited.add(subject.value);
|
|
126
|
+
// Merge all referenced dummy parents with the real one based on assigned URI
|
|
127
|
+
let additionalParentIds = [];
|
|
128
|
+
for (const parentId of parentIds) {
|
|
129
|
+
const assignedUri = store.findObject(parentId, namespaces_1.ns.oslo('assignedURI'));
|
|
130
|
+
if (!assignedUri)
|
|
131
|
+
continue;
|
|
132
|
+
additionalParentIds = [
|
|
133
|
+
...additionalParentIds,
|
|
134
|
+
...store
|
|
135
|
+
.findSubjects(namespaces_1.ns.oslo('assignedURI'), assignedUri)
|
|
136
|
+
.filter((item) => item.value !== subject.value),
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
parentIds = [...parentIds, ...additionalParentIds];
|
|
140
|
+
// Collect all attributes
|
|
121
141
|
attributeIds = [
|
|
122
142
|
...attributeIds,
|
|
123
143
|
...store.findSubjects(namespaces_1.ns.rdfs('domain'), subject),
|
|
124
144
|
];
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
// Recursive search further for attributes
|
|
146
|
+
for (const parentId of parentIds)
|
|
147
|
+
attributeIds = findAllAttributes(parentId, attributeIds, store, logger, visited);
|
|
148
|
+
// Remove from visited so other paths can still traverse through this node
|
|
149
|
+
visited.delete(subject.value);
|
|
128
150
|
return attributeIds;
|
|
129
151
|
}
|
|
130
152
|
exports.findAllAttributes = findAllAttributes;
|
|
@@ -135,7 +157,7 @@ function areStoresEqual(store1, store2) {
|
|
|
135
157
|
// Quick check: different sizes means not equal
|
|
136
158
|
// Second check allows store2 to have more quads than store1 if it has all quads of store1 plus more
|
|
137
159
|
if (quads1.length !== quads2.length) {
|
|
138
|
-
console.log(`[
|
|
160
|
+
console.log(`[QuadStore]: Store1 has a length of ${quads1.length} whilst Store2 has a length of ${quads2.length}.`);
|
|
139
161
|
return false;
|
|
140
162
|
}
|
|
141
163
|
// Check if every quad in store1 exists in store2
|
|
@@ -143,7 +165,7 @@ function areStoresEqual(store1, store2) {
|
|
|
143
165
|
for (const quad1 of quads1) {
|
|
144
166
|
const matchingQuad = store2.findQuad(quad1.subject, quad1.predicate, quad1.object, quad1.graph);
|
|
145
167
|
if (!matchingQuad) {
|
|
146
|
-
console.log(`[
|
|
168
|
+
console.log(`[QuadStore]: Quad not found in store2: ${(_a = quad1.subject) === null || _a === void 0 ? void 0 : _a.value} ${(_b = quad1.predicate) === null || _b === void 0 ? void 0 : _b.value} ${(_c = quad1.object) === null || _c === void 0 ? void 0 : _c.value} ${(_d = quad1.graph) === null || _d === void 0 ? void 0 : _d.value}`);
|
|
147
169
|
return false;
|
|
148
170
|
}
|
|
149
171
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslo-flanders/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
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",
|
package/lib/types/splitUri.d.ts
DELETED
package/lib/types/splitUri.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitUri = void 0;
|
|
4
|
-
const prefixes_1 = require("../constants/prefixes");
|
|
5
|
-
async function splitUri(uri) {
|
|
6
|
-
/* Extract prefix and element by finding the last occurrence of # or / */
|
|
7
|
-
const hashIndex = uri.lastIndexOf('#');
|
|
8
|
-
const slashIndex = uri.lastIndexOf('/');
|
|
9
|
-
const splitIndex = Math.max(hashIndex, slashIndex);
|
|
10
|
-
if (splitIndex > 0) {
|
|
11
|
-
const prefixUri = uri.slice(0, Math.max(0, splitIndex + 1));
|
|
12
|
-
const element = uri.replace(prefixUri, '');
|
|
13
|
-
const prefixes = await (0, prefixes_1.getPrefixes)();
|
|
14
|
-
let prefixLabel;
|
|
15
|
-
for (const [label, puri] of Object.entries(prefixes)) {
|
|
16
|
-
if (puri === prefixUri) {
|
|
17
|
-
prefixLabel = label;
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/* No known prefix found for URI */
|
|
22
|
-
if (!prefixLabel) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
prefix: prefixLabel,
|
|
27
|
-
uri: prefixUri,
|
|
28
|
-
element,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/* Splitting failed */
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
exports.splitUri = splitUri;
|
|
35
|
-
//# sourceMappingURL=splitUri.js.map
|
package/lib/utils/quadSort.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type * as RDF from '@rdfjs/types';
|
|
2
|
-
/**
|
|
3
|
-
* Sort function used on an array of quads. First sorts named nodes alphabetically, then blank nodes alphabetically.
|
|
4
|
-
* @param quadA An RDF.Quad
|
|
5
|
-
* @param quadB An RDF.Quad
|
|
6
|
-
* @returns a number
|
|
7
|
-
*/
|
|
8
|
-
export declare const quadSort: (quadA: RDF.Quad, quadB: RDF.Quad) => number;
|
package/lib/utils/quadSort.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.quadSort = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Sort function used on an array of quads. First sorts named nodes alphabetically, then blank nodes alphabetically.
|
|
6
|
-
* @param quadA An RDF.Quad
|
|
7
|
-
* @param quadB An RDF.Quad
|
|
8
|
-
* @returns a number
|
|
9
|
-
*/
|
|
10
|
-
const quadSort = (quadA, quadB) => {
|
|
11
|
-
if (quadA.subject.termType === quadB.subject.termType) {
|
|
12
|
-
return quadA.subject.value.localeCompare(quadB.subject.value);
|
|
13
|
-
}
|
|
14
|
-
return quadA.subject.termType === 'BlankNode' ? 1 : -1;
|
|
15
|
-
};
|
|
16
|
-
exports.quadSort = quadSort;
|
|
17
|
-
//# sourceMappingURL=quadSort.js.map
|