diff --git a/emmopy/emmocheck.py b/emmopy/emmocheck.py index db177de82..b8ef02c46 100644 --- a/emmopy/emmocheck.py +++ b/emmopy/emmocheck.py @@ -185,6 +185,91 @@ def test_object_property_label(self): class TestFunctionalEMMOConventions(TestEMMOConventions): """Test functional EMMO conventions.""" + def test_description(self): + """Check that all entities have a description. + + A description is either an emmo:elucidation, an + emmo:definition or an emmo:conceptualisation. + + Exceptions include entities from standard w3c vocabularies. + + """ + exceptions = set() + exceptions.update(self.get_config("test_description.exceptions", ())) + props = self.onto.world._props # pylint: disable=protected-access + if ( + "EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9" not in props + or "EMMO_31252f35_c767_4b97_a877_1235076c3e13" not in props + or "EMMO_70fe84ff_99b6_4206_a9fc_9a8931836d84" not in props + ): + self.fail( + "ontology has no description (emmo:elucidation, " + "emmo:definition or emmo:conceptualisation)" + ) + for entity in self.onto.classes(self.check_imported): + + # Skip concepts from exceptions and common w3c vocabularies + vocabs = "owl.", "0.1.", "bibo.", "core.", "terms.", "vann." + r = repr(entity) + if r in exceptions or any(r.startswith(v) for v in vocabs): + continue + + label = str(get_label(entity)) + with self.subTest(entity=entity, label=label): + self.assertTrue( + hasattr(entity, "elucidation"), + msg=f"{label} has no emmo:elucidation", + ) + self.assertTrue( + hasattr(entity, "definition"), + msg=f"{label} has no emmo:definition", + ) + self.assertTrue( + hasattr(entity, "conceptualisation"), + msg=f"{label} has no emmo:conceptualisation", + ) + self.assertTrue( + len(entity.elucidation) + + len(entity.definition) + + len(entity.conceptualisation) + >= 1, + msg="missing description (emmo:elucidation, " + f"emmo:deinition and/or emmo:conceptualidation): {label}", + ) + self.assertTrue( + len( + [ + s + for s in entity.elucidation + if not hasattr(s, "lang") or s.lang == "en" + ] + ) + < 2, + msg=f"more than one emmo:elucidation for {label}", + ) + self.assertTrue( + len( + [ + s + for s in entity.definition + if not hasattr(s, "lang") or s.lang == "en" + ] + ) + < 2, + msg=f"more than one emmo:definition for {label}", + ) + self.assertTrue( + len( + [ + s + for s in entity.conceptualisation + if not hasattr(s, "lang") or s.lang == "en" + ] + ) + < 2, + msg=f"more than one emmo:conceptualisation for {label}", + ) + def test_unit_dimension(self): """Check that all measurement units have a physical dimension. diff --git a/ontopy/utils.py b/ontopy/utils.py index aba32af77..fdd73ff61 100644 --- a/ontopy/utils.py +++ b/ontopy/utils.py @@ -888,8 +888,11 @@ def copy_annotation(onto, src, dst): """ if onto.world[src]: src = onto.world[src] - else: + elif src in onto: src = onto[src] + else: + warnings.warn(f"no such annotation: '{src}' Skip copy annotation...") + return if onto.world[dst]: dst = onto.world[dst] diff --git a/tests/test_emmocheck_module.py b/tests/test_emmocheck_module.py deleted file mode 100644 index 2ca4c417c..000000000 --- a/tests/test_emmocheck_module.py +++ /dev/null @@ -1,13 +0,0 @@ -from emmopy.emmocheck import 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/f282769978af9fda7e1c55d1adeeb0ef9e24fc48/emmo.ttl", - ] -) - -assert status == 0 diff --git a/tests/tools/test_emmocheck.py b/tests/tools/test_emmocheck.py index f134a5e43..e9ed440c4 100644 --- a/tests/tools/test_emmocheck.py +++ b/tests/tools/test_emmocheck.py @@ -15,4 +15,9 @@ def test_run() -> None: test_file = ontodir / "models.ttl" emmocheck = get_tool_module("emmocheck") + # The main() method will raise an exception on error, so it is + # sufficient to just call it here + + emmocheck.main(["--skip=test_description", str(test_file)]) + emmocheck.main([str(test_file)]) diff --git a/tools/ontoconvert b/tools/ontoconvert index 3e1e6a6fb..8d9e0dc69 100755 --- a/tools/ontoconvert +++ b/tools/ontoconvert @@ -244,6 +244,8 @@ def main(argv: list = None): "-->http://www.w3.org/2000/01/rdf-schema#label", "elucidation-->http://www.w3.org/2000/01/rdf-schema#comment", "definition-->http://www.w3.org/2000/01/rdf-schema#comment", + "conceptualisation" + "-->http://www.w3.org/2000/01/rdf-schema#comment", "comment-->http://www.w3.org/2000/01/rdf-schema#comment", ] )