Explain Statement

Last revised 7/15/2021. Contact us.

The Explain Statement exists to help model developers debug their models. It has two forms, one to explain how something was inferred or is known and one to explain why a rule did or did not fire.

Explain: Followed by an Expression

When Explain: is followed by an expression expressing a triple pattern, inference is run and an attempt is made to find a derivation that match the requested pattern. If such a derivation is found, it is displayed. For example, suppose that we have this simple semantic model.

uri "http://sadl.org/Shapes.sadl" alias shp.

Shape is a class described by area with values of type float.

shp:comment is a type of annotation.

Circle is a type of Shape, described by radius with values of type float.

Rule AreaOfCircle:
   if
c is a Circle
   then
area of c is radius of c ^ 2 * PI.

MyCircle is a Circle with radius 3.

Now suppose that we add the following explain statement.

Explain: MyCircle has area x.

In this statement x is an unbound variable, so we are asking for an explanation of any triple that has MyCircle as subject and area as predicate. Running inference with the Jena reasoner produces these results.

Explanation of 'rdf(shp:MyCircle, shp:area, x)':
   Derivation of rdf(MyCircle, area, 28.27433466911316):
      was concluded by: Rule AreaOfCircle
         based on matching conditions:
            MyCircle type Circle
            MyCircle radius 3

We could have made the triple pattern less specific.

Explain: x has area y.


In this case we would have gotten the same results but for a more complex model and/or more complex data, there might be other triples with area as predicate and they might have different derivations.

Note that has we been very specific with the value

Explain: MyCircle has area 28.27433466911316.

We might have gotten results such as these.

Explanation of 'rdf(shp:MyCircle, shp:area, 28.27433466911316)':
  Possible inference of rdf(shp:MyCircle, shp:area, 28.27433466911316):
Statement not found but might be inferred by rule 'AreaOfCircle'.

Rule AreaOfCircle: Premise 1 of 4: rdf(c, type, Circle):
Premises through 1 had 1 matches.
(SPARQL Query: select ?c where {?c <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sadl.org/Shapes.sadl#Circle> })
c
http://sadl.org/Shapes.sadl#MyCircle

Rule AreaOfCircle: Premise 2 of 4: rdf(c, radius, v0):
Premises through 2 had 1 matches.
(SPARQL Query: select ?c ?v0 where {?c <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sadl.org/Shapes.sadl#Circle> . ?c <http://sadl.org/Shapes.sadl#radius> ?v0 })
c, v0
http://sadl.org/Shapes.sadl#MyCircle, 3.0

Rule AreaOfCircle: Premise 3 of 4 ignored: pow(v0,2,v1):
Premises through 3 had 1 matches.
(SPARQL Query: select ?c ?v0 where {?c <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sadl.org/Shapes.sadl#Circle> . ?c <http://sadl.org/Shapes.sadl#radius> ?v0 })
c, v0
http://sadl.org/Shapes.sadl#MyCircle, 3.0

Rule AreaOfCircle: Premise 4 of 4 ignored: product(v1,3.1415927,v2):
Premises through 4 had 1 matches.
(SPARQL Query: select ?c ?v0 where {?c <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sadl.org/Shapes.sadl#Circle> . ?c <http://sadl.org/Shapes.sadl#radius> ?v0 })
c, v0
http://sadl.org/Shapes.sadl#MyCircle, 3.0

Note that built-in functions such as pow and product are ignored at this time as as they are not easily exercised outside of an actual inference environment.

Explain: Followed by a Rule Identification

The Explain: keyword can also be followed by the keyword Rule followed by the name of a rule.

Explain: Rule AreaOfCircle.

This explain statement will seek to explain why the specified rule did or did not fire. If there are derivations that use the rule then those will be reported. If the rule did not fire queries will be executed against the model to try to determine which rule condition (rule body statement) was not satisfied. Most built-in functions are ignored at this time.

This explain statement results in the following output when using the Jena reasoner for the model above.

Explanation of Rule AreaOfCircle:
    Rule AreaOfCircle: Premise 1 of 4:     rdf(c, type, Circle):
    Rule AreaOfCircle: Premise 1 of 4:     rdf(c, type, Circle):
Premises through 1 had 1 matches.
(SPARQL Query: select ?c  where {?c   })
c
http://sadl.org/Shapes.sadl#MyCircle
    Rule AreaOfCircle: Premise 2 of 4:     rdf(c, radius, v0):
Premises through 2 had 1 matches.
(SPARQL Query: select ?c ?v0  where {?c    . ?c  ?v0 })
c, v0
http://sadl.org/Shapes.sadl#MyCircle, 3.0
    Rule AreaOfCircle: Premise 3 of 4 ignored:    pow(v0,2,v1):
Premises through 3 had 1 matches.
(SPARQL Query: select ?c ?v0  where {?c    . ?c  ?v0 })
c, v0
http://sadl.org/Shapes.sadl#MyCircle, 3.0
    Rule AreaOfCircle: Premise 4 of 4 ignored:    product(v1,3.1415927,v2):
Premises through 4 had 1 matches.
(SPARQL Query: select ?c ?v0  where {?c    . ?c  ?v0 })
c, v0
http://sadl.org/Shapes.sadl#MyCircle, 3.0