Skip to content

Conversation

@kirchner
Copy link

@kirchner kirchner commented Jul 3, 2025

Hi,

the current SPARQLRule implementation will put all generated triples into the default_context when the validate function is called with a Dataset (and not a single Graph). But the check if a generated triple is already present (or has been previously generated) looks at the whole dataset. So, if this triple is present in a different graph of the dataset it will not be put into the default_context.

This currently breaks our application where we need to extract only the generated triples and have to provide additional triples (needed for the validation and generation) via extra graphs. And where we sometimes want triples to be generated even if they are already present in these extra graphs.

This PR includes some adjustments to only check the target_graph and adds a test.

Does this look like something you want to include? I'm also happy to do further adjustments. :)

Best regards,
Fabian

Previously, all graphs in the provided dataset would be checked if they
already contained triples generated by a SPARQLRule. But since generated
triples are added to the target graph (which is the default graph of the
dataset), we should only check for the triples inside this graph.
@ashleysommer
Copy link
Collaborator

Thanks for reporting this @kirchner
The decision to check if a generated triple is already present (or has has been previously generated) in the whole dataset, rather than in the default_context was a deliberate choice, but as you point out, it may not be the correct choice.

The thought was that if the triple already exists in a different graph, the user would not want that new triple generated by the rule in the default_graph.

I think this is another one of those features that comes from the fact that PySHACL was originally built to be only a SHACL validator, and the SHACL-AF Inference Rules were originally only for the purpose of facilitating correct validation. If you running SHACL rules expansion before validating a graph, then you would not want triples emitted into the default_graph if they already exist in another named graph in the dataset.

But if you are using pySHACL purely as a rules expander, for the purpose of exporting the built triples, then the original behaviour is not wanted. Perhaps this could be configurable?

@kirchner
Copy link
Author

Hi @ashleysommer,

Thank you for taking a look and your comments. :)

I would be very fine with having this behavior only available via an option. I assume this would be another named parameter of the validate function and would then be handed down to the apply inside the SHACLExecutor instance? And what would be a good name for this, maybe only_check_default_context?

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

Successfully merging this pull request may close these issues.

2 participants