From 40cae800b191588b3f18439194840e9dc4612667 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Mon, 1 Aug 2022 22:00:52 +0200 Subject: [PATCH 1/2] Initial fixes --- demo/horizontal/emmo2meta.py | 4 +++- demo/horizontal/step1_generate_metadata.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/demo/horizontal/emmo2meta.py b/demo/horizontal/emmo2meta.py index 7950f4a7e..d2d1721de 100644 --- a/demo/horizontal/emmo2meta.py +++ b/demo/horizontal/emmo2meta.py @@ -136,7 +136,9 @@ def add_class(self, cls): if not self.coll.has(label): uri = self.get_uri(label) dims, props = self.get_properties(cls) - entity = Instance(uri, dims, props, self.get_description(cls)) + entity = Instance.create_metadata( + uri, dims, props, self.get_description(cls) + ) self.coll.add(label, entity) for relation in cls.is_a: if relation is owlready2.Thing: diff --git a/demo/horizontal/step1_generate_metadata.py b/demo/horizontal/step1_generate_metadata.py index 609eaa2bf..b200fd916 100755 --- a/demo/horizontal/step1_generate_metadata.py +++ b/demo/horizontal/step1_generate_metadata.py @@ -26,7 +26,10 @@ # Load our ontology from the vertical case ontopath = os.path.abspath( os.path.join( - os.path.dirname(__file__), "..", "vertical", "usercase_ontology.owl" + # os.path.dirname(__file__), "..", "vertical", "usercase_ontology.owl" + os.path.dirname(__file__), + "..", + "demo.owl", ) ) onto = get_ontology(ontopath) From b8cd8fd11825663b83c598d2126d5ca8c30db572 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Tue, 2 Aug 2022 09:09:50 +0200 Subject: [PATCH 2/2] Updated emmo2meta.py to match changes in EMMO. Support for value restrictions must be added... --- demo/horizontal/emmo2meta.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/demo/horizontal/emmo2meta.py b/demo/horizontal/emmo2meta.py index d2d1721de..9ca36036d 100644 --- a/demo/horizontal/emmo2meta.py +++ b/demo/horizontal/emmo2meta.py @@ -20,7 +20,7 @@ from dlite import Instance, Dimension, Property from ontopy import get_ontology -from ontopy.utils import asstring +from ontopy.utils import asstring, get_label import owlready2 # pylint: disable=wrong-import-order @@ -96,7 +96,7 @@ def get_uuid(uri=None): def get_label(entity): """Returns a label for entity.""" if hasattr(entity, "label"): - return entity.label.first() + return get_label(entity) name = repr(entity) label, _ = re.subn(r"emmo(-[a-z]+)?\.", "", name) return label @@ -116,6 +116,9 @@ def find_label(self, inst): def add(self, entity): """Adds owl entity to collection and returns a reference to the new metadata.""" + # if isinstance(entity, str): + # entity = self.onto[entity] + if entity == owlready2.Thing: raise ValueError(f"invalid entity: {entity}") @@ -125,14 +128,16 @@ def add(self, entity): if isinstance(entity, owlready2.ClassConstruct): return self.add_class_construct(entity) - raise ValueError(f"invalid entity: {entity}") + raise ValueError( + f'invalid entity "{entity}" of class {entity.__class__}' + ) def add_class(self, cls): """Adds owl class `cls` to collection and returns a reference to the new metadata.""" if isinstance(cls, str): cls = self.onto[cls] - label = cls.label.first() + label = get_label(cls) if not self.coll.has(label): uri = self.get_uri(label) dims, props = self.get_properties(cls) @@ -144,9 +149,7 @@ def add_class(self, cls): if relation is owlready2.Thing: pass elif isinstance(relation, owlready2.ThingClass): - self.coll.add_relation( - label, "is_a", relation.label.first() - ) + self.coll.add_relation(label, "is_a", get_label(relation)) self.add_class(relation) elif isinstance(relation, owlready2.Restriction): # Correct this test if EMMO reintroduce isPropertyOf @@ -287,6 +290,12 @@ def add_restriction(self, restriction): vlabel = self.get_label(restriction.value) self.coll.add(label, inst) self.coll.add_relation(label, asstring(restriction.property), vlabel) + print() + print(f"*** {restriction=}") + print(f"*** {restriction.type=}") + print(f"*** {restriction.value=}") + print(f"*** {label=}") + print(f"*** {vlabel=}") if not self.coll.has(vlabel): self.add(restriction.value) return inst @@ -314,7 +323,7 @@ def add_restriction_entity(self): ), ), ] - entity = Instance( + entity = Instance.create_metadata( uri, [], props,