Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@ Using these classes, it is possible to list all metadata matching a particular c
```

```
>>> datasets = DatasetVersion.list(client, techniques=whole_cell_patch, scope="in progress")
>>> datasets = DatasetVersion.list(client, techniques=whole_cell_patch, release_status="in progress")
```

For research products that are versioned, such as datasets, models, and software, certain attributes may be inherited from the parent (e.g. a DatasetVersion generally inherits its name from a Dataset). In this case, we have a convenience method to retrieve the parent's name:

```
>>> print(datasets[0].get_name(client, scope="in progress"))
>>> print(datasets[0].get_name(client, release_status="in progress"))
'Cholinergic interneurons in the striatum - Single cell patch clamp recordings'
```

If you know the unique identifier of an object, you can retrieve it directly:

```
>>> dataset = DatasetVersion.from_id("17196b79-04db-4ea4-bb69-d20aab6f1d62", client, scope="in progress")
>>> dataset = DatasetVersion.from_id("17196b79-04db-4ea4-bb69-d20aab6f1d62", client, release_status="in progress")
```

Links between metadata in the Knowledge Graph are not followed automatically,
to avoid unnecessary network traffic, but can be followed with the `resolve()` method:

```
>>> license = dataset.license.resolve(client, scope="in progress")
>>> authors = [author.resolve(client, scope="in progress") for author in dataset.authors]
>>> license = dataset.license.resolve(client, release_status="in progress")
>>> authors = [author.resolve(client, release_status="in progress") for author in dataset.authors]
```

The associated metadata is accessible as attributes of the Python objects, e.g.:
Expand Down
2 changes: 1 addition & 1 deletion builder/additional_methods/DatasetVersion.py.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def download(self, local_path, client, accept_terms_of_use=False):
if accepted_terms_of_use(client, accept_terms_of_use=accept_terms_of_use):
repo = self.repository.resolve(client, scope=self.scope or None)
repo = self.repository.resolve(client, release_status=self.release_status or None)
if (repo.iri.value.startswith("https://object.cscs.ch/v1/AUTH")
or repo.iri.value.startswith("https://data-proxy.ebrains.eu/api/v1/public")
):
Expand Down
2 changes: 1 addition & 1 deletion builder/additional_methods/Person.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def me(cls, client, allow_multiple=False, follow_links=None):
user_info = client.user_info()
possible_matches = cls.list(
client, scope="in progress", space="common",
client, release_status="in progress", space="common",
follow_links=follow_links,
family_name=user_info.family_name,
given_name=user_info.given_name
Expand Down
2 changes: 1 addition & 1 deletion builder/additional_methods/ScholarlyArticle.py.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def get_journal(self, client, with_volume=False, with_issue=False):
journal = volume = issue = None
if self.is_part_of:
issue_or_volume = self.is_part_of.resolve(client, scope=self.scope, follow_links={"is_part_of": {}})
issue_or_volume = self.is_part_of.resolve(client, release_status=self.release_status, follow_links={"is_part_of": {}})
if isinstance(issue_or_volume, PublicationIssue):
volume = issue_or_volume.is_part_of
issue = issue_or_volume
Expand Down
2 changes: 1 addition & 1 deletion builder/fairgraph_module_template.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ class {{ class_name }}({{base_class}}, OM{{ class_name }}):
existence_query_properties = {{ existence_query_properties }}
{%- endif %}

def __init__(self {%- for arg in constructor_arguments -%}, {{arg}}=None{%- endfor -%}, id=None, data=None, space=None, scope=None):
def __init__(self {%- for arg in constructor_arguments -%}, {{arg}}=None{%- endfor -%}, id=None, data=None, space=None, release_status=None):
return {{ base_class }}.__init__(self, {{ standard_init_properties }}data=data {%- for arg in constructor_arguments -%}, {{arg}}={{arg}}{%- endfor -%})
{{ additional_methods }}
37 changes: 14 additions & 23 deletions builder/update_openminds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@

OPENMINDS_VERSION = "latest"

name_map = {
"scope": "model_scope", # this is because 'scope' is already a keyword
# we could rename the 'scope' keyword to 'stage'
# but we would have the same problem, as there is
# a property named 'stage'
# Suggested resolution: rename the property "scope" in openMINDS to "hasScope"
}

global_aliases = {
"short_name": "alias",
"full_name": "name",
"has_versions": "versions",
"has_entity": "entities",
"hashes": "hash"
"hashes": "hash",
"scope": "model_scope"
}


Expand Down Expand Up @@ -235,20 +229,17 @@
}

def generate_python_name(json_name):
if json_name in name_map:
python_name = name_map[json_name]
else:
python_name = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", json_name.strip())
python_name = re.sub("([a-z0-9])([A-Z])", r"\1_\2", python_name).lower()
replacements = [
("-", "_"), (".", "_"), ("+", "plus"), ("#", "sharp"), (",", "comma"), ("(", ""), (")", "")
]
for before, after in replacements:
python_name = python_name.replace(before, after)
if python_name[0] in number_names: # Python variables can't start with a number
python_name = number_names[python_name[0]] + python_name[1:]
if not python_name.isidentifier():
raise NameError(f"Cannot generate a valid Python name from '{json_name}'")
python_name = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", json_name.strip())
python_name = re.sub("([a-z0-9])([A-Z])", r"\1_\2", python_name).lower()
replacements = [
("-", "_"), (".", "_"), ("+", "plus"), ("#", "sharp"), (",", "comma"), ("(", ""), (")", "")
]
for before, after in replacements:
python_name = python_name.replace(before, after)
if python_name[0] in number_names: # Python variables can't start with a number
python_name = number_names[python_name[0]] + python_name[1:]
if not python_name.isidentifier():
raise NameError(f"Cannot generate a valid Python name from '{json_name}'")
return python_name


Expand Down Expand Up @@ -665,7 +656,7 @@ def get_type(prop):
else:
base_class = "KGObject"
default_space = get_default_space(module_name, class_name)
standard_init_properties = "id=id, space=space, scope=scope, "
standard_init_properties = "id=id, space=space, release_status=release_status, "
properties = []
plurals_special_cases = {
# because this is a single item (PropertyValueList), but that item contains a list
Expand Down
2 changes: 1 addition & 1 deletion fairgraph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Resolvable: # all
def resolve(
self,
client: KGClient,
scope: Optional[str] = None,
release_status: Optional[str] = None,
use_cache: bool = True,
follow_links: Optional[Dict[str, Any]] = None,
):
Expand Down
Loading