From 55e1885fac9ebe50c87bea07937732105a1ca0c6 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Tue, 16 Jan 2024 10:52:56 +0100 Subject: [PATCH] Update test_unit_dimension in emmocheck to EMMO 1.0.0-beta5 (#678) # Description Update test_unit_dimension in emmocheck to EMMO 1.0.0-beta5. A test for this PR is added in PR #679. ## Type of change - [x] Bug fix. - [ ] New feature. - [ ] Documentation update. - [ ] Test update. ## Checklist This checklist can be used as a help for the reviewer. - [ ] Is the code easy to read and understand? - [ ] Are comments for humans to read, not computers to disregard? - [ ] Does a new feature has an accompanying new test (in the CI or unit testing schemes)? - [ ] Has the documentation been updated as necessary? - [ ] Does this close the issue? - [ ] Is the change limited to the issue? - [ ] Are errors handled for all outcomes? - [ ] Does the new feature provide new restrictions on dependencies, and if so is this documented? ## Comments --------- Co-authored-by: Francesca L. Bleken <48128015+francescalb@users.noreply.github.com> --- emmopy/emmocheck.py | 7 +++---- ontopy/ontology.py | 2 +- ontopy/patch.py | 21 ++++++++++++--------- tests/ontopy_tests/test_patch.py | 21 ++++++++++++++++++++- tests/test_emmocheck_module.py | 6 ++++-- tools/ontoconvert | 1 + 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/emmopy/emmocheck.py b/emmopy/emmocheck.py index 1e09ed083..1df5ca8b7 100644 --- a/emmopy/emmocheck.py +++ b/emmopy/emmocheck.py @@ -126,7 +126,7 @@ def test_class_label(self): for cls in self.onto.classes(self.check_imported): for label in cls.label + getattr(cls, "prefLabel", []): - if label not in exceptions: + if str(label) not in exceptions: with self.subTest(entity=cls, label=label): self.assertTrue(label.isidentifier()) self.assertTrue(label[0].isupper()) @@ -206,6 +206,7 @@ def test_unit_dimension(self): "emmo.DerivedUnit", "emmo.BaseUnit", "emmo.UnitSymbol", + "emmo.SIAccepted", "emmo.SICoherentDerivedUnit", "emmo.SINonCoherentDerivedUnit", "emmo.SISpecialUnit", @@ -219,9 +220,7 @@ def test_unit_dimension(self): if not hasattr(self.onto, "MeasurementUnit"): return exceptions.update(self.get_config("test_unit_dimension.exceptions", ())) - regex = re.compile( - r"^(emmo|metrology).hasPhysicalDimension.some\(.*\)$" - ) + regex = re.compile(r"^(emmo|metrology).hasDimensionString.value\(.*\)$") classes = set(self.onto.classes(self.check_imported)) for cls in self.onto.MeasurementUnit.descendants(): if not self.check_imported and cls not in classes: diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 9940add0f..b4b416d5a 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -118,7 +118,7 @@ def get_ontology( ) elif base_iri == "emmo-development": base_iri = ( - "https://emmo-repo.github.io/versions/1.0.0-beta4/" + "https://emmo-repo.github.io/versions/1.0.0-beta5/" "emmo-inferred.ttl" ) diff --git a/ontopy/patch.py b/ontopy/patch.py index 23e28afb2..61c68e50c 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -187,15 +187,18 @@ def get_indirect_is_a(self, skip_classes=True): """ subclass_relations = set() for entity in reversed(self.mro()): - if hasattr(entity, "is_a"): - if skip_classes: - subclass_relations.update( - _ - for _ in entity.is_a - if not isinstance(_, owlready2.ThingClass) - ) - else: - subclass_relations.update(entity.is_a) + for attr in "is_a", "equivalent_to": + if hasattr(entity, attr): + lst = getattr(entity, attr) + if skip_classes: + subclass_relations.update( + r + for r in lst + if not isinstance(r, owlready2.ThingClass) + ) + else: + subclass_relations.update(lst) + subclass_relations.update(self.is_a) return subclass_relations diff --git a/tests/ontopy_tests/test_patch.py b/tests/ontopy_tests/test_patch.py index 8ce2b253b..36337b2ca 100644 --- a/tests/ontopy_tests/test_patch.py +++ b/tests/ontopy_tests/test_patch.py @@ -1,11 +1,11 @@ """Tests Owlready2 patches implemented in ontopy/patch.py """ +import re import pytest from ontopy import get_ontology - from owlready2 import owl, Inverse from utilities import setassert @@ -87,6 +87,25 @@ def test_get_by_label_onto(emmo: "Ontology") -> None: ) # Check that wikipediaReference can be acceses as attribute +def test_get_indirect_is_a() -> None: + import re + from ontopy import get_ontology + + emmo = get_ontology("emmo-development").load() + assert any( + re.match("^emmo.*\.hasDimensionString.value(.*)$", str(e)) + for e in emmo.MicroPascal.get_indirect_is_a() + ) + assert all( + re.match("^emmo.*\.Item$", str(e)) is None + for e in emmo.MicroPascal.get_indirect_is_a() + ) + assert any( + re.match("^emmo.*\.Item$", str(e)) + for e in emmo.MicroPascal.get_indirect_is_a(skip_classes=False) + ) + + # TODO: Fix disjoint_with(). # It seems not to take into account disjoint unions. # assert set(emmo.Collection.disjoint_with()) == {emmo.Item} diff --git a/tests/test_emmocheck_module.py b/tests/test_emmocheck_module.py index 346b930be..2ca4c417c 100644 --- a/tests/test_emmocheck_module.py +++ b/tests/test_emmocheck_module.py @@ -1,11 +1,13 @@ from emmopy.emmocheck import main -main( +status = main( argv=[ "--url-from-catalog", "--check-imported", # Test against a specific commit of EMMO 1.0.0-beta5 - "https://raw.githubusercontent.com/emmo-repo/EMMO/3b93e2c9c45ab8d9882d2d6385276ff905095798/emmo.ttl", + "https://raw.githubusercontent.com/emmo-repo/EMMO/f282769978af9fda7e1c55d1adeeb0ef9e24fc48/emmo.ttl", ] ) + +assert status == 0 diff --git a/tools/ontoconvert b/tools/ontoconvert index b184b5b23..8c23570b4 100755 --- a/tools/ontoconvert +++ b/tools/ontoconvert @@ -203,6 +203,7 @@ def main(argv: list = None): include_imported=include_imported, debug=verbose, ) + onto.save( args.output, format=output_format,