-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
*.swp | ||
.*.done.log | ||
.venv-pre-commit | ||
_*.* | ||
__pycache__ | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |