From 1524490becf01aedf3dd3d7af23bd7c253225177 Mon Sep 17 00:00:00 2001 From: "TEAM 4.0[bot]" Date: Fri, 21 Jun 2024 23:32:11 +0200 Subject: [PATCH 1/2] [Auto-generated] Update dependencies (#770) ### Update dependencies Automatically created PR from [`ci/dependabot-updates`](https://github.com/emmo-repo/EMMOntoPy/tree/ci/dependabot-updates). The PR is based on the ['CI - Update dependencies PR' workflow](https://SINTEF.github.io/ci-cd/latest/workflows/ci_update_dependencies/) in [SINTEF/ci-cd](https://github.com/SINTEF/ci-cd). #### To do - [ ] Check that the diff is sensible, and that tests and builds pass with the new dependency versions. - [ ] Make sure that the PR is **squash** merged, with a sensible commit message. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Francesca L. Bleken <48128015+francescalb@users.noreply.github.com> Co-authored-by: francescalb Co-authored-by: Jesper Friis --- .github/workflows/ci_workflow.yml | 19 +++++++++++-------- .pre-commit-config.yaml | 2 +- ontopy/excelparser.py | 1 + ontopy/ontology.py | 6 +++--- requirements.txt | 2 +- requirements_dev.txt | 2 +- tools/excel2onto | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 7ed2a9890..435f55a73 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -26,19 +26,22 @@ jobs: pylint_options: "--rcfile=pyproject.toml" pylint_targets: "*.py tools emmopy ontopy" - # safety - # Ignore ID 44715 for now. - # See this NumPy issue for more information: https://github.com/numpy/numpy/issues/19038 - # Also ignore IDs 44716 and 44717 as they are not deemed to be as severe as it is - # laid out in the CVE. - # Remove ignoring 48547 as soon as RDFLib/rdflib#1844 has been fixed and the fix - # has been released. + + # safety-specific settings run_safety: true + # 48547: RDFLib vulnerability: https://pyup.io/vulnerabilities/PVE-2022-48547/48547/ + # 44715-44717: NumPy vulnerabilities: + # https://pyup.io/vulnerabilities/CVE-2021-41495/44715/ + # https://pyup.io/vulnerabilities/CVE-2021-41496/44716/ + # https://pyup.io/vulnerabilities/CVE-2021-34141/44717/ + # 70612: Jinja2 vulnerability. Only used as subdependency for mkdocs++ in tripper. + # https://data.safetycli.com/v/70612/97c/ safety_options: | + --ignore=48547 --ignore=44715 --ignore=44716 --ignore=44717 - --ignore=48547 + --ignore=70612 # Build distribution run_build_package: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d02b5ef8..40817eabf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: name: Blacken - repo: https://github.com/PyCQA/bandit - rev: '1.7.8' + rev: '1.7.9' hooks: - id: bandit args: [-r] diff --git a/ontopy/excelparser.py b/ontopy/excelparser.py index 34504ad66..2b7a8762d 100755 --- a/ontopy/excelparser.py +++ b/ontopy/excelparser.py @@ -643,6 +643,7 @@ def _add_entities( if not altlabel == "nan": labels.update(altlabel.split(";")) # Find column name depending on entitytype + rowheader = "entity_type_not_set" if entitytype is owlready2.ThingClass: rowheader = "subClassOf" # If entitytype is a subclass of owlready2.PropertyClass diff --git a/ontopy/ontology.py b/ontopy/ontology.py index c1952c535..d9731b8e9 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -1112,16 +1112,16 @@ def get_imported_ontologies(self, recursive=False): are also returned. """ - def rec_imported(onto): + def rec_imported(onto, imported): for ontology in onto.imported_ontologies: # pylint: disable=possibly-used-before-assignment if ontology not in imported: imported.add(ontology) - rec_imported(ontology) + rec_imported(ontology, imported) if recursive: imported = set() - rec_imported(self) + rec_imported(self, imported) return list(imported) return self.imported_ontologies diff --git a/requirements.txt b/requirements.txt index 8980a005c..0d97d1d20 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ blessings>=1.7,<2 Cython>=0.29.21,<3.1 defusedxml>=0.7.1,<1 graphviz>=0.16,<0.21 -numpy>=1.19.5,<2 +numpy>=1.19.5,<3 openpyxl>=3.0.9,<3.2 Owlready2>=0.28,!=0.32,!=0.34,<0.44 packaging>=21.0,<25 diff --git a/requirements_dev.txt b/requirements_dev.txt index a8fdb47f1..c278c9e39 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,7 +1,7 @@ pre-commit>=2.21.0,<3; python_version<"3.9" pre-commit~=3.7; python_version>="3.9" pylint~=2.17; python_version<"3.8" -pylint~=3.1; python_version>="3.8" +pylint~=3.2; python_version>="3.8" pytest~=7.4; python_version<"3.8" pytest~=8.2; python_version>="3.8" pytest-cov~=4.1; python_version<"3.8" diff --git a/tools/excel2onto b/tools/excel2onto index 8b144d1a1..a86e68c89 100755 --- a/tools/excel2onto +++ b/tools/excel2onto @@ -71,6 +71,7 @@ def main(argv: list = None): except SystemExit as exc: sys.exit(exc.code) # Exit without traceback on invalid arguments + input_ontology = None if args.update: try: if args.input_ontology: @@ -83,7 +84,6 @@ def main(argv: list = None): "Did not find the output ontology to be updated, " "will fully generate a new one." ) - input_ontology = None else: raise FileNotFoundError( "The output ontology to be updated " From 9b325877f36597c272b492752119048fab09c904 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Sat, 22 Jun 2024 00:01:59 +0200 Subject: [PATCH 2/2] Added test for descriptions (#766) # Description Added test for that entities should be described. We require that a entities should have at least a *elucidation*, *definition* or *conceptualisation*. In addition we require that each of them can max be provided once. Also update ontoconvert to include conceptualisations the `--copy-emmo-annotations` option. Tested against EMMO during development, but no additional EMMO-dependent test has been added to the EMMOntoPy repo. ## Type of change - [ ] Bug fix. - [x] 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 | 85 ++++++++++++++++++++++++++++++++++ ontopy/utils.py | 5 +- tests/test_emmocheck_module.py | 13 ------ tests/tools/test_emmocheck.py | 5 ++ tools/ontoconvert | 2 + 5 files changed, 96 insertions(+), 14 deletions(-) delete mode 100644 tests/test_emmocheck_module.py 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", ] )