@semapps/ontologies 0.6.0-alpha.5 → 0.6.0-alpha.7
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/actions/findNamespace.js +21 -0
- package/actions/get.js +14 -6
- package/actions/prefixToUri.js +27 -0
- package/package.json +3 -3
- package/service.js +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const fetch = require('node-fetch');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
visibility: 'public',
|
|
5
|
+
params: {
|
|
6
|
+
prefix: 'string'
|
|
7
|
+
},
|
|
8
|
+
async handler(ctx) {
|
|
9
|
+
const { prefix } = ctx.params;
|
|
10
|
+
|
|
11
|
+
const response = await fetch(`http://prefix.cc/${prefix}.file.json`);
|
|
12
|
+
|
|
13
|
+
if (response.ok) {
|
|
14
|
+
const json = await response.json();
|
|
15
|
+
|
|
16
|
+
return json && json[prefix];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
package/actions/get.js
CHANGED
|
@@ -8,25 +8,33 @@ module.exports = {
|
|
|
8
8
|
cache: true,
|
|
9
9
|
async handler(ctx) {
|
|
10
10
|
let { prefix, namespace, uri } = ctx.params;
|
|
11
|
+
let ontology;
|
|
12
|
+
|
|
11
13
|
if (!prefix && !namespace && !uri) throw new Error('You must provide a prefix, namespace or uri parameter');
|
|
12
14
|
|
|
13
15
|
if (this.settings.persistRegistry) {
|
|
14
16
|
if (prefix) {
|
|
15
|
-
|
|
17
|
+
ontology = await ctx.call('ontologies.registry.getByPrefix', { prefix });
|
|
16
18
|
} else if (namespace) {
|
|
17
|
-
|
|
19
|
+
ontology = await ctx.call('ontologies.registry.getByNamespace', { namespace });
|
|
18
20
|
} else if (uri) {
|
|
19
21
|
const ontologies = await ctx.call('ontologies.registry.list');
|
|
20
|
-
|
|
22
|
+
ontology = ontologies.find(o => uri.startsWith(o.namespace));
|
|
21
23
|
}
|
|
22
24
|
} else {
|
|
23
25
|
if (prefix) {
|
|
24
|
-
|
|
26
|
+
ontology = this.ontologies[prefix] || false;
|
|
25
27
|
} else if (namespace) {
|
|
26
|
-
|
|
28
|
+
ontology = Object.values(this.ontologies).find(o => o.namespace === namespace);
|
|
27
29
|
} else if (uri) {
|
|
28
|
-
|
|
30
|
+
ontology = Object.values(this.ontologies).find(o => uri.startsWith(o.namespace));
|
|
29
31
|
}
|
|
30
32
|
}
|
|
33
|
+
|
|
34
|
+
// Must return null if no results, because the cache JsonSerializer cannot handle undefined values
|
|
35
|
+
// https://moleculer.services/docs/0.14/networking.html#JSON-serializer
|
|
36
|
+
if (ontology === undefined) ontology = null;
|
|
37
|
+
|
|
38
|
+
return ontology;
|
|
31
39
|
}
|
|
32
40
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { isURL } = require('../utils');
|
|
2
|
+
|
|
3
|
+
const regexPrefix = /^([^:]+):([^:]+)$/gm;
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
visibility: 'public',
|
|
7
|
+
params: {
|
|
8
|
+
value: 'string'
|
|
9
|
+
},
|
|
10
|
+
cache: true,
|
|
11
|
+
async handler(ctx) {
|
|
12
|
+
const { value } = ctx.params;
|
|
13
|
+
|
|
14
|
+
// Check if this is already a full URI
|
|
15
|
+
if (isURL(value)) return value;
|
|
16
|
+
|
|
17
|
+
if (!value.match(regexPrefix)) throw new Error(`The provided value ${value} is neither prefixed, nor a full URI`);
|
|
18
|
+
|
|
19
|
+
const matchResults = regexPrefix.exec(value);
|
|
20
|
+
const prefix = matchResults[1];
|
|
21
|
+
|
|
22
|
+
const ontology = await this.actions.get({ prefix });
|
|
23
|
+
if (!ontology) throw new Error(`No ontology found with prefix ${prefix}`);
|
|
24
|
+
|
|
25
|
+
return value.replace(`${ontology.prefix}:`, ontology.namespace);
|
|
26
|
+
}
|
|
27
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semapps/ontologies",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.7",
|
|
4
4
|
"description": "SemApps ontologies",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Virtual Assembly",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@semapps/triplestore": "0.6.0-alpha.
|
|
8
|
+
"@semapps/triplestore": "0.6.0-alpha.7",
|
|
9
9
|
"moleculer-db": "^0.8.16",
|
|
10
10
|
"node-fetch": "^2.6.6"
|
|
11
11
|
},
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=14"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "7af60c59fc7524fe32a5931ba9609d55b228fea5"
|
|
19
19
|
}
|
package/service.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
const { TripleStoreAdapter } = require('@semapps/triplestore');
|
|
2
2
|
const OntologiesRegistryService = require('./sub-services/registry');
|
|
3
3
|
const findPrefixAction = require('./actions/findPrefix');
|
|
4
|
+
const findNamespaceAction = require('./actions/findNamespace');
|
|
4
5
|
const getAction = require('./actions/get');
|
|
5
6
|
const getPrefixesAction = require('./actions/getPrefixes');
|
|
6
7
|
const getRdfPrefixesAction = require('./actions/getRdfPrefixes');
|
|
7
8
|
const listAction = require('./actions/list');
|
|
9
|
+
const prefixToUriAction = require('./actions/prefixToUri');
|
|
8
10
|
const registerAction = require('./actions/register');
|
|
9
11
|
|
|
10
12
|
module.exports = {
|
|
@@ -30,10 +32,12 @@ module.exports = {
|
|
|
30
32
|
},
|
|
31
33
|
actions: {
|
|
32
34
|
findPrefix: findPrefixAction,
|
|
35
|
+
findNamespace: findNamespaceAction,
|
|
33
36
|
get: getAction,
|
|
34
37
|
getPrefixes: getPrefixesAction,
|
|
35
38
|
getRdfPrefixes: getRdfPrefixesAction,
|
|
36
39
|
list: listAction,
|
|
40
|
+
prefixToUri: prefixToUriAction,
|
|
37
41
|
register: registerAction
|
|
38
42
|
},
|
|
39
43
|
methods: {
|