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

Monolithic file generates report, split .ttl files do not. #46

Closed
James-Hudson3010 opened this issue Mar 27, 2020 · 3 comments
Closed

Comments

@James-Hudson3010
Copy link

James-Hudson3010 commented Mar 27, 2020

I have a gist with all of the relevant files at: https://gist.github.com/James-Hudson3010/2588d9b17dd33e15922122b8b5cf1bd7

If I execute:

$ pyshacl -a -f human employees.ttl

I get the following, correct validation report...

Validation Report
Conforms: False
Results (3):
Constraint Violation in MaxInclusiveConstraintComponent (http://www.w3.org/ns/shacl#MaxInclusiveConstraintComponent):
	Severity: sh:Violation
	Source Shape: hr:jobGradeShape
	Focus Node: d:e4
	Value Node: Literal("8", datatype=xsd:integer)
	Result Path: hr:jobGrade
Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):
	Severity: sh:Violation
	Source Shape: hr:jobGradeShape
	Focus Node: d:e3
	Value Node: Literal("3.14", datatype=xsd:decimal)
	Result Path: hr:jobGrade
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
	Severity: sh:Violation
	Source Shape: hr:jobGradeShape
	Focus Node: d:e2
	Result Path: hr:jobGrade

However, if I split employees.ttl into three files containing the schema, shape, and instance data and run:

pyshacl -s shape.ttl -e schema.ttl -a -f human instance.ttl

the result is:

Validation Report
Conforms: True

I assume I am calling pyshacl correctly.

@James-Hudson3010
Copy link
Author

James-Hudson3010 commented Mar 31, 2020

I believe I understand part of what is going on, but not the reasons behind it.

When one splits into three separate parts, the shacl_graph does not contain the ont_graph information and cannot be processed correctly.

A simple hack that fixes the problem is one line of code in the Validator __init__ code.

shacl_graph = mix_datasets( shacl_graph, self.ont_graph )

        if self.ont_graph is not None and \
            isinstance(self.ont_graph, (rdflib.Dataset, rdflib.ConjunctiveGraph)):
            self.ont_graph.default_union = True

       shacl_graph = mix_datasets( shacl_graph, self.ont_graph )

        if shacl_graph is None:
            shacl_graph = clone_graph(data_graph, identifier='shacl')
        assert isinstance(shacl_graph, rdflib.Graph),\
            "shacl_graph must be a rdflib Graph object"
        self.shacl_graph = ShapesGraph(shacl_graph, self.logger)

basically, I add the ont_graph to the shacl_graph and it works as expected.

Obviously, there are some more checks that need to go in here for a complete solution and there may be other issues I have not yet considered.

@ashleysommer
Copy link
Collaborator

ashleysommer commented Mar 31, 2020

Hi @James-Hudson3010

Yes, your assessment is correct, in pySHACL the shacl_graph does not get any ont_graph triples mixed in.
Keep in mind the extra-ontology-graph feature (ont_graph) was specifically introduced to mix into the DataGraph for the purpose to keep DataGraph files smaller, and the practical reality that DataGraph files cannot always be relied on to contain all of the ontology definitions required for validation to work properly, especially if the Datagraph was supposed to be pre-inferenced before validation and those definitions are needed to enable inferencing.

The ont_graph was never intended to mix with the SHACL Shapes Graph. Its considered bad practice for a shacl validator to modify the Shapes graph in any way before validation, because that can cause unforeseen validation issues (as you have alluded to).

If a SHACL Shapes Graph requires any ontological definitions in order to work correctly then it makes sense that the author should include those definitions either directly in the SHACL Shapes source file, or via an owl:imports statement in the SHACL shapes file.

I hope that has helped.

@ashleysommer ashleysommer changed the title failure to report validation errors Monolithic file generates report, split .ttl files do not. Mar 31, 2020
@James-Hudson3010
Copy link
Author

It does. Thank you.

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

2 participants