Easier in RDFa: multiple types and the influence of syntax on semantics

RDF is defined as an abstract data model, plus a collection of practical notations for exchanging RDF descriptions (eg. RDF/XML, RDFa, Turtle/N3). In theory, your data modelling activities are conducted in splendid isolation from the sleazy details of each syntax. RDF vocabularies define classes of thing, and various types of property/relationship that link those things. And then instance data uses arbitrary combinations of those vocabularies to make claims about stuff. Nothing in your vocabulary design says anything about XML or text formats or HTML or other syntactic details.

All that said, syntactic considerations can mess with your modelling. I’ve just written this up for the Linked Library Data group, but since the point isn’t often made, I thought I’d do so here too.

RDF instance data, ie. descriptions of stuff, is peculiar in that it lets you use multiple independent schemas at the same time. So I might use SKOS, FOAF, Bio, Dublin Core and DOAP all jumbled up together in one document. But there are some considerations when you want to mention that something is in multiple classes. While you can do this in any RDF notation, it is rather ugly in RDF/XML, historically RDF’s most official, standard notation. Furthermore, if you want to mention that two things are related by two or more specified properties, this can be super ugly in RDF/XML. Or at least rather verbose. These practical facts have tended to guide the descriptive idioms used in real world RDF data. RDFa changes the landscape significantly, so let me give some examples.

Backstory – decentralised extensibility

RDF classes from one vocabulary can be linked to more general or specific classes in another; we use rdfs:subClassOf for this. Similarly, RDF properties can be linked with rdfs:subPropertyOf claims. So for example in FOAF we might define a class foaf:Organization, and leave it at that. Meanwhile over in the Org vocabulary, they care enough to distinguish a subclass, org:FormalOrganization. This is great! Incremental, decentralised extensibility. Similarly, FOAF has foaf:knows as a basic link between people who know each other, but over in the relationship¬†vocabulary, that has been specialized, and we see relationships like ‘livesWith‘, ‘collaboratesWith‘. These carry more specific meaning, but they also imply a foaf:knows link too.

This kind of machine-readable (RDFS/OWL) documentation of the patterns of meaning amongst properties (and classes) has many uses. It could be used to infer missing information: if Ian writes RDF saying “Alice collaboratesWith Bob” but doesn’t explicitly say that Alice also knows Bob, a schema-aware processor can add this in. Or it can be used at query time, if someone asks “who does Alice know?”. But using this information is not mandatory, and this creates a problem for publishers. Should they publish redundant information to make it easier for simple data consumers to understand the data without knowing about the more detailed (and often more recent) vocabulary used?

Historically, adding redundant triples to capture the more general claims has been rather expensive – both in terms of markup beauty, and also file size. RDFa changes this.

Here’s a simple RDF/XML description of something.

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person rdf:about="#fred">
 <foaf:name>Fred Flintstone</foaf:name>
</foaf:Person>
</rdf:RDF>

…and here is how it would have to look if we wanted to add a 2nd type:

<foaf:Person rdf:about="#fred"
 rdf:type="http://example.com/vocab2#BiblioPerson">
  <foaf:name>Fred Flintstone</foaf:name>
</foaf:Person>
</rdf:RDF>

To add a 3rd or 4th type, we’d need to add in extra subelements eg.

<rdf:type rdf:resource="http://example.com/vocab2#BiblioPerson"/>

Note that the full URI for the vocabulary needs to be used at every occurence of the type.¬† Here’s the same thing, with multiple types, in RDFa.

<html>
<head><title>a page about Fred</title></head>
<body>
<div xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:vocab2="http://example.com/vocab2#"
 about="#fred" typeof="foaf:Person vocab2:BiblioPerson" >
<span property="foaf:name">Fred Flintstone</span>
</div>
</body>
</html>

RDFa 1.0 requires the second vocabulary’s namespace to be declared, but after that it is pretty concise if you want to throw in a 2nd or a 3rd type, for whatever you’re¬†describing. If you’re talking about a relationship between people, instead of ” rel=’foaf:knows’ ” you could put “rel=’foaf:knows rel:livesWith’ “; if you wanted to mention that something was in the class not just of organizations, but formal organizations, you could write “typeof=’foaf:Organization org:FormalOrganization’”.

Properties and classes serve quite different social roles in RDF. The classes tend towards being dull, boring, because they are the point of connection between different datasets and applications. The detail, personality and real information content in RDF lives in the properties. But both classes and properties fall into specialisation hierarchies that cross independent vocabularies. It is quite a common experience to feel stuck, not sure whether to use a widely known but vague term, or a more precise but ‘niche’, new or specialised vocabulary. As RDF syntaxes improve, this tension can melt away somewhat. In RDFa it is significantly easier to simply publish both, allowing smart clients to understand your full detail, and simple clients to find the patterns they expect without having to do schema-based processing.

5 Responses to Easier in RDFa: multiple types and the influence of syntax on semantics

  1. [...] This post was mentioned on Twitter by Mo, Dan Brickley and infopeep, Tim Sherratt. Tim Sherratt said: RT @danbri: blogged about rdfa, distributed extensibility http://danbri.org/words/2010/11/02/572 [...]

  2. danbri says:

    ps. all my examples concern terms defined in different vocabularies/namespaces; however the same situation arises even eg. with two classes from the same vocabulary.

  3. webr3 says:

    In RDFa 1.1 you can swap the xmlns:foaf approach for the @prefix attribute, which can be used on any element in the tree as such:


    <html
    xmlns="http://www.w3.org/1999/xhtml"
    prefix="foaf: http://xmlns.com/foaf/0.1/
    vocab2: http://example.com/vocab2#"
    >
    <head><title>a page about Fred</title></head>
    <body>
    <div about="#fred" typeof="foaf:Person vocab2:BiblioPerson" >
    <span property="foaf:name">Fred Flintstone</span>
    </div>
    </body>
    </html>

    Or you can set a default @vocab on any element which will allow you to use say “name” rather than foaf:name, as such


    <html
    xmlns="http://www.w3.org/1999/xhtml"
    vocab="http://xmlns.com/foaf/0.1/"
    >
    <head><title>a page about Fred</title></head>
    <body>
    <div about="#fred" prefix="vocab2: http://example.com/vocab2#" typeof="Person vocab2:BiblioPerson" >
    <span property="name">Fred Flintstone</span>
    </div>
    </body>
    </html>

    Or you can define your prefixes in an external document as such


    <html
    xmlns="http://www.w3.org/1999/xhtml"
    profile="http://example.org/my-profile"
    >
    <head><title>a page about Fred</title></head>
    <body>
    <div about="#fred" typeof="foaf:Person vocab2:BiblioPerson" >
    <span property="foaf:name">Fred Flintstone</span>
    </div>
    </body>
    </html>

    Or you can combine profiles and vocabs


    <html
    xmlns="http://www.w3.org/1999/xhtml"
    vocab="http://xmlns.com/foaf/0.1/"
    profile="http://example.org/my-profile"
    >
    <head><title>a page about Fred</title></head>
    <body>
    <div about="#fred" typeof="Person vocab2:BiblioPerson" >
    <span property="name">Fred Flintstone</span>
    </div>
    </body>
    </html>

    Or you can define terms in a profile and do the following:


    <html>
    <head>
    <title>a page about Fred</title>
    </head>
    <body profile="http://example.org/my-profile">
    <div about="#fred" typeof="Person BiblioPerson" >
    <span property="name">Fred Flintstone</span>
    </div>
    </body>
    </html>

    And you can chain things together and reduce that to a single copy and pastable element:


    <html>
    <head><title>a page about Fred</title></head>
    <body>
    <span about="#fred" profile="http://example.org/my-profile" typeof="Person BiblioPerson" property="name">Fred Flintstone</span>
    </body>
    </html>

    But it’s probably worth noting that a typical document will be much bigger and the relevant snippet would be more like:


    <div about="#fred" typeof="vocab2:BiblioPerson">
    ...
    and my name is <em property="name">Fred Flintstone</em>
    ...

    As you can see RDFa 1.1 is a lot more flexible and allows you write markup in various different ways, providing enough attributes to hopefully handle any use case / preferred style.

    Best,

    Nathan

  4. What’s also nice is that you can use rel and rev to establish triples in both directions on the same element:

    <link about=”" rel=”foaf:maker dc:creator foaf:primaryTopic” rev=”foaf:made foaf:isPrimaryTopicOf” href=”http://danbri.org/foaf.rdf#danbri” />

  5. csarven.ca/ says:

    Not that I’m advocating the use of multiple vocabularies for something similar in nature, but, one reason why publishers might want to do that is to make sure that their target consumers make use of that data.

    AFAIK, this is a grey area and there is no perfect answer, yet, Should the publisher leave it up to external tools to fill in the gaps and make their own further conclusions about their data, or be explict as they can?

Leave a Reply