Before you start
By reading this tutorial you will learn practical details of how to implement a semantic URI scheme, the conceptual structure of the pages of your Web site, and how to apply microformats and RDFa to your markup to add semantic value to your Web pages. The tutorial will focus on certain aspects of Apache configuration and the rendered HTML, rather than the PHP and MySQL itself, so even if you only have a superficial understanding of those two technologies, you can still follow along.
This tutorial shows you how to use Semantic Web technologies in the context of a very simple social networking site, SemanticBook (see Prerequisites to access the site). SemanticBook represents your friends by a URI that you can use on any other site, allowing your network of friends to be embedded into a wider network across multiple sites. Given that FOAF is used, the user's data becomes portable, and is easily extracted for use in other applications. For instance, SemanticBook allows you to easily add your friend's contact details to an e-mail client such as Yahoo! Mail. You will develop practical code to build semantic URI schemes, structure your HTML output to allow the contact details of your users to be easily exported from their Web page, and indicate the users relationships through Semantic Web standard formats.
You'll start with a quick introduction to the Semantic Web before you see how to use
Apache's mod_rewrite to decouple the URIs of your Web application from the physical
files that implement. To do this, you will use
RewriteCond directives to build a URI scheme that
reflects the conceptual model rather than the layout of your files on disk. You will
then look at using the hCard microformat to markup the contact information of the users
in a portable way, and see how you can already use that information in browsers today as
well as extract RDF data from it using GRDDL. Finally, you'll look at the FOAF, an
RDF-based vocabulary for describing people and relationships, and see how you can
incorporate that directly into your XHTML using RDFa. The main sections of the tutorial
- A quick introduction to the Semantic Web
- Implement a semantic URI scheme
- Represent the user's contact information with hCard
- Represent the user's network with FOAF
This tutorial uses two different Semantic Web standards: Microformats and RDFa/FOAF. Microformats are a grass roots movement, and are not backed by an official standards body, but are designed to solve specific common problems in semantic data representation. RDFa/FOAF is based on the W3C's RDF standard, a more general attempt to allow the representation of any and all human knowledge. Because I chose relatively straightforward examples, users and their networks, to represent semantically in this tutorial, I might have exclusively used either all microformats or all RDF. There are microformat equivalents to FOAF, while FOAF itself can be used for the same type of data as the hCard microformat. Of course, the point of this tutorial is for you to learn things, so I used both in SemanticBook. Some of the differences and advantages of each are discussed in a sidebar; after you've had a chance to meet some of the implementation details in the context of the SemanticBook social network.
You will need these tools to follow along with this tutorial:
- The main tool required is a text editor. One that has some support for HTML and XML syntax is best.
- PHP —I used Version 4.4.8 in this tutorial, but more recent versions work equally well.
- Apache server —Version 2.0.63.
- MySQL —I used Version 4.1.22, but anything more recent is fine.
- Test your microformats with the Operator Add-On for Firefox.
Installing Apache PHP and MySQL explains how to get everything installed on Windows.
See the SemanticBook application in action.