Skip to content

Commit

Permalink
Added test for descriptions (#766)
Browse files Browse the repository at this point in the history
# 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
<!-- Put an `x` in the boxes that apply. You can also fill these out
after creating the PR. -->

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
<!-- Additional comments here, including clarifications on checklist if
applicable. -->

---------

Co-authored-by: Francesca L. Bleken <[email protected]>
  • Loading branch information
jesper-friis and francescalb authored Jun 21, 2024
1 parent 1524490 commit 9b32587
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 14 deletions.
85 changes: 85 additions & 0 deletions emmopy/emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion ontopy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 0 additions & 13 deletions tests/test_emmocheck_module.py

This file was deleted.

5 changes: 5 additions & 0 deletions tests/tools/test_emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
2 changes: 2 additions & 0 deletions tools/ontoconvert
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
)
Expand Down

0 comments on commit 9b32587

Please sign in to comment.