Skip to content

Commit c504d47

Browse files
authored
Merge pull request #1 from Raphael-Gazzotti/namespace-change
Namespace changes.
2 parents e60e9b4 + 574f598 commit c504d47

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

build.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import yaml
1212

1313
from pipeline.translator import LinkMLClassBuilder, LinkMLSlotBuilder, LinkMLEnumBuilder
14-
from pipeline.utils import clone_sources, SchemaLoader, InstanceLoader, get_short_name
14+
from pipeline.utils import clone_sources, SchemaLoader, InstanceLoader, get_short_name, get_short_namespace
1515

1616

1717
terms_as_enums = True
@@ -43,6 +43,7 @@
4343

4444
for schema_version in schema_loader.get_schema_versions():
4545
imports = []
46+
short_namespace = get_short_namespace(schema_loader.get_namespaces_version(schema_version)['props'])
4647

4748
# Step 3 - find all involved schemas for the current version
4849
schemas_file_paths = schema_loader.find_schemas(schema_version)
@@ -98,15 +99,15 @@
9899
).build()
99100
linkml_classes[module].append(linkml_class)
100101
enum_schema = {
101-
"id": f"https://openminds.ebrains.eu/schemas/latest/enums?format=linkml",
102+
"id": f"{short_namespace}/schemas/latest/enums?format=linkml",
102103
"name": "openMINDS-enums",
103104
"title": f'OpenMINDS instance library as LinkML enums, version "{schema_version}"',
104105
"description": f'Enums for the LinkML representation of openMINDS metadata framework, version "{schema_version}"',
105106
"license": "https://spdx.org/licenses/MIT.html",
106107
"prefixes": {
107108
"linkml": "https://w3id.org/linkml/",
108109
"schema": "http://schema.org/",
109-
"omi": "https://openminds.ebrains.eu",
110+
"omi": f"{short_namespace}",
110111
},
111112
"default_prefix": "omi",
112113
"imports": ["linkml:types"] + linkml_enum_imports,
@@ -122,7 +123,7 @@
122123
)
123124
os.makedirs(os.path.dirname(target_file), exist_ok=True)
124125
module_schema = {
125-
"id": f"https://openminds.ebrains.eu/schemas/latest/{module_name}?format=linkml",
126+
"id": f"{short_namespace}/schemas/latest/{module_name}?format=linkml",
126127
"name": f"openMINDS-{module_name}",
127128
"title": f'OpenMINDS {module_name} module, version "{schema_version}"',
128129
"description": f'Schemas for the {module_name} module of the openMINDS metadata framework, version "{schema_version}"',
@@ -131,7 +132,7 @@
131132
"prefixes": {
132133
"linkml": "https://w3id.org/linkml/",
133134
"schema": "http://schema.org/",
134-
"omi": "https://openminds.ebrains.eu",
135+
"omi": f"{short_namespace}",
135136
},
136137
"default_prefix": "omi",
137138
"classes": class_list,
@@ -142,15 +143,15 @@
142143

143144
# Step 6 - write slots file
144145
slots_schema = {
145-
"id": f"https://openminds.ebrains.eu/schemas/latest/slots?format=linkml",
146+
"id": f"{short_namespace}/schemas/latest/slots?format=linkml",
146147
"name": "openMINDS-slots",
147148
"title": f'OpenMINDS properties as LinkML slots, version "{schema_version}"',
148149
"description": f'Slots for the LinkML representation of the openMINDS metadata framework, version "{schema_version}"',
149150
"license": "https://spdx.org/licenses/MIT.html",
150151
"prefixes": {
151152
"linkml": "https://w3id.org/linkml/",
152153
"schema": "http://schema.org/",
153-
"omi": "https://openminds.ebrains.eu",
154+
"omi": f"{short_namespace}",
154155
},
155156
"default_prefix": "omi",
156157
"imports": ["linkml:types"],
@@ -164,7 +165,7 @@
164165

165166
# Step 7 - write types file
166167
types_metadata = {
167-
"id": f"https://openminds.ebrains.eu/schemas/latest/types/?format=linkml",
168+
"id": f"{short_namespace}/schemas/latest/types/?format=linkml",
168169
"name": "openMINDS-types",
169170
"title": f'Types for OpenMINDS version "{schema_version}"',
170171
"description": f'Types for the LinkML representation of the openMINDS metadata framework, version "{schema_version}"',
@@ -173,7 +174,7 @@
173174
"prefixes": {
174175
"linkml": "https://w3id.org/linkml/",
175176
"schema": "http://schema.org/",
176-
"omi": "https://openminds.ebrains.eu",
177+
"omi": f"{short_namespace}",
177178
},
178179
"default_prefix": "omi",
179180
"types": {
@@ -200,7 +201,7 @@
200201

201202
# Step 7 - create overall schema file
202203
schema_metadata = {
203-
"id": f"https://openminds.ebrains.eu/schemas/latest/?format=linkml",
204+
"id": f"{short_namespace}/schemas/latest/?format=linkml",
204205
"name": "openMINDS",
205206
"title": f'OpenMINDS version "{schema_version}"',
206207
"description": f'The complete collection of schemas for all metadata models of the openMINDS metadata framework, version "{schema_version}"',
@@ -209,7 +210,7 @@
209210
"prefixes": {
210211
"linkml": "https://w3id.org/linkml/",
211212
"schema": "http://schema.org/",
212-
"omi": "https://openminds.ebrains.eu",
213+
"omi": f"{short_namespace}",
213214
},
214215
"default_prefix": "omi",
215216
}

pipeline/translator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os.path
44
from typing import List, Optional, Dict
55

6-
from pipeline.utils import get_short_name
6+
from pipeline.utils import get_short_name, get_short_namespace
77

88

99
class LinkMLClassBuilder(object):
@@ -304,18 +304,19 @@ def build(self):
304304
)
305305
os.makedirs(os.path.dirname(target_file), exist_ok=True)
306306
short_type = get_short_name(self._schema_payload["_type"])
307+
short_namespace = get_short_namespace(self._schema_payload["_type"])
307308
self.translate()
308309

309310
enum_schema = {
310-
"id": f"https://openminds.ebrains.eu/schemas/latest/enums/{short_type}?format=linkml",
311+
"id": f"{short_namespace}/schemas/latest/enums/{short_type}?format=linkml",
311312
"name": f"openMINDS-enums-{short_type}",
312313
"title": f"OpenMINDS enum for {short_type}",
313314
"description": f"OpenMINDS enum for {short_type}",
314315
"license": "https://spdx.org/licenses/MIT.html",
315316
"prefixes": {
316317
"linkml": "https://w3id.org/linkml/",
317318
"schema": "http://schema.org/",
318-
"omi": "https://openminds.ebrains.eu",
319+
"omi": f"{short_namespace}",
319320
},
320321
"default_prefix": "omi",
321322
"enums": {short_type: self._translated_schema},

pipeline/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import glob
22
import json
33
import os
4+
import re
45
import shutil
56
from typing import List
67

@@ -13,6 +14,14 @@ def clone_sources():
1314
Repo.clone_from(
1415
"https://github.com/openMetadataInitiative/openMINDS.git",
1516
to_path="_sources",
17+
depth=1
18+
)
19+
if os.path.exists("_sources_pipeline"):
20+
shutil.rmtree("_sources_pipeline")
21+
Repo.clone_from(
22+
"https://github.com/openMetadataInitiative/openMINDS.git",
23+
to_path="_sources_pipeline",
24+
branch="pipeline",
1625
depth=1,
1726
)
1827
if os.path.exists("_instances"):
@@ -27,6 +36,10 @@ def clone_sources():
2736
def get_short_name(uri):
2837
return uri.split("/")[-1]
2938

39+
def get_short_namespace(uri):
40+
match = re.match(r'^(https?:\/\/[^\/]+)', uri)
41+
return match.group(1) if match else None
42+
3043

3144
class SchemaLoader(object):
3245

@@ -46,6 +59,11 @@ def get_properties(self, version:str):
4659
all_properties = json.load(fp)
4760
return {name: p for name, p in all_properties.items() if version in p["usedIn"]}
4861

62+
def get_namespaces_version(self, version:str):
63+
path = os.path.join(self._root_directory, "_sources_pipeline", "versions.json")
64+
with open(path) as fp:
65+
all_namespaces = json.load(fp)
66+
return all_namespaces[version]["namespaces"]
4967

5068

5169
class InstanceLoader:

0 commit comments

Comments
 (0)