Skip to content

Commit cf0d442

Browse files
author
Lyuba Zehl
authored
Merge pull request #20 from openMetadataInitiative/issue11
Use common vocabulary mapping ("@vocab")
2 parents ebbf70d + 2830179 commit cf0d442

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

pipeline/src/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def value_to_jsonld(value):
6060

6161
data = {"@type": self.type_}
6262
if with_context:
63-
data["@context"] = {"vocab": "https://openminds.ebrains.eu/vocab/"}
63+
data["@context"] = {"@vocab": "https://openminds.ebrains.eu/vocab/"}
6464
if hasattr(self, "id") and self.id:
6565
data["@id"] = self.id
6666
for property in self.__class__.properties:

pipeline/src/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def save(self, path, individual_files=False, include_empty_properties=False):
8989
if parent_dir:
9090
os.makedirs(parent_dir, exist_ok=True)
9191
data = {
92-
"@context": {"vocab": "https://openminds.ebrains.eu/vocab/"},
92+
"@context": {"@vocab": "https://openminds.ebrains.eu/vocab/"},
9393
"@graph": [
9494
node.to_jsonld(
9595
embed_linked_nodes=False, include_empty_properties=include_empty_properties, with_context=False

pipeline/src/module_template.py.txt

Lines changed: 1 addition & 1 deletion
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.ebrains.eu/vocab/"
2020
}
2121

2222
properties = [

pipeline/tests/test_regressions.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ def test_issue_0003():
3838
)
3939
# on export, a single item should be wrapped in a list, where the property expects an array
4040
expected = {
41-
"@context": {"vocab": "https://openminds.ebrains.eu/vocab/"},
41+
"@context": {"@vocab": "https://openminds.ebrains.eu/vocab/"},
4242
"@type": "https://openminds.ebrains.eu/core/FileArchive",
43-
"vocab:IRI": "http://example.com/archive.zip",
44-
"vocab:format": {
43+
"IRI": "http://example.com/archive.zip",
44+
"format": {
4545
"@type": "https://openminds.ebrains.eu/core/ContentType",
46-
"vocab:name": "application/zip",
46+
"name": "application/zip",
4747
},
48-
"vocab:sourceData": [
48+
"sourceData": [
4949
{
5050
"@type": "https://openminds.ebrains.eu/core/File",
51-
"vocab:IRI": "http://example.com/some_file.txt",
52-
"vocab:name": "some_file.txt",
51+
"IRI": "http://example.com/some_file.txt",
52+
"name": "some_file.txt",
5353
}
5454
],
5555
}
@@ -89,22 +89,22 @@ def test_issue0007():
8989

9090
actual = person.to_jsonld(include_empty_properties=False, embed_linked_nodes=False, with_context=True)
9191
expected = {
92-
"@context": {"vocab": "https://openminds.ebrains.eu/vocab/"},
92+
"@context": {"@vocab": "https://openminds.ebrains.eu/vocab/"},
9393
"@id": "_:001",
9494
"@type": "https://openminds.ebrains.eu/core/Person",
95-
"vocab:familyName": "Professor",
96-
"vocab:givenName": "A",
97-
"vocab:affiliation": [
95+
"familyName": "Professor",
96+
"givenName": "A",
97+
"affiliation": [
9898
{
9999
"@type": "https://openminds.ebrains.eu/core/Affiliation",
100-
"vocab:memberOf": {
100+
"memberOf": {
101101
"@id": "_:002",
102102
"@type": "https://openminds.ebrains.eu/core/Organization",
103103
},
104104
},
105105
{
106106
"@type": "https://openminds.ebrains.eu/core/Affiliation",
107-
"vocab:memberOf": {
107+
"memberOf": {
108108
"@id": "_:003",
109109
"@type": "https://openminds.ebrains.eu/core/Organization",
110110
},
@@ -121,39 +121,39 @@ def test_issue0007():
121121
saved_data = json.load(fp)
122122
os.remove("issue0007.jsonld")
123123
expected_saved_data = {
124-
"@context": {"vocab": "https://openminds.ebrains.eu/vocab/"},
124+
"@context": {"@vocab": "https://openminds.ebrains.eu/vocab/"},
125125
"@graph": [
126126
{
127127
"@id": "_:001",
128128
"@type": "https://openminds.ebrains.eu/core/Person",
129-
"vocab:affiliation": [
129+
"affiliation": [
130130
{
131131
"@type": "https://openminds.ebrains.eu/core/Affiliation",
132-
"vocab:memberOf": {
132+
"memberOf": {
133133
"@id": "_:002",
134134
"@type": "https://openminds.ebrains.eu/core/Organization",
135135
},
136136
},
137137
{
138138
"@type": "https://openminds.ebrains.eu/core/Affiliation",
139-
"vocab:memberOf": {
139+
"memberOf": {
140140
"@id": "_:003",
141141
"@type": "https://openminds.ebrains.eu/core/Organization",
142142
},
143143
},
144144
],
145-
"vocab:familyName": "Professor",
146-
"vocab:givenName": "A",
145+
"familyName": "Professor",
146+
"givenName": "A",
147147
},
148148
{
149149
"@id": "_:002",
150150
"@type": "https://openminds.ebrains.eu/core/Organization",
151-
"vocab:fullName": "University of This Place",
151+
"fullName": "University of This Place",
152152
},
153153
{
154154
"@id": "_:003",
155155
"@type": "https://openminds.ebrains.eu/core/Organization",
156-
"vocab:fullName": "University of That Place",
156+
"fullName": "University of That Place",
157157
},
158158
],
159159
}
@@ -174,20 +174,20 @@ def test_issue0008():
174174
)
175175
actual = person.to_jsonld(include_empty_properties=False, embed_linked_nodes=False, with_context=True)
176176
expected = {
177-
"@context": {"vocab": "https://openminds.ebrains.eu/vocab/"},
177+
"@context": {"@vocab": "https://openminds.ebrains.eu/vocab/"},
178178
"@id": "_:002",
179179
"@type": "https://openminds.ebrains.eu/core/Person",
180-
"vocab:affiliation": [
180+
"affiliation": [
181181
{
182182
"@type": "https://openminds.ebrains.eu/core/Affiliation",
183-
"vocab:endDate": "2023-09-30",
184-
"vocab:memberOf": {
183+
"endDate": "2023-09-30",
184+
"memberOf": {
185185
"@id": "_:001",
186186
"@type": "https://openminds.ebrains.eu/core/Organization",
187187
},
188188
}
189189
],
190-
"vocab:familyName": "Professor",
191-
"vocab:givenName": "A",
190+
"familyName": "Professor",
191+
"givenName": "A",
192192
}
193193
assert actual == expected

pipeline/translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_type(property):
114114
{
115115
"name": generate_python_name(property["name"]),
116116
"type": get_type(property), # compress using JSON-LD context
117-
"iri": f"vocab:{property['name']}",
117+
"iri": property['name'], # assumes IRI uses standard @vocab
118118
"allow_multiple": property.get("type", "") == "array",
119119
"required": iri in self._schema_payload.get("required", []),
120120
"description": property.get("description", "no description available"),

0 commit comments

Comments
 (0)