@oslo-flanders/core 1.0.15 → 1.0.17

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.
@@ -1,3 +1,4 @@
1
+ export declare const DataTypes: Map<string, string>;
1
2
  export declare const getDataType: (key: string) => string | undefined;
2
3
  export declare const datatypeIdentifierToHash: (uri: string) => number;
3
4
  export declare const isStandardDatatype: (uri: string) => boolean;
@@ -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
- const DataTypes = new Map([
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
@@ -1,5 +1,6 @@
1
1
  export declare enum OutputFormat {
2
2
  JsonLd = "application/ld+json",
3
+ JsonProblem = "application/problem+json",
3
4
  Json = "application/json",
4
5
  trig = "application/trig",
5
6
  turtle = "text/turtle",
@@ -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";
@@ -226,4 +226,16 @@ export declare class QuadStore {
226
226
  * @param graph The RDF.Term of the named graph
227
227
  */
228
228
  getChildAttribute(subject: RDF.Term, graph?: RDF.Term | null): RDF.Term | undefined;
229
+ /**
230
+ * Check if class is abstract
231
+ * @param subject The RDF.Term to determine if it is an abstract class
232
+ * @param graph The RDF.Term of the named graph
233
+ */
234
+ isAbstractClass(subject: RDF.Term, graph?: RDF.Term | null): boolean;
235
+ /**
236
+ * Check if class is root object
237
+ * @param subject The RDF.Term to determine if it is an root object
238
+ * @param graph The RDF.Term of the named graph
239
+ */
240
+ isRootClass(subject: RDF.Term, graph?: RDF.Term | null): boolean;
229
241
  }
@@ -389,6 +389,30 @@ let QuadStore = class QuadStore {
389
389
  getChildAttribute(subject, graph = null) {
390
390
  return (this.findObject(subject, namespaces_1.ns.oslo('childAttribute')));
391
391
  }
392
+ /**
393
+ * Check if class is abstract
394
+ * @param subject The RDF.Term to determine if it is an abstract class
395
+ * @param graph The RDF.Term of the named graph
396
+ */
397
+ isAbstractClass(subject, graph = null) {
398
+ const types = this.findObjects(subject, namespaces_1.ns.rdf('type'));
399
+ for (const t of types)
400
+ if (t.value === namespaces_1.ns.oslo('AbstractClass').value)
401
+ return true;
402
+ return false;
403
+ }
404
+ /**
405
+ * Check if class is root object
406
+ * @param subject The RDF.Term to determine if it is an root object
407
+ * @param graph The RDF.Term of the named graph
408
+ */
409
+ isRootClass(subject, graph = null) {
410
+ const types = this.findObjects(subject, namespaces_1.ns.rdf('type'));
411
+ for (const t of types)
412
+ if (t.value === namespaces_1.ns.oslo('RootClass').value)
413
+ return true;
414
+ return false;
415
+ }
392
416
  };
393
417
  QuadStore = __decorate([
394
418
  (0, inversify_1.injectable)(),
@@ -0,0 +1,6 @@
1
+ export interface SplittedUri {
2
+ prefix: string;
3
+ uri: string;
4
+ element: string;
5
+ }
6
+ export declare function splitUri(uri: string): Promise<SplittedUri | undefined>;
@@ -0,0 +1,35 @@
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
@@ -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;
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,17 @@
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
@@ -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;
@@ -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
- const parentIds = store.findObjects(subject, namespaces_1.ns.rdfs('subClassOf'));
119
+ function findAllAttributes(subject, attributeIds, store, logger, visited = new Set()) {
120
+ if (visited.has(subject.value)) {
121
+ logger.warn(`[QuadStore]: Circular reference detected for ${subject.value}`);
122
+ return attributeIds;
123
+ }
124
+ visited.add(subject.value);
125
+ let parentIds = store.findObjects(subject, namespaces_1.ns.rdfs('subClassOf'));
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
- for (const parentId of parentIds) {
126
- attributeIds = findAllAttributes(parentId, attributeIds, store);
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(`[QUadStore]: Store1 has a length of ${quads1.length} whilst Store2 has a length of ${quads2.length}.`);
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(`[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}`);
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.15",
3
+ "version": "1.0.17",
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",