-
Notifications
You must be signed in to change notification settings - Fork 3
Allow the user to specify which openMINDS version should be used by Collection.load()
#77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Raphael-Gazzotti
merged 1 commit into
openMetadataInitiative:pipeline
from
apdavison:specify-load-version
Nov 17, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ | |
| from .base import Link | ||
|
|
||
|
|
||
| DEFAULT_VERSION = "v4" | ||
|
|
||
|
|
||
| class Collection: | ||
| """ | ||
| 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): | |
| output_paths.append(file_path) | ||
| return output_paths | ||
|
|
||
| def load(self, *paths): | ||
| def load(self, *paths, version=DEFAULT_VERSION): | ||
| """ | ||
| Load openMINDS metadata from one or more JSON-LD files. | ||
|
|
||
|
|
@@ -152,6 +155,9 @@ def load(self, *paths): | |
| (but without descending into subdirectories) | ||
|
|
||
| 2) one or more JSON-LD files, which will all be loaded. | ||
|
|
||
| By default, openMINDS v4 will be used. | ||
| If the JSON-LD files use a different openMINDS version, specify it with the `version` argument. | ||
| """ | ||
| if len(paths) == 1 and os.path.isdir(paths[0]): | ||
| data_dir = paths[0] | ||
|
|
@@ -168,10 +174,6 @@ def load(self, *paths): | |
| with open(path, "r") as fp: | ||
| data = json.load(fp) | ||
| if "@graph" in data: | ||
| if data["@context"]["@vocab"].startswith("https://openminds.ebrains.eu/"): | ||
| version = "v3" | ||
| else: | ||
| version = "latest" | ||
| for item in data["@graph"]: | ||
| if "@type" in item: | ||
| cls = lookup_type(item["@type"], version=version) | ||
|
|
@@ -245,4 +247,3 @@ def sort_nodes_for_upload(self): | |
| newly_sorted.append(node_id) | ||
| unsorted -= set(newly_sorted) | ||
| return [self.nodes[node_id] for node_id in sorted] | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An empty line seems to be missing.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, I don't think so. I think it's just that GitHub doesn't show a line if the file ends with a linebreak |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of using a constant here, it would be better to automatically select the latest version, excluding "latest" itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that would be better. I propose to leave this for a future pull request.