Skip to content

Commit

Permalink
Warn about key-uniqueness enforcement to types:Dictionary
Browse files Browse the repository at this point in the history
A follow-on patch will regenerate Make-managed files.

References:
* #602

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
  • Loading branch information
ajnelson-nist committed May 7, 2024
1 parent 27ca6b0 commit c349b32
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ontology/uco/types/types.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ types:Dictionary
rdfs:subClassOf core:UcoInherentCharacterizationThing ;
rdfs:label "Dictionary"@en ;
rdfs:comment "A dictionary is list of (term/key, value) pairs with each term/key existing no more than once."@en ;
rdfs:seeAlso [
a sh:NodeShape ;
rdfs:comment "This anonymous shape is attached to types:Dictionary with rdfs:seeAlso in order to associate a warning-severity SPARQL-based shape, that will only be necessary as an independent shape until UCO 2.0.0."@en ;
sh:severity sh:Warning ;
sh:sparql [
a sh:SPARQLConstraint ;
sh:message "A key in a dictionary can appear no more than once."@en ;
sh:select """
PREFIX types: <https://ontology.unifiedcyberontology.org/uco/types/>
SELECT $this ?value
WHERE {
$this
types:entry/types:key ?value ;
.
}
GROUP BY ?value
HAVING (COUNT(?value) > 1)
""" ;
] ;
sh:targetClass types:Dictionary ;
] ;
sh:property [
sh:class types:DictionaryEntry ;
sh:minCount "1"^^xsd:integer ;
Expand Down
2 changes: 2 additions & 0 deletions tests/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ all: \
configuration_setting_XFAIL_validation.ttl \
database_records_PASS_validation.ttl \
database_records_XFAIL_validation.ttl \
dictionary_PASS_validation.ttl \
event_XFAIL_validation.ttl \
file_url_PASS_validation.ttl \
has_facet_inverse_functional_PASS_validation.ttl \
Expand Down Expand Up @@ -98,6 +99,7 @@ check: \
configuration_setting_XFAIL_validation.ttl \
database_records_PASS_validation.ttl \
database_records_XFAIL_validation.ttl \
dictionary_PASS_validation.ttl \
event_XFAIL_validation.ttl \
file_url_PASS_validation.ttl \
has_facet_inverse_functional_PASS_validation.ttl \
Expand Down
83 changes: 83 additions & 0 deletions tests/examples/dictionary_PASS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"@context": {
"kb": "http://example.org/kb/",
"types": "https://ontology.unifiedcyberontology.org/uco/types/"
},
"@graph": [
{
"@id": "kb:Dictionary-eaded28e-0bf8-4df1-aee8-84d22c09702c",
"@type": "types:Dictionary",
"types:entry": [
{
"@id": "kb:DictionaryEntry-314212eb-39c4-4bf3-be3a-f07c38f0eae8"
},
{
"@id": "kb:DictionaryEntry-9ec24a1a-7e99-41c9-ba7d-9d23f11babb4"
}
]
},
{
"@id": "kb:DictionaryEntry-314212eb-39c4-4bf3-be3a-f07c38f0eae8",
"@type": "types:DictionaryEntry",
"types:key": "x",
"types:value": "1"
},
{
"@id": "kb:DictionaryEntry-9ec24a1a-7e99-41c9-ba7d-9d23f11babb4",
"@type": "types:DictionaryEntry",
"types:key": "y",
"types:value": "2"
},
{
"@id": "kb:Dictionary-a8e5e8e1-b3de-4ac4-99dd-e36f96beea4d",
"@type": "types:Dictionary",
"rdfs": "This dictionary will trigger a warning from having two entries keyed with value 'x'.",
"types:entry": [
{
"@id": "kb:DictionaryEntry-55786f64-534d-4e8c-8a64-616f708ea4d3"
},
{
"@id": "kb:DictionaryEntry-d1a83c3d-cbe6-40b0-bb26-3527c47a01d8"
}
]
},
{
"@id": "kb:DictionaryEntry-55786f64-534d-4e8c-8a64-616f708ea4d3",
"@type": "types:DictionaryEntry",
"types:key": "x",
"types:value": "1"
},
{
"@id": "kb:DictionaryEntry-d1a83c3d-cbe6-40b0-bb26-3527c47a01d8",
"@type": "types:DictionaryEntry",
"types:key": "x",
"types:value": "2"
},
{
"@id": "kb:Dictionary-e9adf6c1-0287-4290-95a9-c94a128d7ff6",

"@type": "types:Dictionary",
"rdfs": "This dictionary will trigger a warning from having two entries keyed with value 'x'.",
"types:entry": [
{
"@id": "kb:DictionaryEntry-20431f00-64a3-4c0f-94a4-1eb09f8a6b6a"
},
{
"@id": "kb:DictionaryEntry-f187ee7f-12fb-4580-966d-47bf1afd4975"
}
]
},
{
"@id": "kb:DictionaryEntry-20431f00-64a3-4c0f-94a4-1eb09f8a6b6a",
"@type": "types:DictionaryEntry",
"types:key": "x",
"types:value": "1"
},
{
"@id": "kb:DictionaryEntry-f187ee7f-12fb-4580-966d-47bf1afd4975",
"@type": "types:DictionaryEntry",
"types:key": "x",
"types:value": "1"
}
]
}
10 changes: 10 additions & 0 deletions tests/examples/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ def test_database_records_XFAIL() -> None:
}
)

def test_dictionary_PASS() -> None:
confirm_validation_results(
"dictionary_PASS_validation.ttl",
True,
expected_focus_node_severities={
("http://example.org/kb/Dictionary-a8e5e8e1-b3de-4ac4-99dd-e36f96beea4d", str(NS_SH.Warning)),
('http://example.org/kb/Dictionary-e9adf6c1-0287-4290-95a9-c94a128d7ff6', str(NS_SH.Warning)),
}
)

def test_event_XFAIL() -> None:
confirm_validation_results(
"event_XFAIL_validation.ttl",
Expand Down

0 comments on commit c349b32

Please sign in to comment.