Schemarama 2 is a testing framework for RDF, that uses SPARQL to generate messages based on patterns found in a graph.
Design
First, you define a test case. A test case consists of a list of tests, organised into test groups.
Here is an example test case, written in Turtle:
# A schemarama test case to establish the basic integrity of some SKOS data
@prefix skos: <http://www.w3.org/2004/02/skos/core#>.
@prefix : <http://purl.org/net/schemarama#>.
@prefix dc: <http://purl.org/dc/elements/1.1/>.
<> a :TestCase;
dc:title "SKOS Core Basic Integrity Test Case";
dc:description "A schemarama test case to establish the basic integrity of some SKOS data.";
:groups (
_:group1
);
.
_:group1 a :TestGroup;
dc:title "Main Test Group";
dc:description "Main test group.";
:infer <rules/basic.rules>;
:tests (
<tests/basic1.sparql>
<tests/basic2.sparql>
);
.
<tests/basic1.sparql> a :Test;
dc:title "Hierarchy Circularity Test";
dc:description "Tests for circularities in generalisation (skos:broader/skos:narrower) relationships between concepts.";
.
<tests/basic2.sparql> a :Test;
dc:title "Hierarchy Integrity Test";
dc:description "Tests for any two concepts involved in an associative (skos:related) relationship, where there is also a generalisation (skos:broader/skos:narrower) relationship.";
.
(This file is found at http://isegserv.itd.rl.ac.uk/cvs-public/~checkout~/skos/schemarama/basic.turtle)
A test group may have one or more sets of background rules, given by the :infer property, to be computed before the tests in that group are run. The ‘basic.rules’ file looks like:
# Inference rules to support basic integrity test case (Jena2 syntax)
@prefix skos: <http://www.w3.org/2004/02/skos/core#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
# Infer sub-property closure
(?p rdfs:subPropertyOf ?q), (?x ?p ?y) -> (?x ?q ?y).
# Infer sub-class closure
(?c rdfs:subClassOf ?d), (?x rdf:type ?c) -> (?x rdf:type ?d).
# Infer inverse of skos:narrower
(?x skos:narrower ?y) -> (?y skos:broader ?x).
# Infer symmetric for skos:related
(?x skos:related ?y) -> (?y skos:related ?x).
# Infer transitive closure of skos:broader
(?x skos:broader ?y), (?y skos:broader ?z) -> (?x skos:broader ?z).
Each test is a SPARQL CONSTRUCT query, that generates one or more reports based on an examination of the test data. Heres the ‘basic1.sparql’ query:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX : <http://purl.org/net/schemarama#>
CONSTRUCT
{
[] a :Error;
:message 'Concept [1] is involved in a circularity in the generalisation hierarchy.';
:implicated ( ?x );
.
}
WHERE
{
?x skos:broader ?x.
}
Credits
The idea of generating errors and warnings based on a graph pattern match, with implicated nodes, comes from the Jena2 validation support.
The name ‘Schemarama 2′ comes from the fact that the approach is very similar to the original ‘Schemarama’ work done by Dan Brickley, Leigh Dodds and Libby Miller. See Leigh’s XML.com article, the IRLT schemarama site, and the schemarama demo at rdfweb.org.
The approach is also similar in principle to the Schematron language for making assertions about patterns found in XML documents.