GRDDL Is Out, How To Integrate With SPARQL
GRDDL is out, providing a mechanism for providing instructions to convert documents on the web into RDF. In short, GRDDL allows you to link an XSLT transform to your XHTML page, which converts the XHTML into an RDF document. For more information, start at the GRDDL Primer.
(The irony is that while you can use XSLT to convert into RDF, you can’t ever use XSLT to convert RDF into something else with complete certainly because RDF/XML output is nondeterministic.)
The primer includes a few examples of using SPARQL to query the RDF document generated by a GRDDL transform. Here’s an example from the primer:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rev: <http://www.purl.org/stuff/rev#>
PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?rating ?name ?region ?hotelname
FROM <http://www.w3.org/TR/grddl-primer/hotel-data.rdf>
WHERE {
?x rev:hasReview ?review;
vcard:ADR ?address;
vcard:FN ?hotelname .
?review rev:rating ?rating .
?address vcard:Locality ?region.
FILTER (?rating > "2").
?review rev:reviewer ?reviewer.
?reviewer foaf:name ?name;
foaf:homepage ?homepage
}
Looking at the FROM line, you see that we are referencing an RDF document by URI. However, if we are using GRDDL, that document doesn’t exist until after we perform any transforms.
This means we can’t use GRDDL directly in our SPARQL queries, as there isn’t a physical RDF document to reference.
However, using the ever useful GRDDL Service, which is an online web service (lower case web service
to generate RDF from documents using GRDDL, we could integrate GRDDL enabled documents directly into our SPARQL queries.
Let’s replace the FROM clause in our original SPARQL query with the direct URI to the RDF document (instead of the generated "middle man" RDF document).
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rev: <http://www.purl.org/stuff/rev#>
PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?rating ?name ?region ?hotelname
FROM <http://www.w3.org/2007/08/grddl/?docAddr=http%3A%2F%2Fwww.w3.org%2FTR%2Fgrddl-primer%2Fhotel-data.html&output=rdfxml>
WHERE {
?x rev:hasReview ?review;
vcard:ADR ?address;
vcard:FN ?hotelname .
?review rev:rating ?rating .
?address vcard:Locality ?region.
FILTER (?rating > "2").
?review rev:reviewer ?reviewer.
?reviewer foaf:name ?name;
foaf:homepage ?homepage
}
There, now isn’t that much more webby? I think the success of GRDDL lies with the integration into existing RDF toolkits. Otherwise, it’s a two step process to get documents off the web, transformed into RDF, and then into RDF tools.
For XHTML documents, though, my money is with RDFa. I think linking XSLT to XHTML is just too complicated and brittle (hmm, rhymes with GRDDL) for the masses OR for the tools. RDFa at least lets me directly embed the markup inside my XHTML documents, which makes it much easier to change when I change the XHTML. Plus, as my tools will dynamically generate the XHTML (think template languages for web frameworks) I can easily embed the RDFa right into the templates. Plus, I’m already using CSS and CSS classes, which RDFa encourages, so I can ride off of that investment.

[...] As you might know, GRDDL can also be used to generate RDF from XHTML+RDFa documents. However, there are people around preferring to use RDFa rather directly [...]
RDFa » Blog Archive » GRDDL is a W3C Recommendation
September 11, 2007 at 8:46 pm
Great stuff!
re. converting arbitrary RDF/XML with XSLT – it can be done if you keep triples in mind. Jeremy Carroll did a parser ages ago (“Snail” – it wasn’t fast
and the Semantic Planet RdfToTriplesStylesheet is a practical implementation.
Parsing the stuff into a store, querying and using XSLT on the SPARQL results would be my preferred option though…
Danny
September 12, 2007 at 1:28 am
[...] also How to integrate with SPARQL (not [...]
Unilever Centre for Molecular Informatics, Cambridge - petermr’s blog » Blog Archive » Semantic web : the scream!
September 24, 2007 at 11:12 am