Skip to content

Commit c8f7a0a

Browse files
committed
Appropriate context
1 parent a8df009 commit c8f7a0a

3 files changed

Lines changed: 70 additions & 3 deletions

File tree

pipeline/src/module_template.py.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class {{ class_name }}({{ base_class }}):
1616
"""
1717
type_ = "{{ openminds_type }}"
1818
context = {
19-
"@vocab": "https://openminds.ebrains.eu/vocab/"
19+
"@vocab": "https://openminds.om-i.org/vocab/"
2020
}
2121
schema_version = "{{ schema_version }}"
2222

@@ -61,4 +61,4 @@ class {{ class_name }}({{ base_class }}):
6161
{{key}}={{value}},
6262
{%- endif %}
6363
{% endfor -%}
64-
){% endfor %}
64+
){% endfor %}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
{{docstring}}
3+
"""
4+
5+
# this file was auto-generated!
6+
7+
{{preamble}}
8+
9+
from openminds.base import {{ base_class }}
10+
from openminds.properties import Property
11+
12+
13+
class {{ class_name }}({{ base_class }}):
14+
"""
15+
{{ docstring }}
16+
"""
17+
type_ = "{{ openminds_type }}"
18+
context = {
19+
"@vocab": "https://openminds.ebrains.eu/vocab/"
20+
}
21+
schema_version = "{{ schema_version }}"
22+
23+
properties = [
24+
{% for property in properties -%}
25+
Property(
26+
"{{property.name}}",
27+
{{property.type}},
28+
"{{property.iri}}",
29+
{%- if property.allow_multiple %}
30+
multiple={{property.allow_multiple}},
31+
unique_items={{property.unique_items}},
32+
{% if property.min_items -%}min_items={{property.min_items}},{% endif %}
33+
{% if property.max_items -%}max_items={{property.max_items}},{% endif %}
34+
{% endif -%}
35+
{% if property.type == "str" -%}
36+
formatting="{{property.formatting}}",
37+
{% if property.multiline -%}multiline={{property.multiline}},{% endif %}
38+
{% endif %}
39+
{%- if property.required -%}required={{property.required}},{% endif %}
40+
description="{{property.description}}",
41+
instructions="{{property.instructions}}"
42+
),
43+
{% endfor %}
44+
]
45+
46+
def __init__(self{%- if base_class == "LinkedMetadata" %}, id=None{%- endif -%}{%- for property in properties -%}, {{property.name}}=None{%- endfor -%}):
47+
return super().__init__({%- if base_class == "LinkedMetadata" %}id=id, {%- endif -%}{%- for property in properties -%}{{property.name}}={{property.name}}, {%- endfor -%})
48+
49+
{{ additional_methods }}
50+
51+
{% for instance_name, instance in instances.items() %}
52+
{{ class_name }}.{{ instance_name }} = {{ class_name }}(
53+
{% for key, value in instance.items() -%}
54+
{% if value is string -%}
55+
{% if value.startswith('http') and key != 'id' -%}
56+
{{key}}=IRI("{{value}}"),
57+
{%- else -%}
58+
{{key}}="{{value}}",
59+
{%- endif %}
60+
{%- else -%}
61+
{{key}}={{value}},
62+
{%- endif %}
63+
{% endfor -%}
64+
){% endfor %}

pipeline/translator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ class PythonBuilder(object):
5757

5858
def __init__(self, schema_file_path: str, root_path: str, instances: Optional[dict] = None,
5959
additional_methods: Optional[dict] = None):
60-
self.template_name = "src/module_template.py.txt"
6160
self.env = Environment(
6261
loader=FileSystemLoader(os.path.dirname(os.path.realpath(__file__))), autoescape=select_autoescape()
6362
)
6463
_relative_path_without_extension = (
6564
schema_file_path[len(root_path) + 1 :].replace(".schema.omi.json", "").split("/")
6665
)
6766
self.version = _relative_path_without_extension[0]
67+
if self.version in ["v3.0" , "v2.0" , "v1.0"]:
68+
self.template_name = "src/module_template_old.py.txt"
69+
else:
70+
self.template_name = "src/module_template.py.txt"
6871
self.relative_path_without_extension = [
6972
generate_python_name(part) for part in _relative_path_without_extension[1:]
7073
]

0 commit comments

Comments
 (0)