Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Implement Semantic Web standards in your Web site

Discover what Semantic Web standards can do for your current or next Web site project

Rob Crowther (robert@crowther.info), Web developer, Freelance
Photo of Rob Crowther
Rob Crowther is a Web Developer from London and is currently moderator of the Exploring Semantic Web Technologies forum on developerWorks. He has a keen interest in Web Standards and blogs sporadically at http://www.boogdesign.com/b2evo/.

Summary:  With Yahoo's recent announcement that they will implement support of Semantic Web standards in their search engine, the benefits that the Semantic Web has for your site have never been clearer. In addition to the existing benefits such as your structured content giving you a free, open-ended API, you now get the opportunity for increased search rankings, and more importantly, increased relevance because the search engine can better understand what the content of your site is about. In this tutorial you will learn to implement a simple social networking site using PHP and MySQL, which will implement Semantic Web standards such as hCard and Friend of a Friend (FOAF) as part of a semantic Uniform Resource Identifier (URI) scheme.

Date:  20 May 2008
Level:  Intermediate PDF:  A4 and Letter (365 KB)Get Adobe® Reader®

Activity:  29791 views
Comments:  

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.

About this tutorial

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.

Frequently used acronyms

  • API: application programming interface
  • DTD: Document Type Definition
  • GRDDL: Gleaning Resource Descriptions from Dialects of Languages
  • HTML: HyperText Markup Language
  • PHP: PHP Hypertext Preprocessor
  • RDF: Resource Description Framework
  • UI: User Interface
  • W3C: World Wide Web Consortium
  • XHTML: Extensible Hypertext Markup Language
  • XML: Extensible Markup Language

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 RewriteRule and 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 are:

  • 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.


Prerequisites

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.

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML, Web development, Open source
ArticleID=309094
TutorialTitle=Implement Semantic Web standards in your Web site
publish-date=05202008
author1-email=robert@crowther.info
author1-email-cc=dwxed@us.ibm.com