[pystardog] Inference explanation remains empty

I'm currently trying to get the inference explanation of a queried result through pystardog.
Using the examples inside the GitHub repository is was able to create something like this:

s = result['s']['value']
triple = "<"+s+">\t"+"<https://www.w3.org/1999/02/22-rdf-syntax-ns#type>\t"+"<http://www.w3.org/ns/sosa/Observation>."
r = conn.explain_inference(stardog.content.Raw(triple))
print(r)

But the return value is always an empty list...
I've tried other ways to format the triple itself, but then I get a 406 error...

Or does pystardog provides other ways to get the inference rules from a select query?

More in detail:
I have some rules inside my database, and when I perform a select SPARQL query, I receive the correct triples. I now want to know which rules were fired for each of the individual query results..

Hello. Just to help isolate the problem, have you attempted to explain the inference using the Stardog CLI? Something like this command will do it:

stardog reasoning explain dbname '<urn:subj> <urn:pred> <urn:obj> .'

I haven't used pystardog myself but this is just my best guess. You might want to drop the angle brackets when constructing triple in case the result already has angle brackets in which case you'd end up with double angle brackets.

s = result['s']['value']
triple = "" + s + "\t" + "<https://www.w3.org/1999/02/22-rdf-syntax-ns#type>\t" + "<http://www.w3.org/ns/sosa/Observation>."
print(triple)
r = conn.explain_inference(stardog.content.Raw(triple))
print(r)

Hi, I think pystardog drops these angle brackets by default..
When I run your code, I get this error:
[400] : Expected '<' or '_', found: h [L1]

Hi Cullan,
I have tested your suggestion, but I'm getting an Input axiom is not inferred; nothing to explain.

Command:

stardog reasoning explain test '<http://example.com/observations/10060> <https://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://IBCNServices.github.io/Folio-Ontology/Folio.owl#ConfirmedAnomaly>.' 

Triple:

<http://example.com/observations/10060> <http://www.w3.org/ns/sosa/hasSimpleResult> "951"^^<http://www.w3.org/2001/XMLSchema#float> .
<http://example.com/observations/10060> <http://www.w3.org/ns/sosa/resultTime> "2019-04-08T08:15:29+02:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<http://example.com/observations/10060> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/sosa/Observation> .

And I'm using a simple SWRL rule:

sosa:Observation(?x2) ^ sosa:hasSimpleResult(?x2, ?r2) ^ swrlb:greaterThan(?r2, 900) -> folio:ConfirmedAnomaly(?x2)

It looks like you have https as the protocol in the rdf:type predicate. It should be HTTP. Please let us know if this fixes it.

Jess

1 Like

Hi Jess,

This was indeed the problem.
Tx

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.