Skip to content

Commit 2248509

Browse files
Merge pull request openMetadataInitiative#77 from apdavison/specify-load-version
Allow the user to specify which openMINDS version should be used by `Collection.load()`
2 parents ba033c5 + a58719a commit 2248509

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

pipeline/src/collection.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from .base import Link
1212

1313

14+
DEFAULT_VERSION = "v4"
15+
16+
1417
class Collection:
1518
"""
1619
A collection of metadata nodes that can be saved to
@@ -141,7 +144,7 @@ def save(self, path, individual_files=False, include_empty_properties=False):
141144
output_paths.append(file_path)
142145
return output_paths
143146

144-
def load(self, *paths):
147+
def load(self, *paths, version=DEFAULT_VERSION):
145148
"""
146149
Load openMINDS metadata from one or more JSON-LD files.
147150
@@ -152,6 +155,9 @@ def load(self, *paths):
152155
(but without descending into subdirectories)
153156
154157
2) one or more JSON-LD files, which will all be loaded.
158+
159+
By default, openMINDS v4 will be used.
160+
If the JSON-LD files use a different openMINDS version, specify it with the `version` argument.
155161
"""
156162
if len(paths) == 1 and os.path.isdir(paths[0]):
157163
data_dir = paths[0]
@@ -168,10 +174,6 @@ def load(self, *paths):
168174
with open(path, "r") as fp:
169175
data = json.load(fp)
170176
if "@graph" in data:
171-
if data["@context"]["@vocab"].startswith("https://openminds.ebrains.eu/"):
172-
version = "v3"
173-
else:
174-
version = "latest"
175177
for item in data["@graph"]:
176178
if "@type" in item:
177179
cls = lookup_type(item["@type"], version=version)
@@ -245,4 +247,3 @@ def sort_nodes_for_upload(self):
245247
newly_sorted.append(node_id)
246248
unsorted -= set(newly_sorted)
247249
return [self.nodes[node_id] for node_id in sorted]
248-

pipeline/tests/test_regressions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import os
44
from openminds import Collection, IRI
5-
from openminds.latest import core as omcore
5+
from openminds.v4 import core as omcore
66
from utils import build_fake_node
77

88

@@ -261,12 +261,12 @@ def test_issue0073():
261261
# Infinite recursion in validate()
262262
ds1 = omcore.DatasetVersion(
263263
short_name="ds1",
264-
is_variant_of=None
264+
is_alternative_version_of=None
265265
)
266266
ds2 = omcore.DatasetVersion(
267267
short_name="ds2",
268-
is_variant_of=ds1
268+
is_alternative_version_of=ds1
269269
)
270-
ds1.is_variant_of = ds2
270+
ds1.is_alternative_version_of = ds2
271271

272272
failures = ds1.validate()

0 commit comments

Comments
 (0)