Provenance plugin

Description

The Provenance plugin generates at query-time all statements that can be inferred from the statements of a specific graph, when they are combined with the axiomatic triples or added as part of the schema transaction (read-only).

In its essence, the plugin does a forward-chaining over the statements in a specific graph. The closure is computed during query evaluation and considers only statements marked as AXIOM in conjunction with the statements in the target graph.

The basic approach is to create ‘inference context’ using the provenance:derivedFrom predicate where the target graph is passed as a subject and its ‘inference context’ is created with a request scope and bound to the object variable of the provenance:derivedFrom triple pattern. Once created, the statements contained in the graph, along with the statements directly derived from them (recursively) are enumerated when the triple pattern is reevaluated by the query engine. The subject, predicate and object of any solution could be accessed using the provenance:subject, provenance:predicate, provenance:object predicates, which accept the ‘inference context’ as a subject component and bind the respective statement component within the object variable of the respective pattern. In case the object of these patterns is already bound, the solutions are filtered so that only the statements that have the specified component bound are returned.

Vocabulary

Common plugin namespace

<http://www.ontotext.com/provenance/>

Plugin predicates

The predicate that creates ‘inference context’ from a specific graph: <http://www.ontotext.com/provenance/derivedFrom>.

The set of predicates that access the solution using the currently bound ‘inference context’ from its subject, predicate and object components:

<http://www.ontotext.com/provenance/subject>
<http://www.ontotext.com/provenance/predicate>
<http://www.ontotext.com/provenance/object>

Examples

Example 1:

A query that returns all inferences derived from the triples in the <g:1> graph:

PREFIX pr: <http://www.ontotext.com/provenance/>

select {
     <g:1> pr:derivedFrom ?ctx .
     ?ctx pr:subject ?subject .
     ?ctx pr:predicate ?predicate .
     ?ctx pr:object ?object .
}

Example 2:

A query that returns all inferences derived from the triples in the <g:1> graph, which have an object that matches a specific RDF node:

PREFIX pr: <http://www.ontotext.com/provenance/>

select {
     <g:1> pr:derivedFrom ?ctx .
     ?ctx pr:subject ?subject .
     ?ctx pr:predicate ?predicate .
     ?ctx pr:object <unr:object> .
}

Example 3:

A more elaborate example with some background data and results returned from the sample queries.

  1. Configure a repository with an rdfs ruleset and add the following ‘axiomatic’ data.

    Note

    sys:schemaTransaction is used to mark the statements as ‘axioms’.

    INSERT DATA {
      <u:label> rdf:type rdf:Property .
      <u:label> rdfs:subPropertyOf rdfs:label .
      <u:prop> rdfs:domain <u:Class> .
      <u:Class> rdfs:subClassOf <u:ClassBase> .
      <u:ClassBase> rdfs:subClassOf <u:Root> .
      [] <http://www.ontotext.com/owlim/system#schemaTransaction> [] .
    }
    
  2. Add some user data to the two user graphs <g:1> and <g:2>:

    INSERT DATA {
      GRAPH <g:1> {
      <u:s:1> <u:prop> <u:val:1> .
      <u:shared> <u:label> "shared:g1" .
    }
    
      GRAPH <g:2> {
      <u:s:2> <u:prop> <u:val:2> .
      <u:shared> <u:label> "shared:g2" .
      }
    }
    
  3. Evaluate a query using the Provenance plugin:

    prefix pr: <http://www.ontotext.com/provenance/>
    
    select * {
          values ?g {<g:1>}
          ?g pr:derivedFrom ?r .
          ?r pr:subject ?subject .
          ?r pr:predicate ?predicate .
          ?r pr:object ?object.
    }
    
  4. Get results such as:

    g object subject predicate
    g:1 "shared:g1" u:shared u:label
    g:1 "shared:g1" u:shared http://www.w3.org/2000/01/rdf-schema#label
    g:1 u:val:1 u:s:1 u:prop
    g:1 u:Class u:s:1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type
    g:1 u:ClassBase u:s:1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type
    g:1 u:Root u:s:1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type

    To get only the statements that have the <u:shared> node as a subject (use ‘VALUES’ for easy reading):

    prefix pr: <http://www.ontotext.com/provenance/>
    
    select * {
        values ?subject {<u:shared>} .
        values ?g {<g:1>}
        ?g pr:derivedFrom ?r .
        ?r pr:subject ?subject .
        ?r pr:predicate ?predicate .
        ?r pr:object ?object.
    }
    

    the results are, respectively:

    g object subject predicate
    g:1 "shared:g1" u:shared u:label
    g:1 "shared:g1" u:shared http://www.w3.org/2000/01/rdf-schema#label

    Alternatively, to get only the rdf:type statements, the query may look like the following:

    prefix pr: <http://www.ontotext.com/provenance/>
    
    select * {
        values ?predicate {rdf:type} .
        values ?g {<g:1>}
        ?g pr:derivedFrom ?r .
        ?r pr:subject ?subject .
        ?r pr:predicate ?predicate .
        ?r pr:object ?object.
    }
    

    and the results will be:

    g subject object predicate
    g:1 u:s:1 u:Class http://www.w3.org/1999/02/22-rdf-syntax-ns#type
    g:1 u:s:1 u:ClassBase http://www.w3.org/1999/02/22-rdf-syntax-ns#type
    g:1 u:s:1 u:Root http://www.w3.org/1999/02/22-rdf-syntax-ns#type