Rdf:List Stresstest

From RDF Data Shapes Working Group
Jump to: navigation, search

This is meant as a “stresstest” rather than as a practical use case:

Can we express validating rdf:Lists a in our framework? Conditions (are these sufficient?):

  • Is there an rdf:rest that is neither rdf:nil, nor a bnode?
  • Is there an rdf:rest without an rdf:first?
  • rdf:nil should not have outgoing edges
  • subject for rdf:rest or rdf:first and first must be a bnode
  • lists may not branch (cardinality on first and rest must be exactly 1.
  • no cycles

This could be extended to constraints *on* lists... e.g. are the elements in the list all numeric, ore the elements ordered, etc.

In SPIN (untested, just showing the ASK queries attached to rdf:List via spin:constraint):

   # Cardinality of rdf:first must be 1
   ASK WHERE {
       FILTER (spl:objectCount(?this, rdf:first) != 1) .
   }

   # Cardinality of rdf:rest must be 1
   ASK WHERE {
       FILTER (spl:objectCount(?this, rdf:rest) != 1) .
   }

   # rdf:rest must be a bnode or rdf:nil
   ASK WHERE {
       ?this rdf:rest ?rest .
       FILTER (!(isBlank(?rest) || (?rest = rdf:nil))) .
   }

   # Subject of rdf:first or rdf:rest must be a bnode
   ASK WHERE {
       ?this rdf:first|rdf:rest ?any .
       FILTER isIRI(?this) .
   }

   # Lists must be acyclic
   ASK WHERE {
       ?this (rdf:rest)+ ?this .
   }

(If the system triple rdf:nil a rdf:List is present then some WHERE clauses need to include a FILTER ?this != rdf:nil because they do not apply to rdf:nil itself).

This SPIN solution could be made more readable by introducing Templates - many patterns here are generic and therefore may be reused with different properties.