Skip to content

Commit

Permalink
Update test_unit_dimension in emmocheck to EMMO 1.0.0-beta5 (#678)
Browse files Browse the repository at this point in the history
# 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
<!-- Put an `x` in the box that applies. -->
- [x] Bug fix.
- [ ] 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 Jan 16, 2024
1 parent 77c3bdc commit 55e1885
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
7 changes: 3 additions & 4 deletions emmopy/emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -206,6 +206,7 @@ def test_unit_dimension(self):
"emmo.DerivedUnit",
"emmo.BaseUnit",
"emmo.UnitSymbol",
"emmo.SIAccepted",
"emmo.SICoherentDerivedUnit",
"emmo.SINonCoherentDerivedUnit",
"emmo.SISpecialUnit",
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
21 changes: 12 additions & 9 deletions ontopy/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion tests/ontopy_tests/test_patch.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}
Expand Down
6 changes: 4 additions & 2 deletions tests/test_emmocheck_module.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tools/ontoconvert
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def main(argv: list = None):
include_imported=include_imported,
debug=verbose,
)

onto.save(
args.output,
format=output_format,
Expand Down

0 comments on commit 55e1885

Please sign in to comment.