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

core:name validation error missed #96

Open
ajnelson-nist opened this issue Jul 13, 2022 · 2 comments
Open

core:name validation error missed #96

ajnelson-nist opened this issue Jul 13, 2022 · 2 comments

Comments

@ajnelson-nist
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member Author

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

@ajnelson-nist ajnelson-nist changed the title UcoObject core:name validation error missed Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant