Introduction To RDF
In this section we introduce RDF, one of the foundational technologies of the RDFa implementation of rNews.
The Resource Description Language (aka RDF) is a data model useful for asserting facts about things. First proposed by the World Wide Web Consortium (W3C) in 1999, RDF models data using triples. A triple is a simple assertion about a thing made in the form of subject-verb-object statement. For instance, the following triple asserts that the subject "Stuart Myles" has the twitter handle "@smyles". Where "Stuart Myles" is the subject, "Has Twitter Handle" is the verb and "@smyles" is the object.
Of course, this being the real world, things are more slightly more complicated. While we might be content to refer to the subject "Stuart Myles" using the literal phrase "Stuart Myles", RDF expects you to be more rigorous. Rather than expressing subjects, verbs and sometimes the objects using messy literal values (i.e. text and numbers), RDF requires that you use Universal Resource Identifiers (URIs). So instead of calling our subject "Stuart Myles" we might call him http://www.iptc.org/authority/per/stuart_myles. Instead of referring to our our verb as "Has Twitter Handle" we might refer to it as "http://www.iptc.org/ns/1.0/has_twitter_handle. Using these URIs we can rewrite the illegitimate triple pictured above as the completely legitimate and proper triple:
There are a couple of details worth mentioning about URIs. First of all, from RDF's point of view a URI is nothing more than a name for a thing. There is no significance to the text of the URI itself. We could have called "Stuart Myles" http://foobar.com/QPG01VG and it wouldn't have made a bit of difference to RDF. The only requirement at all is that we assign a unique URI to the thing we're naming. No two different things should ever be referred to by the same URI.
A second point about URIs in RDF: even though they look an awful lot like web addresses (formally known as Uniform Resource Locators or URLs), RDF uses URIs for a completely different purpose. As previously mentioned RDF uses URIs to give names to things. The web on the other hand uses URLs to specify the location of resources. There is no requirement in RDF that a URI actually refer to a resource on the web. A URI is just a name.
Returning to our example. You've no doubt noticed that a name like http://www.iptc.org/ns/1.0/has_twitter_handle is rather cumbersome. Fortunately RDF includes the ability to condense unwieldily URI to a more readable Compact URI (CURIE). To transform "http://www.iptc.org/ns/1.0/has_twitter_handle" into a CURI you first declare a namespace prefix. In this case we'll define the namespace prefix iptcTerms = http://www.iptc.org/ns/1.0/. Using this prefix we can then rewrite the verb http://www.iptc.org/ns/1.0/has_twitter_handle as iptcTerms:has_twitter_handle. Compact URIs may be used to express any part of an RDF triple. Tying this all together, we can rewrite our example triple using a Compact URI for the verb as follows:
Now suppose we want to assert something about Stuart besides his twitter handle. For example, Stuart has his own blog at http://stuartmyles.blogspot.com and we want to model this fact in RDF. We simply assert another triple with the same subject as follows: A couple notes on terminology: a collection of triples share the that same subject is called a graph of triples. A triple with a literal-valued object (e.g. "@smyles") is called a data triple. A triple with a URI valued object (e.g. http://stuartmyles.blogspot.com) is called an object triple.
So far we've dealt with RDF on an abstract level, using pictures to visualize how RDF models data. As you probably have guessed, its more complicated than that in reality. Somewhat confusingly several standards exist for writing RDF data models to disk. For the purposes of this introduction we'll focus on a standard called Turtle. Using Turtle we can write down the above model as follows:
@prefix iptcTerms: <http://www.iptc.org/ns/1.0/> . <http://www.iptc.org/authority/per/stuart_myles> iptcTerms:has_twitter_handle "@smyles" ; iptcTerms:has_blog <http://stuartmyles.blogspot.com/>.
The Turtle syntax for expressing RDF data models is straightforward. A Turtle document opens with one or more @prefix declarations which establish the namespaces abbreviations for the Compact URIs we'll be using below. Next come the triples. In Turtle syntax the subject is written down just once, even if it is the subject of multiple triples. In the above example that subject is - of course - <http://www.iptc.org/authority/per/stuart_myles>. The subject is followed by one or more verb-object statements, such as iptcTerms:has_twitter_handle "@smyles" in the above example. Although this example has only one subject, it is perfectly legal for Turtle documents to have multiple subjects.
Now that we've told you a little bit about RDF, we'll move onto RDFa.
Want to comment on this page or rNews: we invite you to post your comment to the rNews Forum.