Skip to content

Commit

Permalink
Test inverse-functional nature of core:hasFacet
Browse files Browse the repository at this point in the history
A follow-on patch will regenerate Make-managed files.

References:
* #379

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
  • Loading branch information
ajnelson-nist committed Aug 19, 2022
1 parent da5a1f3 commit 70ba689
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ontology/uco/core/core.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,29 @@ core:hasFacet
rdfs:range core:Facet ;
.

core:hasFacet-shape
a sh:PropertyShape ;
sh:path core:hasFacet ;
sh:sparql [
a sh:SPARQLConstraint ;
sh:message "hasFacet must not be used to link two objects to one Facet."@en ;
sh:select """
PREFIX core: <https://ontology.unifiedcyberontology.org/uco/core/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT $this ?value
WHERE {
?value core:hasFacet $this .
?nOtherValue core:hasFacet $this .
FILTER ( ?value != ?nOtherValue )
FILTER NOT EXISTS {
?value owl:sameAs|^owl:sameAs ?nOtherValue .
}
}
""" ;
] ;
sh:targetObjectsOf core:hasFacet ;
.

core:id
a owl:DatatypeProperty ;
rdfs:label "id"@en ;
Expand Down
4 changes: 4 additions & 0 deletions tests/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ all: \
action_result_PASS_validation.ttl \
co_PASS_validation.ttl \
co_XFAIL_validation.ttl \
has_facet_inverse_functional_PASS_validation.ttl \
has_facet_inverse_functional_XFAIL_validation.ttl \
hash_PASS_validation.ttl \
hash_XFAIL_validation.ttl \
location_PASS_validation.ttl \
Expand Down Expand Up @@ -84,6 +86,8 @@ check: \
action_result_PASS_validation.ttl \
co_PASS_validation.ttl \
co_XFAIL_validation.ttl \
has_facet_inverse_functional_PASS_validation.ttl \
has_facet_inverse_functional_XFAIL_validation.ttl \
hash_PASS_validation.ttl \
hash_XFAIL_validation.ttl \
location_PASS_validation.ttl \
Expand Down
30 changes: 30 additions & 0 deletions tests/examples/has_facet_inverse_functional_PASS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"@context": {
"kb": "http://example.org/kb/",
"core": "https://ontology.unifiedcyberontology.org/uco/core/",
"owl": "http://www.w3.org/2002/07/owl#"
},
"@graph": [
{
"@id": "kb:facet-1",
"@type": "core:Facet"
},
{
"@id": "kb:object-1",
"@type": "core:UcoObject",
"core:hasFacet": {
"@id": "kb:facet-1"
},
"owl:sameAs": {
"@id": "kb:object-2"
}
},
{
"@id": "kb:object-2",
"@type": "core:UcoObject",
"core:hasFacet": {
"@id": "kb:facet-1"
}
}
]
}
26 changes: 26 additions & 0 deletions tests/examples/has_facet_inverse_functional_XFAIL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"@context": {
"kb": "http://example.org/kb/",
"core": "https://ontology.unifiedcyberontology.org/uco/core/"
},
"@graph": [
{
"@id": "kb:facet-1",
"@type": "core:Facet"
},
{
"@id": "kb:object-1",
"@type": "core:UcoObject",
"core:hasFacet": {
"@id": "kb:facet-1"
}
},
{
"@id": "kb:object-2",
"@type": "core:UcoObject",
"core:hasFacet": {
"@id": "kb:facet-1"
}
}
]
}
15 changes: 15 additions & 0 deletions tests/examples/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ def test_action_result_PASS_validation():
g = load_validation_graph("action_result_PASS_validation.ttl", True)
assert isinstance(g, rdflib.Graph)

def test_has_facet_inverse_functional_PASS() -> None:
confirm_validation_results(
"has_facet_inverse_functional_PASS_validation.ttl",
True
)

def test_has_facet_inverse_functional_XFAIL() -> None:
confirm_validation_results(
"has_facet_inverse_functional_XFAIL_validation.ttl",
False,
expected_focus_node_severities={
("http://example.org/kb/facet-1", str(NS_SH.Violation))
}
)

def test_hash_PASS() -> None:
g = load_validation_graph("hash_PASS_validation.ttl", True)
assert isinstance(g, rdflib.Graph)
Expand Down

0 comments on commit 70ba689

Please sign in to comment.