|Tutorial 2: Introducing RDF/XML|
Next: Semantic Modeling
If the graph data model is the model the semantic web uses to store data, RDF is the format in which it is written. In the first lesson, we looked at graph data and introduced RDF. Now, we go further and describe the groundwork you need to write graph data yourself using RDF/XML - one of the most popular RDF formats on the web.
After this tutorial, you should be able to:
You should have already understood the following tutorial (and pre-requisites) before you begin:
We then looked briefly at RDF (Resource Description Framework) format, and saw how it defined statements comprising a subject, a predicate (property), and an object. The subject->predicate->object relationship is called a triple. You also learned that RDF is the foundation upon which the web of semantic data is built.
During this lesson, you will learn step-by-step how to build your own RDF statements and understand them visually in a graph. This will then allow you to start thinking about adding semantics (meaning) to your data and understand the profound advantages this offers.
To do this best, let's build a simple RDF document, step-by-step.
2.1 Building An RDF Document
Add The RDF Document Root Tag
First, add the RDF root node:
If you look at line 02, you will see the standard W3.org namespace http://www.w3.org/1999/02/22-rdf-syntax-ns#. This namespace tells any machine reader that the enclosing document is an RDF document, and that the rdf:RDF tag resides in this namespace.
This namespace, and the RDF node, forms the root of all RDF documents.
Add A Statement
An RDF document can contain more than one statement. For simplicity, we'll only add one. Start by adding a an rdf:Description tag, which in RDF/XML can contain one or more statements about the same subject:
The rdf:Description tag simply means "I'm going to describe something (a subject) and I'm giving it the unique ID http://www.linkeddatatools.com/clothes#t-shirt".
There's no point in saying you're going to describe something, give it a unique ID but then not describe anything about it. RDF statements describe the characteristics of their subjects using properties, or predicates in RDF terminology.
For simplicity, let's start by adding one predicate: the size of our T-shirt.
See line 07. This simply says "The subject has a property with name feature:size which has the literal value 12". In RDF terminology, this is a statement.
Finally, let's add one more predicate: the color of the T-shirt.
You'll notice this one isn't quite the same as the last one. Whereas the last one had the literal value 12, this one is referring to the subject (ID) of another statement. That's right - objects in RDF can refer (reference) the subjects of other statements.
Remember A subject in an RDF document may also be referenced as a object of a property in another RDF statement (in the resource attribute). This can be a confusing concept for those starting out with RDF.
So this simply says "The subject has a property with name feature:color with object referring to the statement with ID http://www.linkeddatatools.com/colors#white".
2.2 Breaking Down The Statement
Now we've looked at a simple example of an RDF document, let's formalize what we've learned and break the statement into its component parts:
Here you see the subject of the statement (what the statement is about), and the two forms of predicates (literal values and resources, which reference other RDF statements).
Note The rdf:Description RDF/XML element allows you to group one or more statements into a single container. The above general form actually contains two statements referring to the same subject, but with two predicates and objects: a resource and a literal.
2.3 A More Thorough Example
Let's return to the more complex example we gave in our last lesson on graph data:
To test your understanding and point out any areas where you need to recap, see if you can identify on the RDF document above the:
Once you have understood RDF documents, and how they relate to data graphs, you are ready for our next lesson introducing the idea of modeling semantics into RDF graph data.
2.4 A Quick Recap Of URIs And XML Namespaces
Unique IDs that we've been using so far such as http://www.linkeddatatools.com/clothes#t-shirt are called Uniform Resource Identifiers, or URIs for short. We've been using URIs to give a unique ID to the subjects, predicates or objects of statements so far without really saying why.
Because URIs are so crucial to the driving purpose behind RDF - to make data exchangable globally - we will make a quick recap of URIs now. If you already understand URIs, you can skip this section.
XML Namespace URIs
Look back again at our example RDF document we've built. See that the T-shirt size predicate has the name feature:size on line 07 below:
On line 03, notice that we've defined the XML namespace feature by giving it the namespace URI http://www.linkeddatatools.com/clothing-features#.
The purpose of this namespace is simply to avoid name conflicts with tags of the same name: other tags with the name "size" could be defined with other namespace URIs, and an RDF reader would still be able to tell that they were different properties even though they had the same tag name.
To get a fully qualified URI for feature:size, simply substitute the prefix feature: with its namespace URI, obtaining the full name http://www.linkeddatatools.com/clothing-features#size.
Note XML namespace URIs in RDF are used to distinguish between properties with the same (tag) name. To get the fully qualified URI, simply substitute the namespace prefix with the namespace URI.
Now we can state the graph with fully qualified URIs.
As you can see, it's not always easy or convenient to represent URIs in full in RDF graph diagrams. Often, shorthand versions are used instead (i.e. only using the namespace prefix).
You have completed this lesson. You should now understand the following:
You should now be able to start the following tutorial: