@semapps/ontologies 0.6.0-alpha.5
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/LICENSE +201 -0
- package/README.md +3 -0
- package/actions/findPrefix.js +23 -0
- package/actions/get.js +32 -0
- package/actions/getPrefixes.js +12 -0
- package/actions/getRdfPrefixes.js +11 -0
- package/actions/list.js +11 -0
- package/actions/register.js +66 -0
- package/index.js +16 -0
- package/ontologies/core/acl.json +4 -0
- package/ontologies/core/as.json +6 -0
- package/ontologies/core/dc.json +16 -0
- package/ontologies/core/foaf.json +4 -0
- package/ontologies/core/index.js +14 -0
- package/ontologies/core/ldp.json +4 -0
- package/ontologies/core/rdf.json +4 -0
- package/ontologies/core/rdfs.json +4 -0
- package/ontologies/core/sec.json +45 -0
- package/ontologies/core/semapps.json +4 -0
- package/ontologies/core/vcard.json +15 -0
- package/ontologies/core/void.json +23 -0
- package/ontologies/core/xsd.json +4 -0
- package/ontologies/custom/index.js +11 -0
- package/ontologies/custom/mp.json +4 -0
- package/ontologies/custom/oasis.json +4 -0
- package/ontologies/custom/og.json +13 -0
- package/ontologies/custom/pair.json +328 -0
- package/ontologies/custom/petr.json +4 -0
- package/ontologies/custom/schema.json +4 -0
- package/ontologies/custom/skos.json +13 -0
- package/ontologies/custom/syreen.json +43 -0
- package/ontologies/custom/tutor.json +26 -0
- package/ontologies/solid/apods.json +55 -0
- package/ontologies/solid/index.js +1 -0
- package/ontologies/solid/interop.json +64 -0
- package/ontologies/solid/oidc.json +28 -0
- package/package.json +19 -0
- package/service.js +47 -0
- package/sub-services/registry.js +71 -0
- package/utils.js +19 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const DbService = require('moleculer-db');
|
|
2
|
+
const { TripleStoreAdapter } = require('@semapps/triplestore');
|
|
3
|
+
const { isURL } = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
name: 'ontologies.registry',
|
|
7
|
+
mixins: [DbService],
|
|
8
|
+
adapter: new TripleStoreAdapter({ type: 'Ontology', dataset: 'settings' }),
|
|
9
|
+
settings: {
|
|
10
|
+
idField: '@id'
|
|
11
|
+
},
|
|
12
|
+
actions: {
|
|
13
|
+
async getByPrefix(ctx) {
|
|
14
|
+
const { prefix } = ctx.params;
|
|
15
|
+
const [ontology] = await this._find(ctx, { query: { prefix } });
|
|
16
|
+
return this.parse(ontology);
|
|
17
|
+
},
|
|
18
|
+
async getByNamespace(ctx) {
|
|
19
|
+
const { namespace } = ctx.params;
|
|
20
|
+
const [ontology] = await this._find(ctx, { query: { namespace } });
|
|
21
|
+
return this.parse(ontology);
|
|
22
|
+
},
|
|
23
|
+
async list(ctx) {
|
|
24
|
+
const ontologies = await this._list(ctx, {});
|
|
25
|
+
return ontologies.rows.map(({ prefix, namespace, owl, jsonldContext, preserveContextUri }) => {
|
|
26
|
+
return this.parse({ prefix, namespace, owl, jsonldContext, preserveContextUri });
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
async updateOrCreate(ctx) {
|
|
30
|
+
let { prefix, namespace, owl, jsonldContext, preserveContextUri } = ctx.params;
|
|
31
|
+
|
|
32
|
+
const ontology = await this.actions.getByPrefix({ prefix }, { parentCtx: ctx });
|
|
33
|
+
|
|
34
|
+
if (!isURL(jsonldContext)) jsonldContext = JSON.stringify(jsonldContext);
|
|
35
|
+
|
|
36
|
+
if (ontology) {
|
|
37
|
+
await this._update(ctx, {
|
|
38
|
+
'@id': ontology['@id'],
|
|
39
|
+
namespace,
|
|
40
|
+
owl,
|
|
41
|
+
jsonldContext,
|
|
42
|
+
preserveContextUri
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
await this._create(ctx, {
|
|
46
|
+
prefix,
|
|
47
|
+
namespace,
|
|
48
|
+
owl,
|
|
49
|
+
jsonldContext,
|
|
50
|
+
preserveContextUri
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
methods: {
|
|
56
|
+
parse(ontology) {
|
|
57
|
+
// If the jsonldContext is not an URL, it is an object to be parsed
|
|
58
|
+
if (ontology?.jsonldContext && !isURL(ontology.jsonldContext)) {
|
|
59
|
+
ontology.jsonldContext = JSON.parse(ontology.jsonldContext);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (ontology?.preserveContextUri === 'true') {
|
|
63
|
+
ontology.preserveContextUri = true;
|
|
64
|
+
} else if (ontology?.preserveContextUri === 'false') {
|
|
65
|
+
ontology.preserveContextUri = false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return ontology;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
package/utils.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const arrayOf = value => {
|
|
2
|
+
// If the field is null-ish, we suppose there are no values.
|
|
3
|
+
if (!value) {
|
|
4
|
+
return [];
|
|
5
|
+
}
|
|
6
|
+
// Return as is.
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
// Single value is made an array.
|
|
11
|
+
return [value];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const isURL = value => (typeof value === 'string' || value instanceof String) && value.startsWith('http');
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
arrayOf,
|
|
18
|
+
isURL
|
|
19
|
+
};
|