Materialize inferred triples

26 views
Skip to first unread message

richarddi...@gmail.com

unread,
May 20, 2021, 11:55:10 AM5/20/21
to rdflib-dev
Using shacl-af with    pyshacl -a   I want to materialize the inferred triples using shacl-rules.
It is however not clear to me in what result the triples are collected.
Any hint is appreciated.

kind regards, Richard

Boris Pelakh

unread,
May 20, 2021, 1:50:17 PM5/20/21
to rdfli...@googlegroups.com
Richard,

As per the code, it appears that triples created by inference from sh:rule are added into the data_graph, which makes sense, since you can evaluate the other rules against the inferred content. In SPARQLRule:

   data_graph = clone_graph(g, target_graph=data_graph)

and in TripleRule:

            for i in iter(new_triples):
                data_graph.add(i)

I believe this makes the new triples not accessible from the command line at this time, but if you invoke pySHACL from your own main, you should be able to inspect the data graph you passed in after running and determine the new triples introduced.

--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/6cf11681-7896-472c-8237-7a951548e6d0n%40googlegroups.com.

richarddi...@gmail.com

unread,
May 21, 2021, 2:54:02 AM5/21/21
to rdflib-dev
Thank you Boris for the hint.

Inferences going into the datagraph makes sense indeed. However attached example does not give the wanted result.
I will check this in the weekend again.

btw I am running on Windows10 using RDFlib 5.0.0

Kind regards,
Richard
testpyshacl.zip

Boris Pelakh

unread,
May 21, 2021, 8:00:32 AM5/21/21
to rdflib-dev
Took a look at your code and shapes, had to make a couple of little fixes. In your prologue, you had:

data_graph_orig = data_graph

That made them both reference the same graph, so there was never a difference. I replaced that with:

data_graph_orig = Graph()
for t in data_graph:
    data_graph_orig.add(t)

to clone the data. That made the extra triples introduced by RDFS reasoning show up as added. I then took a look
at your shapes, and was a little thrown off by the sh:values construct you used (I can't find it in SHACL-AF) and the
use of the spif: time functions, which are not natively present in pySHACL (perhaps you introduced them in your
context?). Regardless, I added the following declaration and rule:

kennedys:
a owl:Ontology ;
owl:imports sh: ;
sh:declare [
sh:prefix "kennedys" ;
sh:namespace "http://kennedys.com/"^^xsd:anyURI ;
] ;
sh:declare [
sh:prefix "schema" ;
sh:namespace "http://schema.org/"^^xsd:anyURI ;
] .

schema:PersonAgeRule
a sh:NodeShape ;
sh:targetClass schema:Person ;
sh:rule [
a sh:SPARQLRule ;
sh:prefixes schema: ;
sh:construct """
CONSTRUCT {
$this schema:age ?age
}
WHERE {
$this schema:birthDate ?birthDate .
FILTER NOT EXISTS { $this schema:deathDate ?any }
bind(year(now()) - year(xsd:dateTime(CONCAT(STR(?birthDate), 'T00:00:00'))) as ?age)
}
""" ;
] ;
.

(The actual YEAR() function only works on dateTime, thus the date hackery)

which caused the following to show up in the graph diff:

(rdflib.term.URIRef('http://kennedys.com/CarolineKennedy'), rdflib.term.URIRef('http://schema.org/age'), rdflib.term.Literal('64', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')))

Hope that helps.

richarddi...@gmail.com

unread,
May 21, 2021, 8:48:29 AM5/21/21
to rdflib-dev
Hi Boris,

Thank you for fixing the errors and showing how pyshacl can do it.

The shapes do come from the TopQuadrant site: https://www.topquadrant.com/graphql/values.html , expecting that these would run for sure.
This explains the spif class .

Kind regards,
Richard

Boris Pelakh

unread,
May 21, 2021, 10:16:21 AM5/21/21
to rdfli...@googlegroups.com
Oh, I see. It does state that this is 'SHACL property value rules, a proposed extension to the SHACL-AF specification.', so not yet in the standard, and therefore not yet in pySHACL. Looks interesting, though I prefer the clarity of Datalog-based rules such as https://docs.stardog.com/inference-engine/user-defined-rules or https://docs.oxfordsemantic.tech/reasoning.html#the-rule-language-of-rdfox as opposed to the increasingly awkward ways TQ is bolting inference onto SHACL.

You received this message because you are subscribed to a topic in the Google Groups "rdflib-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rdflib-dev/WBH8odJKVf0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rdflib-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/c708299c-ecf2-4a6b-9ad0-31e39371a5e8n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages