Skip to content

Commit e60e9b4

Browse files
committed
Use enums for license, content-type and graph structure instances
1 parent cbdd53b commit e60e9b4

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

build.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616

1717
terms_as_enums = True
18+
licenses_as_enums = True
19+
content_types_as_enums = True
20+
graph_structures_as_enums = True
1821

1922
print("********************************************************")
2023
print(f"Triggering the generation of LinkML models for openMINDS")
@@ -69,10 +72,17 @@
6972
)
7073
module = relative_path.split(os.path.sep)[0]
7174
instances_for_version = instances.get(schema_version, None)
72-
if (
73-
terms_as_enums
74-
and instances_for_version
75-
and "controlled" in schema_file_path
75+
if instances_for_version and any(
76+
[
77+
terms_as_enums and "controlled" in schema_file_path,
78+
licenses_as_enums and "license" in schema_file_path,
79+
content_types_as_enums and "contentType" in schema_file_path,
80+
graph_structures_as_enums
81+
and (
82+
"parcellationEntity" in schema_file_path
83+
or "commonCoordinateSpace" in schema_file_path
84+
),
85+
]
7686
):
7787
LinkMLEnumBuilder(
7888
schema_file_path,
@@ -144,7 +154,7 @@
144154
},
145155
"default_prefix": "omi",
146156
"imports": ["linkml:types"],
147-
"slots": slots
157+
"slots": slots,
148158
}
149159
with open(
150160
os.path.join("target", "schemas", schema_version, f"slots.yaml"),
@@ -172,21 +182,18 @@
172182
"repr": "str",
173183
"base": "str",
174184
"description": "A correctly formatted e-mail address",
175-
"exact_mappings": ["schema:email"]
185+
"exact_mappings": ["schema:email"],
176186
},
177187
"ECMA262": {
178188
"uri": "linkml:ECMA262",
179189
"repr": "str",
180190
"base": "str",
181-
"description": "Text which is syntactically valid ECMAScript code"
182-
}
183-
184-
}
191+
"description": "Text which is syntactically valid ECMAScript code",
192+
},
193+
},
185194
}
186195
with open(
187-
os.path.join(
188-
"target", "schemas", schema_version, f"types.yaml"
189-
),
196+
os.path.join("target", "schemas", schema_version, f"types.yaml"),
190197
"w",
191198
) as fp:
192199
yaml.dump(types_metadata, fp, sort_keys=False)

pipeline/translator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def _resolve_number_property(self, property) -> Dict:
5555
elif property["type"] == "float":
5656
number_property_spec = {"range": "float"}
5757
elif property["type"] == "number": # or perhaps define a Number type
58-
number_property_spec = {"any_of": [{"range": "integer"}, {"range": "float"}]}
58+
number_property_spec = {
59+
"any_of": [{"range": "integer"}, {"range": "float"}]
60+
}
5961
else:
6062
raise ValueError(property["type"])
6163
# if "multipleOf" in property and property["multipleOf"]:
@@ -277,6 +279,9 @@ def build_enum(instance):
277279
"meaning"
278280
return enum
279281

282+
def get_instance_name(instance):
283+
return instance.get("name", instance.get("shortName"))
284+
280285
instances_payload = self.instances[self._schema_payload["_type"]]
281286
self._translated_schema = {
282287
"enum_uri": self._schema_payload["_type"],
@@ -285,7 +290,8 @@ def build_enum(instance):
285290
if "description" in self._schema_payload:
286291
self._translated_schema["description"] = self._schema_payload["description"]
287292
self._translated_schema["permissible_values"] = {
288-
instance["name"]: build_enum(instance) for instance in instances_payload
293+
get_instance_name(instance): build_enum(instance)
294+
for instance in instances_payload
289295
}
290296

291297
def build(self):

0 commit comments

Comments
 (0)