Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 629: Revise vocabulary pattern #630

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions ontology/uco/core/core.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ core:ObjectStatusVocab
owl:equivalentClass [
a rdfs:Datatype ;
owl:oneOf (
"Draft"^^core:ObjectStatusVocab
"Final"^^core:ObjectStatusVocab
"Deprecated"^^core:ObjectStatusVocab
"Draft"
"Final"
"Deprecated"
) ;
] ;
.
Expand Down Expand Up @@ -443,6 +443,17 @@ core:UcoObject
sh:nodeKind sh:Literal ;
sh:path core:modifiedTime ;
] ,
[
sh:datatype xsd:string ;
sh:in (
"Draft"
"Final"
"Deprecated"
) ;
sh:maxCount "1"^^xsd:integer ;
sh:nodeKind sh:Literal ;
sh:path core:objectStatus ;
] ,
[
sh:datatype xsd:string ;
sh:maxCount "1"^^xsd:integer ;
Expand All @@ -464,17 +475,6 @@ core:UcoObject
sh:datatype xsd:string ;
sh:nodeKind sh:Literal ;
sh:path core:tag ;
] ,
[
sh:datatype core:ObjectStatusVocab ;
sh:in (
"Draft"^^core:ObjectStatusVocab
"Final"^^core:ObjectStatusVocab
"Deprecated"^^core:ObjectStatusVocab
) ;
sh:maxCount "1"^^xsd:integer ;
sh:nodeKind sh:Literal ;
sh:path core:objectStatus ;
]
;
sh:targetClass core:UcoObject ;
Expand Down
62 changes: 25 additions & 37 deletions ontology/uco/types/types.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ types:Hash
rdfs:subClassOf core:UcoInherentCharacterizationThing ;
rdfs:label "Hash"@en ;
rdfs:comment "A hash is a grouping of characteristics unique to the result of applying a mathematical algorithm that maps data of arbitrary size to a bit string (the 'hash') and is a one-way function, that is, a function which is practically infeasible to invert. This is commonly used for integrity checking of data. [based on https://en.wikipedia.org/wiki/Cryptographic_hash_function]"@en ;
rdfs:seeAlso types:hashMethod-objects-in-shape ;
sh:property
[
sh:datatype xsd:hexBinary ;
Expand All @@ -144,49 +145,15 @@ types:Hash
sh:path types:hashValue ;
] ,
[
sh:datatype vocabulary:HashNameVocab ;
sh:message "Value is outside the default vocabulary HashNameVocab." ;
sh:datatype xsd:string ;
sh:message "As of UCO 1.4.0, the datatype to use for types:hashMethod should be xsd:string. Not using xsd:string will be an error in UCO 2.0.0." ;
sh:path types:hashMethod ;
sh:severity sh:Info ;
sh:severity sh:Warning ;
] ,
[
sh:maxCount "1"^^xsd:integer ;
sh:minCount "1"^^xsd:integer ;
sh:nodeKind sh:Literal ;
sh:or (
[
sh:datatype vocabulary:HashNameVocab ;
]
[
sh:datatype xsd:string ;
]
) ;
sh:path types:hashMethod ;
] ,
[
sh:message "Value is not member of the vocabulary HashNameVocab." ;
sh:or (
[
sh:datatype vocabulary:HashNameVocab ;
sh:in (
"MD5"^^vocabulary:HashNameVocab
"MD6"^^vocabulary:HashNameVocab
"SHA1"^^vocabulary:HashNameVocab
"SHA224"^^vocabulary:HashNameVocab
"SHA256"^^vocabulary:HashNameVocab
"SHA3-224"^^vocabulary:HashNameVocab
"SHA3-256"^^vocabulary:HashNameVocab
"SHA3-384"^^vocabulary:HashNameVocab
"SHA3-512"^^vocabulary:HashNameVocab
"SHA384"^^vocabulary:HashNameVocab
"SHA512"^^vocabulary:HashNameVocab
"SSDEEP"^^vocabulary:HashNameVocab
) ;
]
[
sh:datatype xsd:string ;
]
) ;
sh:path types:hashMethod ;
]
;
Expand Down Expand Up @@ -339,6 +306,27 @@ types:hashMethod
] ;
.

types:hashMethod-objects-in-shape
a sh:NodeShape ;
sh:in (
"MD5"
"MD6"
"SHA1"
"SHA224"
"SHA256"
"SHA3-224"
"SHA3-256"
"SHA3-384"
"SHA3-512"
"SHA384"
"SHA512"
"SSDEEP"
) ;
sh:message "Value is not member of the vocabulary HashNameVocab." ;
sh:severity sh:Info ;
sh:targetObjectsOf types:hashMethod ;
.

types:hashValue
a owl:DatatypeProperty ;
rdfs:label "hashValue"@en ;
Expand Down
24 changes: 12 additions & 12 deletions ontology/uco/vocabulary/vocabulary.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -593,18 +593,18 @@ vocabulary:HashNameVocab
owl:equivalentClass [
a rdfs:Datatype ;
owl:oneOf (
"MD5"^^vocabulary:HashNameVocab
"MD6"^^vocabulary:HashNameVocab
"SHA1"^^vocabulary:HashNameVocab
"SHA224"^^vocabulary:HashNameVocab
"SHA256"^^vocabulary:HashNameVocab
"SHA3-224"^^vocabulary:HashNameVocab
"SHA3-256"^^vocabulary:HashNameVocab
"SHA3-384"^^vocabulary:HashNameVocab
"SHA3-512"^^vocabulary:HashNameVocab
"SHA384"^^vocabulary:HashNameVocab
"SHA512"^^vocabulary:HashNameVocab
"SSDEEP"^^vocabulary:HashNameVocab
"MD5"
"MD6"
"SHA1"
"SHA224"
"SHA256"
"SHA3-224"
"SHA3-256"
"SHA3-384"
"SHA3-512"
"SHA384"
"SHA512"
"SSDEEP"
) ;
] ;
.
Expand Down
32 changes: 32 additions & 0 deletions tests/examples/hash_PASS.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
{
"@context": {
"kb": "http://example.org/kb/",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"types": "https://ontology.unifiedcyberontology.org/uco/types/",
"vocabulary": "https://ontology.unifiedcyberontology.org/uco/vocabulary/",
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@graph": [
{
"@id": "kb:hash-04dcd1dc-6920-4977-a898-e242870249a4",
"@type": "types:Hash",
"rdfs:comment": "Should trigger sh:Info from the hashMethod literal not having its value be in the HashNameVocab vocabulary.",
"types:hashMethod": "CUSTOM_hash",
"types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "a39a3ee5e6b4b0d3255bfef95601890afd80709d"
}
},
{
"@id": "kb:hash-af4b0c85-b042-4e2d-a213-210b3d7f115c",
"@type": "types:Hash",
"rdfs:comment": "Should trigger sh:Info from the hashMethod literal not being a member of the vocabulary. ('SHA1' is in the vocabulary; 'SHA-1' isn't.)",
"types:hashMethod": "SHA-1",
"types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
},
{
"@id": "kb:hash-b7eca8de-142d-4aa9-b546-0796a268afa4",
"@type": "types:Hash",
"rdfs:comment": "Should trigger an sh:Info from the hashMethod value not having its (literal-)value in the HashNameVocab vocabulary, and also not being an xsd:string.",
"types:hashMethod": {
"@type": "vocabulary:HashNameVocab",
"@value": "SHA1"
Expand All @@ -17,6 +39,16 @@
"@type": "xsd:hexBinary",
"@value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
},
{
"@id": "kb:hash-f46c714f-559a-4325-bf8a-4ef60c92c771",
"@type": "types:Hash",
"rdfs:comment": "This should trigger an sh:Warning from the hashMethod value not being a string, and not being in the HashNameVocab vocabulary.",
"types:hashMethod": 1,
"types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
}
]
}
70 changes: 70 additions & 0 deletions tests/examples/hash_PASS_validation.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,80 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix types: <https://ontology.unifiedcyberontology.org/uco/types/> .
@prefix vocabulary: <https://ontology.unifiedcyberontology.org/uco/vocabulary/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

[]
a sh:ValidationReport ;
sh:conforms "true"^^xsd:boolean ;
sh:result
[
a sh:ValidationResult ;
sh:focusNode "1"^^xsd:integer ;
sh:resultMessage "Value is not member of the vocabulary HashNameVocab." ;
sh:resultSeverity sh:Info ;
sh:sourceConstraintComponent sh:InConstraintComponent ;
sh:sourceShape types:hashMethod-objects-in-shape ;
sh:value "1"^^xsd:integer ;
] ,
[
a sh:ValidationResult ;
sh:focusNode "CUSTOM_hash" ;
sh:resultMessage "Value is not member of the vocabulary HashNameVocab." ;
sh:resultSeverity sh:Info ;
sh:sourceConstraintComponent sh:InConstraintComponent ;
sh:sourceShape types:hashMethod-objects-in-shape ;
sh:value "CUSTOM_hash" ;
] ,
[
a sh:ValidationResult ;
sh:focusNode "SHA-1" ;
sh:resultMessage "Value is not member of the vocabulary HashNameVocab." ;
sh:resultSeverity sh:Info ;
sh:sourceConstraintComponent sh:InConstraintComponent ;
sh:sourceShape types:hashMethod-objects-in-shape ;
sh:value "SHA-1" ;
] ,
[
a sh:ValidationResult ;
sh:focusNode "SHA1"^^vocabulary:HashNameVocab ;
sh:resultMessage "Value is not member of the vocabulary HashNameVocab." ;
sh:resultSeverity sh:Info ;
sh:sourceConstraintComponent sh:InConstraintComponent ;
sh:sourceShape types:hashMethod-objects-in-shape ;
sh:value "SHA1"^^vocabulary:HashNameVocab ;
] ,
[
a sh:ValidationResult ;
sh:focusNode <http://example.org/kb/hash-b7eca8de-142d-4aa9-b546-0796a268afa4> ;
sh:resultMessage "As of UCO 1.4.0, the datatype to use for types:hashMethod should be xsd:string. Not using xsd:string will be an error in UCO 2.0.0." ;
sh:resultPath types:hashMethod ;
sh:resultSeverity sh:Warning ;
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
sh:sourceShape [
sh:datatype xsd:string ;
sh:message "As of UCO 1.4.0, the datatype to use for types:hashMethod should be xsd:string. Not using xsd:string will be an error in UCO 2.0.0." ;
sh:path types:hashMethod ;
sh:severity sh:Warning ;
] ;
sh:value "SHA1"^^vocabulary:HashNameVocab ;
] ,
[
a sh:ValidationResult ;
sh:focusNode <http://example.org/kb/hash-f46c714f-559a-4325-bf8a-4ef60c92c771> ;
sh:resultMessage "As of UCO 1.4.0, the datatype to use for types:hashMethod should be xsd:string. Not using xsd:string will be an error in UCO 2.0.0." ;
sh:resultPath types:hashMethod ;
sh:resultSeverity sh:Warning ;
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
sh:sourceShape [
sh:datatype xsd:string ;
sh:message "As of UCO 1.4.0, the datatype to use for types:hashMethod should be xsd:string. Not using xsd:string will be an error in UCO 2.0.0." ;
sh:path types:hashMethod ;
sh:severity sh:Warning ;
] ;
sh:value "1"^^xsd:integer ;
]
;
.

42 changes: 3 additions & 39 deletions tests/examples/hash_XFAIL.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,11 @@
},
"@graph": [
{
"@id": "kb:hash-04dcd1dc-6920-4977-a898-e242870249a4",
"@id": "kb:hash-66954988-aa9a-4f0d-8ad1-380700c830fc",
"@type": "types:Hash",
"rdfs:comment": "Should trigger sh:Info from the literal not having its datatype be the HashNameVocab vocabulary.",
"types:hashMethod": "CUSTOM_hash",
"types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "a39a3ee5e6b4b0d3255bfef95601890afd80709d"
}
},
{
"@id": "kb:hash-af4b0c85-b042-4e2d-a213-210b3d7f115c",
"@type": "types:Hash",
"rdfs:comment": "Should trigger sh:Violation from the literal declaring itself a member of the vocabulary, but not being a member. ('SHA1' is in the vocabulary; 'SHA-1' isn't.)",
"types:hashMethod": {
"@type": "vocabulary:HashNameVocab",
"@value": "SHA-1"
},
"types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
},
{
"@id": "kb:hash-e97431ea-6fb8-46d9-9c23-94be4b7cc977",
"@type": "types:Hash",
"rdfs:comment": "This should trigger sh:Info from the term not having its datatype be the vocabulary. Currently, no inspection is done on the lexical value.",
"rdfs:comment": "This should trigger sh:Violation from the hash value not being hexBinary.",
"types:hashMethod": "SHA1",
"types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
},
{
"@id": "kb:hash-f46c714f-559a-4325-bf8a-4ef60c92c771",
"@type": "types:Hash",
"rdfs:comment": "This should trigger sh:Violation from the term not being a string.",
"types:hashMethod": 1,
"types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
"types:hashValue": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
]
}
Loading
Loading