Skip to content

Commit

Permalink
Keep 'ci/dependabot-updates' up-to-date with 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
TEAM4-0 committed Aug 2, 2022
2 parents 96b4dc6 + abbdb8e commit 68100a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
29 changes: 20 additions & 9 deletions demo/horizontal/emmo2meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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}")

Expand All @@ -125,26 +128,28 @@ 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)
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:
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
Expand Down Expand Up @@ -285,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
Expand Down Expand Up @@ -312,7 +323,7 @@ def add_restriction_entity(self):
),
),
]
entity = Instance(
entity = Instance.create_metadata(
uri,
[],
props,
Expand Down
5 changes: 4 additions & 1 deletion demo/horizontal/step1_generate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68100a5

Please sign in to comment.