casework / CASE

Cyber-investigation Analysis Standard Expression (CASE) Ontology
https://caseontology.org
Apache License 2.0
66 stars 22 forks source link

core:name validation error missed #96

Open ajnelson-nist opened 2 years ago

ajnelson-nist commented 2 years ago

This snippet failed to trigger a validation error:

{
    "@context": {
        "case-investigation": "https://ontology.caseontology.org/case/investigation/",
        "kb": "http://example.org/kb/",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
        "uco-action": "https://ontology.unifiedcyberontology.org/uco/action/",
        "uco-core": "https://ontology.unifiedcyberontology.org/uco/core/",
        "uco-identity": "https://ontology.unifiedcyberontology.org/uco/identity/",
        "uco-location": "https://ontology.unifiedcyberontology.org/uco/location/",
        "uco-observable": "https://ontology.unifiedcyberontology.org/uco/observable/",
        "uco-tool": "https://ontology.unifiedcyberontology.org/uco/tool/",
        "uco-types": "https://ontology.unifiedcyberontology.org/uco/types/",
        "uco-vocabulary": "https://ontology.unifiedcyberontology.org/uco/vocabulary/",
        "xsd": "http://www.w3.org/2001/XMLSchema#"
    },
    "@graph": [
        {
            "@id": "kb:organization-2b3b98e2-aea2-4270-876a-7f9917623cb6",
            "@type": "uco-core:UcoObject",
            "uco-core:name": {"@id": "Cyber Domain Ontology"}
        }
    ]
}
ajnelson-nist commented 2 years ago

Diagnosis:

This was an issue with rdflib silently dropping the invalid node-identifier form.

This Python program demonstrates the issue:

import rdflib

graph_data = """\
{
    "@context": {
        "case-investigation": "https://ontology.caseontology.org/case/investigation/",
        "kb": "http://example.org/kb/",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
        "uco-action": "https://ontology.unifiedcyberontology.org/uco/action/",
        "uco-core": "https://ontology.unifiedcyberontology.org/uco/core/",
        "uco-identity": "https://ontology.unifiedcyberontology.org/uco/identity/",
        "uco-location": "https://ontology.unifiedcyberontology.org/uco/location/",
        "uco-observable": "https://ontology.unifiedcyberontology.org/uco/observable/",
        "uco-tool": "https://ontology.unifiedcyberontology.org/uco/tool/",
        "uco-types": "https://ontology.unifiedcyberontology.org/uco/types/",
        "uco-vocabulary": "https://ontology.unifiedcyberontology.org/uco/vocabulary/",
        "xsd": "http://www.w3.org/2001/XMLSchema#"
    },
    "@graph": [
        {
            "@id": "kb:organization-2b3b98e2-aea2-4270-876a-7f9917623cb6",
            "@type": "uco-core:UcoObject",
            "uco-core:name": {"@id": "Cyber Domain Ontology"}
        }
    ]
}
"""

graph = rdflib.Graph()
graph.parse(data=graph_data, format="json-ld")
print(len(graph))

This prints 1 (with only one valid triple left, assigning a UcoObject type to the KB node). The length of the graph is supposed to be 2, but the uco-core:name triple does not load.

As expected, the graph length becomes 2, and a SHACL validation error is triggered, if I replace this:

{"@id": "Cyber Domain Ontology"}

with this:

{"@id": "kb:organization-2b3b98e2-aea2-4270-876a-7f9917623cb6"}
ajnelson-nist commented 2 years ago

How to handle the silent-dropping issue has been raised in rdflib Issue 2017.