Skip to content

Commit

Permalink
Merge branch 'base'
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnelson-nist committed Nov 6, 2024
2 parents 6f64a1c + 443ced0 commit c6d12be
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*.swp
.*.done.log
.venv-pre-commit
_*.*
__pycache__
venv
9 changes: 9 additions & 0 deletions ontology/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ ttl_basenames := $(wildcard uco-*.ttl)
all: \
catalog-v001.xml

.pytest.done.log: \
$(top_srcdir)/.venv.done.log \
$(ttl_basenames)
source $(top_srcdir)/venv/bin/activate \
&& pytest \
--log-level=DEBUG
touch $@

catalog-v001.xml: \
$(top_srcdir)/.venv.done.log \
$(top_srcdir)/etc/domain_directories.tsv \
Expand All @@ -43,6 +51,7 @@ catalog-v001.xml: \
mv _$@ $@

check: \
.pytest.done.log \
catalog-v001.xml

clean:
Expand Down
71 changes: 71 additions & 0 deletions ontology/test_disjointedness_symmetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to title 17 Section 105 of the
# United States Code this software is not subject to copyright
# protection and is in the public domain. NIST assumes no
# responsibility whatsoever for its use by other parties, and makes
# no guarantees, expressed or implied, about its quality,
# reliability, or any other characteristic.
#
# We would appreciate acknowledgement if the software is used.

import logging
from pathlib import Path

from rdflib import OWL, Graph, URIRef

NS_OWL = OWL

srcdir = Path(__file__).parent


def test_disjointedness_symmetry() -> None:
"""
This test confirms that owl:disjointWith statements are entered specified in both directions. (While the effect of a disjointedness assertion does not require this symmetric entry, the extra explicitness is meant to assist with modeling comprehension.)
"""
# The expected-set is all owl:disjointWith statements backwards and forwards.
# This test will derive the expected set from the computed set.
expected: set[tuple[URIRef, URIRef]] = set()
computed: set[tuple[URIRef, URIRef]] = set()

profile_graph = Graph()
for filepath in (srcdir).iterdir():
if filepath.name.startswith("_"):
# Skip temporary build artifacts.
continue
if filepath.name.startswith("."):
# Skip quality control test artifacts.
continue
if filepath.name.endswith(".ttl"):
logging.debug("Loading profile graph %r.", filepath)
profile_graph.parse(filepath)
logging.debug("len(profile_graph) = %d.", len(profile_graph))

for triple in profile_graph.triples((None, NS_OWL.disjointWith, None)):
assert isinstance(triple[0], URIRef)
assert isinstance(triple[2], URIRef)
computed.add((triple[0], triple[2]))

for pair in computed:
expected.add(pair)
expected.add((pair[1], pair[0]))

try:
assert expected == computed
except AssertionError:
lines_to_copy_paste = "\n".join(
(
"<%s> <%s> <%s> ." % (x[0], NS_OWL.disjointWith, x[1])
for x in (expected - computed)
)
)
logging.info(
"This can be addressed by copying the following lines into uco-gufo.ttl. Automated format-checking should handle syntactically normalizing them.\n%s"
% lines_to_copy_paste
)
raise

0 comments on commit c6d12be

Please sign in to comment.