|
Grit
Grokkable RDF Is Transformable
IntroductionGrit (Grokkable RDF Is Transformable) is an XML format intended to solve the shortcomings of the often cumbersome and varied RDF/XML format. The design of Grit has been geared towards applying XSLT to generate output markup (e.g. html), but it's intended to be a generally versatile XML-format for RDF. PrinciplesGrit is a new format. This makes it clear that any XSLT (or other code) which uses the output isn't intended to transform RDF/XML. There is no formal way to indicate if an RDF/XML document has been normalized in any way, which makes it hard to impossible to use XML-tools with that serialization efficiently. Grit is designed to make that possible. The core points of Grit are:
DesignGrit uses non-namespaced elements and attributes to represent the structure skeleton of a resource tree, where all resources have a @uri attribute. All properties use namespaced elements (as in RDF/XML). A document consists of a <graph> root element containing (usually) one or more <resource> elements. These <resource> elements normally have a @uri attribute to set the subject of the described resource. Example: <graph
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<resource uri="http://example.org/somebody#">
<a><foaf:Person/></a>
<foaf:name>Some Body</foaf:name>
<foaf:homepage ref="http://example.org/somebody"/>
</resource>
<resource uri="http://example.org/somebody">
<dct:title xml:lang="en">The homepage of Some Body</dct:title>
<dct:created fmt="datatype"><xsd:dateTime>2010-01-17T17:00:00Z</xsd:dateTime></dct:created>
</resource>
</graph>NormalizationWhen representing a set of RDF statements as Grit XML, each described resource must be fully enclosed in a <resource> element, if it has a URI. If it is anonymous (i.e. a bnode), all statements either go within a property referencing it, or in a top-level <resource> element without a @uri. (In the rare cases where bnodes are used as object in more than one statement, the bnode ID:s are given in the @ref and @uri attributes respecively, prefixed by _:. See #BNodes below for more details.) TypesType references are treated specially, to facilitate XPath matching. They are represented as elements wrapped in an <a> element, as in: <resource uri="...">
<a><foaf:Agent/></a>
<a><foaf:Person/></a>
....
</resource>URI referencesProperties referencing resources with a @ref attribute containing the URI: <foaf:homepage ref="http://example.org/somebody"/> BNodesProperties referencing bnodes carry the descriptions inline (similar to @parseType='Literal' in RDF/XML). Example: <foaf:knows>
<foaf:nick>otherone</foaf:nick>
</foaf:knows>In the rare cases where bnodes are used as object in more than one statement, Grit allows giving the needed bnode id in the regular @ref and @uri, as a special value prefixed by _:. Example: <resource uri="_:p1">
<a><foaf:Person/></a>
<foaf:knows ref="_:p2"/>
</resource>
<resource uri="_:p2">
<a><foaf:Person/></a>
<foaf:knows ref="_:p1"/>
</resource>This form isn't allowed in the URI formal syntax, but in order to make processing of Grit XML easier, the value space in these attributes is overloaded to be both real URI:s and this bnode id syntax. The opinion of Grit is that this is rarely a feature, as it makes the particulars of bnodes more difficult to work with. But since it may have it's usage (and since such statements exist in the wild), Grit allows it. (There is also a usability trade-off in nesting property elements for bnodes in the referencing property element, as using code must check for the presence of a @ref in order to determine whether to use the contents of the property element, or look up a possible description via /graph/resource/@uri on it.) LiteralsLiterals are given as inlined strings, as expected. Language LiteralsA literal with language looks just as in RDF/XML: <dct:title xml:lang="en">The homepage of Some Body</dct:title> Typed LiteralsThis is a preliminary design which must be evaluated for usability. Typed literals are marked with @fmt, which may have a value of either datatype, for which the value is wrapped in an element whose qname is resolvable to the datatype URI: <dct:created fmt="datatype"><xsd:dateTime>2010-01-17T17:00:00Z</xsd:dateTime></dct:created> or xml (for an inlined XML literal): <dct:description fmt="xml">
<p xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">Details in the <a href="...">XHTML</a> format.</p>
</dct:description>RDF ListsLists use null-namespaced <li> elements, corresponding to the content of regular <resource> elements (either carrying @ref attributes or representing nested bnodes). (This, of course, is equivalent to the @parseType="Collection" of RDF/XML.) Example: <bibo:editorList>
<li ref="http://example.org/editor/1"/>
<li ref="http://example.org/editor/2"/>
<li ref="http://example.net/editor/3"/>
<li>
<rdfs:label>editor 4<rdfs:label>
</li>
<li>
<rdfs:label>editor 5<rdfs:label>
</li>
</bibo:editorList>ImplementationsThere is an XSLT for transforming RDF/XML to Grit at http://purl.org/oort/impl/xslt/grit/rdfxml-grit.xslt. There's also an XSLT for GRDDL:ing Grit back to RDF/XML at http://purl.org/oort/impl/xslt/grit/grit-grddl.xslt. (Also, checkout the source repository, especially the examples and the aforementioned implementations.) Relationship to Other XML-based RDF formatsThere are several XML-based formats for expressing RDF, with different design principles and intended use. Only RDF/XML and RDFa are W3C standards, and XHTML+RDFa isn't intended for the same things as Grit (representing normalized data), so it is excluded in these comparisons. RDF/XMLWhen implementing an XSLT for instrumental use of RDF/XML, it became apparent that "just" normalizing RDF/XML (as has been done by many people) may not be enough to make the result readily usable in XSLT. Matching types, looking up things by XPath etc. should be as simple as possible. This is what Grit is intended to solve. Allowing for compact xpath expressions is the primary reason for not using a namespace (a.k.a. the "blank" or "null" namespace) for the "skeleton" (the graph and resource elements and the @uri, @ref and @fmtattributes). Another motivation for deviating from the RDF/XML format is to attempt to provide a more readable format in general, designed have a much more normalized form (limiting many variations of expression). This should also make it much more straightforward to work with using regular XML tools such as XSLT+XPath, XQuery and many existing XML API:s available. TriX, RXRUsing namespaces to represent properties and types with qnames is at the heart of Grit, just as in RDF/XML. This sets it apart from e.g. TRiX and RXR. These formats express triples directly, and use full URI:s for properties. AtomThe design of Grit is to some degree reminiscent of the Atom XML syntax. In terms of resource description, it is both more versatile, by supporting rich datatypes and also a uniform way of representing both literals and "links", i.e. resource references. In comparison, Atom, the @rel-attribute of the <atom:link> element is used to name relations, and for anything else either the builtin properties of atom (title, updated etc.) or invent extensions who lack any shared formal semantics. Still it is important to understand that the Atom semantics are about capturing entries (slightly similar to a "unit of description") and temporality, that is the updated element determines which is the most recent (and thus currently "active") description. It also defines little in terms of an open world, graphs of statements etc. Working on integrating these aspects is (at least currently) beyond the scope of Grit, interesting as it may be. The Grit serialization of RDF has a form which may be suitable for embedding in entries (along with rules for how they relate). And something could be made of multiple named graphs/contexts with timestamps.. TributeAll of the other formats mentioned here (and more), as well as a lot of other existing (often XSLT-leveraging) tools for normalizing RDF/XML have been extensive sources of inspiration for Grit. If anything Grit should be considered as homage to all that work. That said, it does strive, to some extent, to be their alternative. Here are some interesting articles on the topic of using/normalizing XML-serializations of RDF in random order:
Tips & TricksLeverage EXSLT whenever you can when working with XSLT on this format (and other XML) . Some useful examples of using Grit are in the making but have yet to be published. |