W3C

Best Practice Recipes for Publishing RDF Vocabularies

Editor's Draft 01 December 2008

This version:
http://www.w3.org/2006/07/SWD/recipes/draft-20081201.html
Latest version:
http://www.w3.org/TR/swbp-vocab-pub/
Previous version:
http://www.w3.org/TR/2008/NOTE-swbp-vocab-pub-20080828/
Editors:
Diego Berrueta, Fundación CTIC
Jon Phipps, Cornell University Library
Previous Editors:
Alistair Miles, STFC Rutherford Appleton Laboratory
Thomas Baker, Goettingen State and University Library
Ralph Swick, W3C

Please refer to the errata for this document, which may include some normative corrections.


Abstract

This document describes best practice recipes for publishing vocabularies or ontologies on the Web (in RDF Schema or OWL). The features of each recipe are described in detail, so that vocabulary designers may choose the recipe best suited to their needs. Each recipe introduces general principles and an example configuration for use with an Apache HTTP server (which may be adapted to other environments). The recipes are all designed to be consistent with the architecture of the Web as currently specified, although the associated example configurations have been kept intentionally simple.

Status of this Document

This document is for review by the Semantic Web Deployment Working Group (SWD) and is subject to change without notice. This document has no formal standing within W3C. Please consult the group's home page and the W3C technical reports index for information about the latest publications by this group.

Table of Contents


Introduction

This document is intended for the creators and maintainers of vocabularies in RDFS and OWL (vocabulary and ontology are used interchangeably in the context of this specification). It provides step-by-step instructions for publishing vocabularies on the Web, giving example configurations designed to cover the most common cases. For more information about RDFS and OWL see [RDFS, RDFPrimer, OWLGuide, OWLFeatures].

This “cookbook” gives “recipes” describing the steps needed to publish a vocabulary on a Web server, and to configure the Web server to support Semantic Web applications. The section “Choosing a recipe” provides guidance for choosing the most appropriate recipe depending on the situation and requirements. Once the recipe has been chosen, the reader can follow the steps, adapting the examples for a particular vocabulary.

All of the recipes give example configurations for the Apache HTTP server [APACHE20]. For those not already familiar with Apache configuration, the appendix on Apache configuration provides a short introduction to the Apache configuration mechanisms used in the examples and basic information on troubleshooting.

While the provided configuration examples are specific to an Apache HTTP server, the general principles apply to non-Apache environments as well. The Working Group invites contributions of additional bindings for non-Apache servers. The W3C has provided a wiki page to collect these non-Apache bindings and recommendations.

This document is primarily intended for creators and maintainers of existing vocabularies who are looking for guidance on how their vocabularies should best be published on the Web. It is not intended to provide detailed and exhaustive guidance on choosing an appropriate URI namespace for naming a new vocabulary and its constituent terms. However, some basic technical information about URI namespaces, including some considerations relevant to choosing a URI namespace for a vocabulary, is given in the section on URI namespaces.

The recipes have all been designed to be consistent with the architectural principles of the World Wide Web as currently specified in the document "Architecture of the World Wide Web" [AWWW04]. In order to verify that they are in fact so, a set of minimum requirements is described at the end of this document. These minimum requirements are intended to articulate the fundamental requirements of Semantic Web applications. All of the recipes when correctly implemented should satisfy the minimum requirements. A set of extended requirements is also given. The extended requirements are intended to articulate further practical needs of Semantic Web application developers, such as providing documentation about a vocabulary on Web pages in HTML. Recipes 3, 4, 5 and 6, when correctly implemented, should satisfy the extended requirements.

In order to satisfy the extended requirements, the recipes 3, 4, 5, and 6 configure a server to perform content negotiation. A brief explanation of this process is given in the section on content negotiation, along with a description of some options for coping with variability in deployed client behavior.

Appendix A describes how to adapt the six recipes given in the main body of the document for the special case of vocabularies identified using "persistent URLs", or PURLs, which are resolved using PURL services such as http://purl.org/ [PURL].

For brevity, the rationale behind each of the recipes is not described in this document. Readers wishing to go deeper should consult URI/Resource Relationships in "Architecture of the World Wide Web" [AWWW04], fragment identifiers in HTTP URIs [RFC3986] [RFC2616], the W3C Interest Group Note: "Cool URIs for the Semantic Web" [COOLURI], and the W3C Technical Architecture Group's resolution on the range of HTTP dereferencing (aka "httpRange-14"). [HTTPRANGE14]

Finally, it should be noted that the Recipes described in this Cookbook are not the only way to publish a vocabulary or ontology for use by Semantic Web applications. RDFa and its cousin GRDDL may in the near future provide an effective method for publishing documents for use by both people and machines. But a useful discussion of RDFa and GRDDL is well beyond the scope of this document.


Choosing a recipe

The choice of recipe depends primarily on what types of content you wish to provide from your vocabulary URI and the URIs of the classes and properties defined by your vocabulary. URI namespaces are described in more detail in Appendix B; throughout this document, the expression "vocabulary URI" can be interpreted as "vocabulary namespace URI".

Quick Selection Table

Configuration hash namespace slash namespace
Machine processable RDF Recipe 1 Recipe 2
Machine processable RDF (using PURLs) Recipe 1a Recipe 2a
RDF and Single HTML document Recipe 3 Recipe 4
RDF and Single HTML document (using PURLs) Recipe 3a Recipe 4a
RDF and Multiple HTML documents   Recipe 5 or Recipe 6
RDF and Multiple HTML documents(using PURLs)   Recipe 5a

 

Simple configuration

The simplest recipes configure your server to provide only machine-processable (RDF) content from the vocabulary URI.

If you are using a hash namespace see Recipe 1 or, if using PURLs, Recipe 1a.

If you are using a slash namespace see Recipe 2 or, if using PURLs, Recipe 2a.

Extended configuration

The extended recipes configure your server to provide both machine-processable (RDF) and human-readable (HTML) content (see also the section content negotiation below). These recipes are easily extended to serve additional content types.

If you are using a hash namespace and want to provide both RDF and HTML content, see Recipe 3 or, if using PURLs, Recipe 3a.

If you are using a slash namespace and want to provide both RDF and HTML content, where the HTML content is contained in a single document, see Recipe 4 or, if using PURLs, Recipe 4a.

If you are using a slash namespace and want to provide both RDF and HTML content, where the HTML content is served as individual hyperlinked documents for each class or property, with an overview (e.g. a table of contents or an index) at the vocabulary URI, see Recipe 5 or, if using PURLs, Recipe 5a.

If you are using a slash namespace and want to provide both RDF and HTML content, where the HTML content is served as individual hyperlinked documents for each class or property, and where the RDF is served as bounded descriptions of each class or property, see Recipe 6.


Content negotiation

When an HTTP client attempts to dereference a URI, it can specify which type (or types) of content it would prefer to receive in response. It does this by including an 'Accept:' field in the header of the request message, the value of which gives MIME types corresponding to preferred content types. For example, an HTTP client that prefers RDF/XML content might include the following field in the header of each request:

Accept: application/rdf+xml

Similarly, an HTTP client that prefers HTML content, such as a Web browser, might include something like the following field in the header of each request:

Accept: application/xhtml+xml,text/html

It is accepted as a principle of good practice that HTTP clients SHOULD include an 'Accept:' field in a request header, explicitly specifying those content types that may be handled.

When the server receives a request, it can use the value(s) of the 'Accept:' field to select the most appropriate response from those available, attempting to meet the preference of the client as closely as possible. This process is an example of content negotiation [AWWW04].

Recipes 1 and 2 below do not configure the server to perform any content negotiation. RDF/XML is the only representation type available, and is provided irrespective of the value of the 'Accept:' header sent by the client.

Recipes 3, 4, 5 and 6 below do configure the server to perform content negotiation based on the value of the 'Accept:' header field sent by the client. However, the proposed configuration examples do not handle the full HTTP specification with respect to content negotiation. Actually, although the examples accommodate some client ordering preferences in content negotiation, they do not handle the 'q' metrics. Therefore, HTTP clients which use q-values in the 'Accept' header may obtain unexpected results.

Editor's note: The Working Group is considering alternatives to be fully compliant with the HTTP specification, while keeping the recipes as simple as possible. This is recorded as ISSUE-58 in the Working Group's issue process. Comments on this issue are invited, and should be sent in an email to the SWD Working Group, starting the subject line with "Comment: ISSUE-58".

Default behavior

When the server is configured to perform content negotiation, a 'default behavior' must be specified -- the server must be able to determine which response should be sent in the cases where:

  1. the client does not include an 'Accept:' field in the request message header (i.e. the client doesn't specify a preference)
  2. the values of the 'Accept:' field do not match any of the available content types (i.e. the client asks for something other than RDF/XML or HTML).

In recipes 3, 4, 5, and 6 below, RDF/XML is configured as the default response. This is chosen to minimize the impact on deployed Semantic Web applications that do not currently send appropriate 'Accept:' header field values for RDF content. Bear in mind that if HTML is configured as the default response, some existing Semantic Web applications expecting to receive RDF content will receive HTML content instead, and will break.

Providing an 'Accept:' header

Developers and maintainers of Semantic Web applications that expect to process RDF content, and that do not currently provide an 'Accept:' header field in HTTP requests, should plan to provide such a header in the future.

A suitable value of the 'Accept:' field is as follows:

Accept: application/rdf+xml,application/xml;q=0.5

The 'q=0.5' value in the above example indicates a relative quality value as specified by Section 14 the HTTP 1.1 protocol [RFC2616]. The default 'q' value if none is specified is 1.0. This example can be read as "I prefer 'application/rdf+xml, giving it the default relative quality value of 1.0, but will still accept application/xml, although I consider it to be only 50% of the value of application/rdf+xml".

Special Default Behavior for Internet Explorer

Unlike most other browsers, Internet Explorer sends 'Accept:' headers containing a catch-all */* without a mediating 'q' value. In contrast, both Firefox and Safari accept */*;q=0.5, and Opera accepts */*;q=0.1. Establishing a default behavior that takes this into account requires the insertion of a rewrite condition based on the value of the 'User-agent:' header field:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*

Additionally, if you also want to retain 'clickable' URIs in IE, you must set HTML as the default response (see comments in examples for instructions on how to do this).

Server configuration testing

Effectively testing the results of content negotiation can become fairly complex for some of the Recipes. In order to facilitate the testing of the results of content negotiation on a single URI a content negotiation testing service has been established.

This service will request a provided URI from a server, run a test suite specifically designed to test the response of the server against the Recipe specifications, and display a pass/fail report on each set of tests as well as a detailed explanation of its findings.

The source code for the testing service is also available.


Recipe 1. Minimal configuration for a 'hash namespace'

Jump straight to: Example configuration | Testing the configuration

This recipe gives an example of the simplest possible configuration for a vocabulary that uses a hash namespace. The recipe configures the server to provide machine-processable (RDF) content from the vocabulary URI, thereby satisfying the minimum requirements. This is illustrated by the following diagram:

Dereference the vocabulary URI

client-server interaction

(Serve the RDF description of the vocabulary, encoded as RDF/XML.)

Example Configuration

For a vocabulary …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example1

defining classes …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example1#ClassA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example1#ClassB

and properties …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example1#propA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example1#propB

Step 1

Create a file called example1.rdf that contains a complete RDF/XML serialization of the vocabulary. I.e. all resources defined by the vocabulary are described in this file.

Step 2

Copy the example1.rdf file to the /apachedocumentroot/examples/ directory on the server.

Step 3

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory on the server:

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to serve RDF/XML content from the vocabulary URI
RewriteRule ^example1$ example1.rdf

(N.B. If a .htaccess file does not exist, create one.)

Testing the Configuration

If this configuration is working, it should support the following interactions:

Dereference the vocabulary URI

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example1 HTTP/1.1
Host: example.com

Response header should contain the following fields:

HTTP/1.x 200 OK
Content-Type: application/rdf+xml

Recipe 2. Minimal configuration for a 'slash namespace'

Jump straight to: Example configuration | Testing the configuration

This recipe gives an example of the simplest possible configuration for a vocabulary that uses a slash namespace. The recipe configures the server to provide machine-processable (RDF) content from the vocabulary URI, and to redirect the client to the vocabulary URI from class and property URIs, thereby satisfying the minimum requirements. This is illustrated by the following diagrams:

Dereference the vocabulary URI

Example 2 client-server interaction.

(Serve the RDF description of the vocabulary, encoded as RDF/XML.)

Dereference the URI of a class or property

Example 2 client-server interaction.

(Redirect the client to the vocabulary URI.)

Example Configuration

For vocabulary …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example2/

defining classes …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example2/ClassA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example2/ClassB

and properties …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example2/propA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example2/propB

Step 1

Create a file called example2.rdf that contains a complete RDF/XML serialization of the vocabulary. I.e. all resources defined by the vocabulary are described in this file.

Step 2

Copy the example2.rdf file to the /apachedocumentroot/examples/ directory on the server.

Step 3

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory on the server:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to redirect 303 from any class or prop URI
RewriteRule ^example2/.+ example2/ [R=303]

# Rewrite rule to serve RDF/XML content from the vocabulary URI
RewriteRule ^example2/$ example2.rdf

(N.B. If a .htaccess file does not exist, create one.)

The directory option 'MultiViews' must be disabled for this configuration to work, and a directory called /apachedocumentroot/examples/example2/ must not actually exist on the server's file system.

Testing the Configuration

If this configuration is working, it should support the following interactions:

Dereference the vocabulary URI

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example2/ HTTP/1.1
Host: example.com

Response header should contain the following fields:

HTTP/1.x 200 OK
Content-Type: application/rdf+xml

Dereference the URI of a class or property

Test message (substitute correct path and host for your class or property URI):

GET /examples/example2/ClassA HTTP/1.1
Host: example.com

Response header should contain the following fields, with your vocabulary URI as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example2/

Recipe 3. Extended configuration for a 'hash namespace'

Jump straight to: Example configuration | Testing the configuration | Notes

This recipe gives an example of an extended configuration for a vocabulary with a hash namespace. The recipe configures the server to provide either human-readable (HTML) or machine-processable (RDF) content from the vocabulary URI, depending on what is requested, thereby satisfying the extended requirements. This is illustrated by the following diagrams:

Dereference the vocabulary URI, requesting HTML content

client-server interaction

(Redirect the client to current HTML documentation for the vocabulary.)

Dereference the vocabulary URI, requesting RDF content

client-server interaction

(Redirect the client to the current RDF description of the vocabulary.)

Example Configuration

For vocabulary …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example3

defining classes …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example3#ClassA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example3#ClassB

and properties …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example3#propA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example3#propB

Step 1

Create a file called 2005-10-31.rdf that contains a complete RDF/XML serialization of the vocabulary, as at 2005-10-31 (or whatever the current date is). I.e. all resources defined by the vocabulary are described in this file, and this file represents a 'snapshot' or 'version' of the vocabulary.

Step 2

Create a file called 2005-10-31.html that contains HTML content documentation about all classes and properties defined by the vocabulary as at 2005-10-31 (or whatever the current date is). This document may include sections for each of the classes/properties documented, each section being headed by an HTML anchor whose name is identical to the fragment identifier of the documented class or property.

Step 3

Copy 2005-10-31.rdf and 2005-10-31.html to the directory /apachedocumentroot/examples/example3-content/ on the server.

Step 4

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to serve HTML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example3$ example3-content/2005-10-31.html [R=303]

# Rewrite rule to serve RDF/XML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^example3$ example3-content/2005-10-31.rdf [R=303]

# Choose the default response
# ---------------------------

# Rewrite rule to serve the RDF/XML content from the vocabulary URI by default
RewriteRule ^example3$ example3-content/2005-10-31.rdf [R=303]

# Rewrite rule to serve HTML content from the vocabulary URI by default (disabled)
# (To enable this option, uncomment the rewrite rule below, and comment
# out the rewrite rule directly above)
# RewriteRule ^example3$ example3-content/2005-10-31.html [R=303]

(N.B. If a .htaccess file does not exist, create one.)

Testing the Configuration

If this configuration is working, it should support the following interactions:

Dereference the vocabulary URI, requesting HTML content

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example3 HTTP/1.1
Host: example.com
Accept: text/html

Response header should contain the following fields, with your HTML content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example3-content/2005-10-31.html

Dereference the vocabulary URI, requesting RDF content

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example3 HTTP/1.1
Host: example.com
Accept: application/rdf+xml

Response header should contain the following fields, with your current RDF content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example3-content/2005-10-31.rdf

Dereference the vocabulary URI, default case

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example3 HTTP/1.1
Host: example.com

Response header should contain the following fields, with your current RDF content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example3-content/2005-10-31.rdf

Notes

This example uses the modification date of the vocabulary version to create file names. It would also be possible to use version numbers (e.g. '1.01') instead of dates for this purpose, or indeed any convention that makes it possible to differentiate between vocabulary versions, and helps to keep track of version history.

See also the section on content negotiation.


Recipe 4. Extended configuration for a 'slash namespace', using a single HTML document

Jump straight to: Example configuration | Testing the configuration | Notes

This recipe gives an example of an extended configuration for a vocabulary with a slash namespace. The recipe configures the server to provide either human-readable (HTML) or machine-processable (RDF) content from the vocabulary URI, depending on what is requested, and to redirect the client from class and property URIs to the appropriate content locations, again depending on what is requested, thereby satisfying the extended requirements. The HTML documentation is served as a single file. This behavior is illustrated by the following diagrams:

Dereference the vocabulary URI, requesting HTML content

client-server interaction

(As per Recipe 3, redirect the client to current HTML documentation for the vocabulary.)

Dereference the vocabulary URI, requesting RDF content

client-server interaction

(As per Recipe 3, redirect the client to the current RDF description of the vocabulary.)

Dereference the URI of a class or property, requesting HTML content

client-server interaction

(Redirect the client to the fragment of current HTML documentation for the vocabulary relevant to the class or property.)

Dereference the URI of a class or property, requesting RDF content

client-server interaction

(Redirect the client to the current RDF description of the vocabulary.)

Example Configuration

For vocabulary …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example4/

defining classes …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example4/ClassA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example4/ClassB

and properties …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example4/propA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example4/propB

Step 1

Create a file called 2005-10-31.rdf that contains a complete RDF/XML serialization of the vocabulary, as at 2005-10-31 (or whatever the current date is). I.e. all resources defined by the vocabulary are described in this file, and this file represents a 'snapshot' or 'version' of the vocabulary.

Step 2

Create a file called 2005-10-31.html that contains HTML content documentation about all classes and properties defined by the vocabulary as at 2005-10-31 (or whatever the current date is). This document may include sections for each of the classes/properties documented, each section being headed by an HTML anchor whose name is identical to the fragment identifier of the documented class or property.

Step 3

Copy 2005-10-31.rdf and 2005-10-31.html to the directory /apachedocumentroot/examples/example4-content/ on the server.

Step 4

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to serve HTML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example4/$ example4-content/2005-10-31.html [R=303]

# Rewrite rule to serve directed HTML content from class/prop URIs
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example4/(.+) example4-content/2005-10-31.html#$1 [R=303,NE]

# Rewrite rule to serve RDF/XML content if requested
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^example4/ example4-content/2005-10-31.rdf [R=303]

# Choose the default response
# ---------------------------

# Rewrite rule to serve RDF/XML content by default
RewriteRule ^example4/ example4-content/2005-10-31.rdf [R=303]

# Rewrite rules to serve HTML content by default (disabled)
# (To enable this option, uncomment the two rewrite rules below,
# and comment out the rewrite rule directly above)
# RewriteRule ^example4/$ example4-content/2005-10-31.html [R=303]
# RewriteRule ^example4/(.+) example4-content/2005-10-31.html#$1 [R=303,NE]
 

(N.B. If a .htaccess file does not exist, create one.)

For this configuration to work, the directory option 'MultiViews' must be disabled, and a directory called /apachedocumentroot/examples/example4/ must not actually exist on the server's file system.

Testing the Configuration

If this configuration is working, it should support the following interactions:

Dereference the vocabulary URI, requesting HTML content

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example4/ HTTP/1.1
Host: example.com
Accept: text/html

Response header should contain the following fields, with your HTML content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example4-content/2005-10-31.html

Dereference the vocabulary URI, requesting RDF content

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example4/ HTTP/1.1
Host: example.com
Accept: application/rdf+xml

Response header should contain the following fields, with your RDF content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example4-content/2005-10-31.rdf

Dereference the vocabulary URI, default case

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example4/ HTTP/1.1
Host: example.com

Response header should contain the following fields, with your RDF content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example4-content/2005-10-31.rdf

Dereference the URI of a class or property, requesting HTML content

Test message (substitute correct path and host for your class or property URI):

GET /examples/example4/ClassA HTTP/1.1
Host: example.com
Accept: text/html

Response header should contain the following fields, with your HTML content location (plus appropriate fragment identifier) as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example4-content/2005-10-31.html#ClassA

Dereference the URI of a class or property, requesting RDF content

Test message (substitute correct path and host for your class or property URI):

GET /examples/example4/ClassA HTTP/1.1
Host: example.com
Accept: application/rdf+xml

Response header should contain the following fields, with your RDF content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example4-content/2005-10-31.rdf

Dereference the URI of a class or property, default case

Test message (substitute correct path and host for your class or property URI):

GET /examples/example4/ClassA HTTP/1.1
Host: example.com

Response header should contain the following fields, with your RDF content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example4-content/2005-10-31.rdf

Notes

As with Recipe 3, this example uses the modification date of the vocabulary version to create file names. It would also be possible to use version numbers (e.g. '1.01') instead of dates for this purpose, or indeed any convention that makes it possible to differentiate between vocabulary versions, and helps to keep track of version history.

See also the section on content negotiation.


Recipe 5. Extended configuration for a 'slash namespace', using multiple HTML documents

Jump straight to: Example configuration | Testing the configuration | Notes

This recipe gives an example of an extended configuration for a vocabulary with a slash namespace. The recipe configures the server to provide both machine-processable (RDF) and human-readable (HTML) content, depending on what is requested, with the HTML documentation being given as multiple hyperlinked HTML documents plus an overview document. This behavior is illustrated by the following diagrams:

Dereference the vocabulary URI, requesting HTML content

client-server interaction

(Redirect the client to current HTML overview documentation for the vocabulary.)

Dereference the vocabulary URI, requesting RDF content

client-server interaction

(As per Recipe 3 and Recipe 4, redirect the client to the current RDF description of the vocabulary.)

Dereference the URI of a class or property, requesting HTML content

client-server interaction

(Redirect the client to current HTML documentation for the class or property.)

Dereference the URI of a class or property, requesting RDF content

client-server interaction

(As per Recipe 4, redirect the client to the current RDF description of the vocabulary.)

Example Configuration

For vocabulary …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example5/

defining classes …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example5/ClassA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example5/ClassB

and properties …

http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example5/propA
http://www.w3.org/2006/07/SWD/recipes/examples-20080421/example5/propB

Step 1

Create a file called 2005-10-31.rdf that contains a complete RDF/XML serialization of the vocabulary, as at 2005-10-31 (or whatever the current date is). I.e. all resources defined by the vocabulary are described in this file, and this file represents a 'snapshot' or 'version' of the vocabulary.

Step 2

Copy 2005-10-31.rdf to the directory /apachedocumentroot/examples/example5-content/ on the server.

Step 3

Create files ClassA.html ClassB.html propA.html propB.html each of which contains HTML content documentation relevant to the class or property with the corresponding local name, as at 2005-10-31 (or whatever the current date is). Create a file index.html that contains HTML content documentation about the vocabulary itself, with hyperlinks to all class or property documentation.

Step 4

Copy ClassA.html ClassB.html propA.html propB.html and index.html to the directory /apachedocumentroot/examples/example5-content/2005-10-31-docs/ on the server.

Step 5

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule 1: to serve HTML content from the namespace URI if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example5/$ example5-content/2005-10-31-docs/index.html [R=303]

# Rewrite rule 2: to serve HTML content from class or prop URIs if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example5/(.+) example5-content/2005-10-31-docs/$1.html [R=303]

# Rewrite rule 3: to serve RDF content is requested
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^example5/ example5-content/2005-10-31.rdf [R=303]

# Choose the default response
# ---------------------------

# Rewrite rule 4: to serve RDF/XML content by default
RewriteRule ^example5/ example5-content/2005-10-31.rdf [R=303]

# Rewrite rules to serve HTML content by default (disabled)
# (To enable this option, uncomment the two rewrite rules below,
# and comment out the rewrite rule directly above)
# RewriteRule ^example5/$ example5-content/2005-10-31-docs/index.html [R=303]
# RewriteRule ^example5/(.+) example5-content/2005-10-31-docs/$1.html [R=303]

(N.B. If a .htaccess file does not exist, create one.)

Testing the Configuration

If this configuration is working, it should support the following interactions:

Dereference the vocabulary URI, requesting HTML content

Test message (substitute correct path and host for your vocabulary URI):

GET /examples/example5/ HTTP/1.1
Host: example.com
Accept: text/html

Response header should contain the following fields, with your HTML overview content location as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example5-content/2005-10-31-docs/index.html

Dereference the vocabulary URI, requesting RDF content

Same as Recipe 4.

Dereference the vocabulary URI, default case

Same as Recipe 4.

Dereference the URI of a class or property, requesting HTML content

Test message (substitute correct path and host for your class or property URI):

GET /examples/example5/ClassA HTTP/1.1
Host: example.com
Accept: text/html

Response header should contain the following fields, with the HTML content location for the given class or property as the value of the 'Location' field:

HTTP/1.x 303 See Other
Location: http://example.com/examples/example5-content/2005-10-31-docs/ClassA.html

Dereference the URI of a class or property, requesting RDF content

Same as Recipe 4.

Dereference the URI of a class or property, default case

Same as Recipe 4.

Notes

See also the section on content negotiation.

As with Recipe 3, this example uses the modification date of the vocabulary version to create file names. It would also be possible to use version numbers (e.g. '1.01') instead of dates for this purpose, or indeed any convention that makes it possible to differentiate between vocabulary versions, and helps to keep track of version history.

If you have the directory options Indexes and MultiViews enabled for the directory /apachedocumentroot/examples/example5-content/2005-10-31-docs/ then you can replace the rewrite rules 1 and 2 with one single rewrite rule:

RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example5/(.*) example5-content/2005-10-31-docs/$1 [R=303]

This configuration is particularly suited to the use of documentation generated by the OWLDoc plugin for Protege.


Recipe 6. Extended configuration for a 'slash namespace', using multiple HTML documents and a query service

This recipe gives an example of an extended configuration for a vocabulary with a slash namespace. The recipe configures the server to provide both machine-processable (RDF) and human-readable (HTML) content, depending on what is requested, with the HTML documentation being given as multiple hyperlinked HTML documents plus an overview document, and the RDF content being made available via a query service such that clients can obtain a partial RDF description of the vocabulary as appropriate.

Despite the fact that this recipe shares nearly all of the features of Recipe 5, the use of a query service or script to retrieve RDF content makes it arguably the most complex of the extended configurations and presents the greatest challenge to providing a directly usable recipe. So we have decided to present this recipe as a set of suggested implementation patterns rather than a 'just follow the numbers' recipe. Moreover, we do not describe a particular implementation pattern in the same level of detail employed in the other recipes. Consequently, some web programming knowledge is required to implement this recipe.

Pattern 1: Using application logic

This pattern relies on some application logic deployed in the web server. This logic can be a thin layer that simply redirects the requests (or acts as a proxy) to a third-party web server (see the DBPedia example below), or a thick layer that loads an RDF datasource and translates the HTTP requests into API calls to execute the queries.

There are two alternatives to introducing server-side logic:

  1. Script on the server-side.
    Common server-side script languages (PHP, Python, Perl, Ruby) have RDF APIs and bindings with RDF stores, and can be used to write a simple script that queries an RDF file or RDF triple store and returns the relevant portion.
  2. Java Servlet (or equivalent).

Sample implementation (valid for both alternatives 1 and 2).

The DBPedia server is used in the following example as the content provider:

RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteRule ^example6/(.+) http://dbpedia.org/page/$1 [R=303]

RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^example6/(.+) http://dbpedia.org/data/$1 [R=303]

RewriteRule ^example6/(.+) http://dbpedia.org/data/$1 [R=303]

This is an example of a 'thin' implementation layer and the rewrite rules are straightforward:

  1. Requests for HTML data are forwarded to the URL of the HTML version exported by the DBPedia servlet;
  2. Requests for RDF data (or without an 'Acccept:' header since returning RDF is the default behavior) are forwarded to the URL of the RDF data.

The trickiest part of implementing Recipe 6 using application logic is to correctly implement HTTP content-negotiation from scratch. While most web scripting languages (PHP, Python, etc.) and frameworks provide access to the value of the HTTP headers and thus, to the 'Accept:' header, choosing the appropriate return type is far from trivial. The 'Accept:' header may contain wildcards and q-values, so regular expressions or simple string comparison functions are not enough. There is a wiki page with pointers to content negotiation libraries for different programming languages. The Working Group invites contributions of additional libraries and frameworks that support content negotiation.

Pattern 2: Redirecting to a SPARQL endpoint using Apache

This pattern does not involve writing any application logic. Instead, requests are HTTP-redirected using Apache mod_rewrite. This technique is particularly well-suited to wrap an existing SPARQL endpoint. We exploit the fact that many SPARQL endpoints export HTTP bindings.

Sample implementation:

RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteRule ^example6/(.+) http://dbpedia.org/$1 [R=303]

RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^example6/(.+) http://dbpedia.org/sparql?query=DESCRIBE+<http://dbpedia.org/$1> [R=303]

RewriteRule ^example6/(.+) http://dbpedia.org/sparql?query=DESCRIBE+<http://dbpedia.org/$1> [R=303]

In this example, when the client asks for HTML content, the request is forwarded to an external web server. However, RDF requests are handled differently. A request for a URI such as http://example.org/example6/property/birthplace is redirected to the result of executing a DESCRIBE <http://dbpedia.org/property/birthplace> sentence against the DBPedia SPARQL endpoint. The result is an RDF graph which describes the resource (in this particular case, the property that links people to the place where they were born).

Case studies


Requirements

This section attempts to articulate the requirements and expectations of Semantic Web applications and application developers with respect to the HTTP behavior of vocabularies, classes, and properties denoted by HTTP URIs (i.e., URIs from the http: URI space). It is intended as a benchmark against which the example configurations given in the recipes above may be verified.

Minimum Requirements

M1. The 'authoritative' RDF description of a vocabulary, class, or property denoted by an HTTP URI can be obtained by dereferencing the URI of that vocabulary, class, or property.

An HTTP client can obtain the 'authoritative' RDF description of a vocabulary, class, or property by performing an HTTP GET request against the URI of that vocabulary, class or property. The RDF description is returned as an HTTP response whose content type is a registered MIME type for RDF content (currently only 'application/rdf+xml').

This is the default behavior in the case that some form of content negotiation has been implemented for these URIs. I.e. an HTTP GET request without an 'Accept:' header field will result in a response with content type 'application/rdf+xml', which is a serialization of a set of RDF statements, including those statements that constitute the 'authoritative' RDF description of the denoted resource.

N.B. it is reasonable for an attempt to dereference the URI of an RDF property or class to result in an RDF description of more than just that property or class.

M2. The behavior of an HTTP URI denoting an RDFS/OWL vocabulary, class or property, does not lead to inconsistency in the interpretation of the nature of the denoted resource.

Currently the architecture of the Web allows applications to draw inferences about the nature of a resource denoted by an HTTP URI, based on the following:

(i) The HTTP response code obtained when dereferencing the URI (see the resolution of TAG issue 'httpRange-14' [HTTPRANGE14] ),

and …

(ii) Where the URI contains a fragment identifier, the content type(s) of the available representations [AWWW04].

Given these constraints, for each HTTP URI denoting an RDFS/OWL vocabulary, class or property, the range of possible responses to HTTP requests against that URI will not lead applications to draw any inconsistent conclusions.

Extended Requirements

These requirements are an extension of the minimum requirements.

E1. 'Human-readable' documentation about an RDF vocabulary, class or property, denoted by an HTTP URI, can be obtained by dereferencing the URI of that vocabulary, class or property.

An HTTP client such as a Web browser can obtain 'human-readable' documentation relating to an RDFS/OWL vocabulary, class or property, by performing an HTTP GET request against the URI of that vocabulary, class or property, specifying 'Accept:' headers appropriate to the desired content type in the request.

E2. Applications are able to differentiate between 'versions' of a vocabulary.

Vocabularies change over time as properties or classes are added or their descriptions are editorially changed. Applications need a way to differentiate between successive 'snapshots' of the vocabularies over time. To be precise, what is "versioned" is the description of a property -- i.e., a set of RDF statements about the property -- rather than the property itself, the URI of which does not change.

Conventions in common use for distinguishing successive descriptions include the use of version-number strings or date strings in filenames (e.g., 1.01.rdf or 2005-10-31.rdf) or in pathnames (e.g., http://dublincore.org/2008/01/14/dcelements.rdf#title). It should be noted that, at present, there are no generally accepted conventions for using date or version-number strings in this way.


Acknowledgments

The examples attempt to distill elements of good practice from currently deployed Semantic Web vocabularies, especially the Dublin Core Metadata Terms, the Friend of a Friend Ontology, and the SKOS Core Vocabulary. All those who contributed to the development of these practices are gratefully acknowledged.


References

This bibliography as: BibTex | BibTeXML | RDF

APACHE20
Apache HTTP Server Version 2.0 Documentation , The Apache Software Foundation.
Available at http://httpd.apache.org/docs/2.0/
AWWW04
Architecture of the World Wide Web, Volume One , Ian Jacobs and Norman Walsh, World Wide Web Consortium, W3C Recommendation, December 2004.
Available at http://www.w3.org/TR/2004/REC-webarch-20041215/
COOLURI
Cool URIs for the Semantic Web , Leo Sauermann, DFKI GmbH; Richard Cyganiak, Freie Universität Berlin. W3C Interest Group Note March 2008
Available at http://www.w3.org/TR/cooluris/
FOAF
FOAF Vocabulary Specification , Dan Brickley and Libby Miller.
Available at http://xmlns.com/foaf/0.1/
GRDDL
Gleaning Resource Descriptions from Dialects of Languages (GRDDL) , Dan Connolly, World Wide Web Consortium, W3C Recommendation September 2007
Available at http://www.w3.org/TR/grddl/
HTTPRANGE14
W3C Technical Architecture Group's resolution on the range of HTTP dereferencing (aka "httpRange-14").
Available at http://lists.w3.org/Archives/Public/www-tag/2005Jun/0039.html
OWLFeatures
OWL Web Ontology Language Overview , Deborah L. McGuinness and Frank van Harmelen, World Wide Web Consortium, W3C Recommendation, February 2004.
Available at http://www.w3.org/TR/2004/REC-owl-features-20040210/
OWLGuide
OWL Web Ontology Language Guide , Michael K. Smith, Chris Welty and Deborah L. McGuinness, World Wide Web Consortium, W3C Recommendation, February 2004.
Available at http://www.w3.org/TR/2004/REC-owl-guide-20040210/
PURL
Introduction to Persistent Uniform Resource Locators , Keith Shafer, Stuart Weibel, Erik Jul and Jon Fausey, 6565 Frantz Road, Dublin, Ohio 43017-3395: OCLC Online Computer Library Center, Inc., 1996.
Available at http://purl.oclc.org/docs/inet96.html
RDFa
RDFa in XHTML: Syntax and Processing , B. Adida, M. Birbeck, S. McCarron, S. Pemberton, World Wide Web Consortium, W3C Candidate Recommendation June 2008
Available at http://www.w3.org/TR/2008/CR-rdfa-syntax-20080620/
RDFPrimer
RDF Primer , Frank Manola and Eric Miller, World Wide Web Consortium, W3C Recommendation, February 2004.
Available at http://www.w3.org/TR/2004/REC-rdf-primer-20040210/
RDFS
RDF Vocabulary Description Language 1.0: RDF Schema , Dan Brickley and R. V. Guha, World Wide Web Consortium, W3C Recommendation, February 2004.
Available at http://www.w3.org/TR/2004/REC-rdf-schema-20040210/
RFC2616
Hypertext Transfer Protocol - HTTP/1.1 , R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach and T. Berners-Lee, Internet Engineering Task Force, RFC (2616), June 1999.
Available at http://www.ietf.org/rfc/rfc2616.txt
RFC3986
Uniform Resource Identifier (URI): Generic Syntax , T. Berners-Lee, R. Fielding and L. Masinter, Internet Engineering Task Force, RFC (3986), January 2005.
Available at http://www.ietf.org/rfc/rfc3986.txt
SKOS
SKOS Core Vocabulary Specification , Alistair Miles and Dan Brickley, World Wide Web Consortium, W3C Working Draft, November 2005.
Available at http://www.w3.org/TR/2005/WD-swbp-skos-core-spec-20051102/
XMLNames
Namespaces in XML , Tim Bray, Dave Hollander and Andrew Layman, World Wide Web Consortium, W3C Recommendation, January 1999.
Available at http://www.w3.org/TR/1999/REC-xml-names-19990114/

Change Log

Since Note 28 August 2008


Appendix A. Vocabularies that use PURLs for naming

PURLs ('Persistent URLs') are URIs from the http://purl.org/ URI space. PURLs are supported by a PURL resolution service, which allows the registered owners of a PURL domain to redirect HTTP requests against a PURL to an arbitrary resource URL. Registered owners of PURLs may not configure the central PURL server other than to specify the redirect URL for each PURL.

When the central PURL server was originally developed in the 1990s, the standard response of an HTTP server to a request against a PURL was to return a response code of 302 ("temporarily moved"). Web architecture has evolved since then, and the Technical Architecture Group (TAG) of W3C has resolved that, for the purpose of such redirects for RDF Class and Property names, the response code 303 ("see other") should be returned (see the TAG resolution on httpRange-14 [HTTPRANGE14]).

As PURL servers use a 302 response code and there is currently no way to configure them to use 303 response codes, existing vocabularies with http://purl.org slash namespaces servers do not strictly conform to the current TAG recommendations. These cases are treated in the following recipes.

Note: At the time this Working Draft is being written (January 2008), an update to the PURL service is in progress. We anticipate this update will address the TAG finding on httpRange-14 and 303 redirects. (see http://www.oclc.org/news/releases/200669.htm ).

Recipe 1a. | Recipe 2a. | Recipe 3a. | Recipe 4a. | Recipe 5a.


Recipe 1a. Minimal configuration for a PURL 'hash namespace'

This recipe gives an example configuration that satisfies the minimum requirements for a vocabulary with a hash namespace within the http://purl.org/ URI space. Only machine-processable (RDF) content is served at the namespace URI.

For vocabulary …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example1a

defining classes …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example1a#ClassA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example1a#ClassB

and properties …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example1a#propA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example1a#propB

Step 1

Create a file called example1a.rdf that contains a complete RDF/XML serialization of the vocabulary. I.e. all resources defined by the vocabulary are described in this file.

Step 2

Copy example1a.rdf to the directory /apachedocumentroot/examples/ on the server from which you wish to serve the content (in this example the server is www.w3.org).

Step 3

Set up the following PURL:

PURL: http://purl.org/NET/SWD/recipes/examples-A/example1a
URL:  http://www.w3.org/2006/07/SWD/recipes/examples/example1a.rdf 

Notes

If the server is already configured to serve files with the .rdf extension as content type application/rdf+xml then you don't have to do anything further. If this is not the case, you will need to add the following directive:

AddType application/rdf+xml .rdf

either to the main apache configuration files, or if you don't have access to these, to the per-directory configuration file (.htaccess) for the directory /apachedocumentroot/examples/ on the server.


Recipe 2a. Minimal configuration for a PURL 'slash namespace'

This recipe gives an example configuration that satisfies the minimum requirements for a vocabulary with a slash namespace within the http://purl.org/ URI space. Only machine-processable (RDF) content is served at the namespace URI.

N.B. As of the date of this Working Draft, this example does not strictly conform with the TAG resolution on httpRange-14 [HTTPRANGE14] because the purl.org servers use a 302 redirect code, and not a 303.

For vocabulary …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example2a/

defining classes …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example2a/ClassA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example2a/ClassB

and properties …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example2a/propA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example2a/propB

Step 1

Create a file called example2a.rdf that contains a complete RDF/XML serialization of the vocabulary. I.e. all resources defined by the vocabulary are described in this file.

Step 2

Copy example2a.rdf to the directory /apachedocumentroot/examples/ on the server from which you wish to serve the content (in this example the server is www.w3.org).

Step 3

Set up the following Partial Redirect PURL:

PR PURL: http://purl.oclc.org/NET/SWD/recipes/examples-A/example2a/
Root URL:  http://www.w3.org/2006/07/SWD/recipes/examples/example2a/ 

Step 4

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory on the server:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to serve RDF/XML content from all partially redirected URIs
RewriteRule ^example2a/ example2a.rdf

(N.B. If a .htaccess file does not exist, create one.)

Notes

In the above recipe the single rewrite rule is an internal redirect. This minimizes the number of external (i.e. HTTP) redirects involved in the dereference action. However, you could also implement this rewrite rule as an external redirect, by replacing the above rule with the following:

# Rewrite rule to serve RDF/XML content from all partially redirected URIs
RewriteRule ^example2a/ example2a.rdf [R=303]

This creates an additional HTTP redirect in the dereference action, but possibly makes it clearer to the client that attempts to dereference Vocabulary, Class or Property URIs all end up at the same place and it does make the current PURL implementation conformant with the TAG httpRange-14 resolution [HTTPRANGE14].

It is also possible to avoid any server configuration by creating individual PURLs for each class and property of the vocabulary, all referencing the same URL (rather than a Partial Redirect PURL). However, if the content were subsequently to be moved, each PURL would need to be updated -- a cumbersome and impractical task for medium- to large-size ontologies.


Recipe 3a. Extended configuration for a PURL 'hash namespace'

This recipe gives an example configuration that satisfies the extended requirements for a vocabulary with a hash namespace within the http://purl.org/ URI space. Both machine-processable (RDF) and human-readable (HTML) content is served at the namespace URI.

For vocabulary …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example3a

defining classes …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example3a#ClassA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example3a#ClassB

and properties …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example3a#propA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example3a#propB

Step 1

Create a file called 2005-10-31.rdf that contains a complete RDF/XML serialization of the vocabulary, as at 2005-10-31 (or whatever the current date is). I.e. all resources defined by the vocabulary are described in this file, and this file represents a 'snapshot' or 'version' of the vocabulary.

Step 2

Create a file called 2005-10-31.html that contains HTML content documentation about all classes and properties defined by the vocabulary as at 2005-10-31 (or whatever the current date is). This document may include sections for each of the classes/properties documented, each section being headed by an HTML anchor whose name is identical to the fragment identifier of the documented class or property.

Step 3

Copy 2005-10-31.rdf and 2005-10-31.html to the directory /apachedocumentroot/examples/example3a-content/ on the server from which you wish to serve the content (in this example the server is www.w3.org).

Step 4

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to make sure we serve HTML content from the namespace URI if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example3a$ example3a-content/2005-10-31.html [R=303]

# Rewrite rule to make sure we serve the RDF/XML content from the namespace URI by default
RewriteRule ^example3a$ example3a-content/2005-10-31.rdf [R=303]

Step 5

Setup the following PURL:

PURL: http://purl.oclc.org/NET/SWD/recipes/examples-A/example3a
URL:  http://www.w3.org/2006/07/SWD/recipes/examples/example3a

Notes

Because we can't configure the PURL server for content negotiation, this example configures the content server to perform negotiation after the 302 redirect from the PURL server.


Recipe 4a. Extended configuration for a PURL 'slash namespace', single HTML document

This recipe gives an example configuration that satisfies the extended requirements for a vocabulary with a slash namespace within the http://purl.org/ URI space. Both machine-processable (RDF) and human-readable (HTML) content is served at the namespace URI. The HTML documentation is served as a single file.

N.B. this example does not strictly conform with the TAG resolution on httpRange-14 [HTTPRANGE14] because the purl.org servers use a 302 redirect code, and not a 303.

For vocabulary …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example4a/

defining classes …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example4a/ClassA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example4a/ClassB

and properties …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example4a/propA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example4a/propB

Step 1

Create a file called 2005-10-31.rdf that contains a complete RDF/XML serialization of the vocabulary, as at 2005-10-31 (or whatever the current date is). I.e. all resources defined by the vocabulary are described in this file, and this file represents a 'snapshot' or 'version' of the vocabulary.

Step 2

Create a file called 2005-10-31.html that contains HTML content documentation about all classes and properties defined by the vocabulary as at 2005-10-31 (or whatever the current date is). This document may include sections for each of the classes/properties documented, each section being headed by an HTML anchor whose name is identical to the fragment identifier of the documented class or property.

Step 3

Copy 2005-10-31.rdf and 2005-10-31.html to the directory /apachedocumentroot/examples/example4a-content/ on the server from which you wish to serve the content (in this example the server is www.w3.org)..

Step 4

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to serve HTML content from the namespace URI if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example4a/$ example4a-content/2005-10-31.html [R=303]

# Rewrite rule to serve directed HTML content from class/prop URIs
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example4a/(.+) example4a-content/2005-10-31.html#$1 [R=303,NE]

# Rewrite rule to serve RDF/XML content from the namespace URI by default
RewriteRule ^example4a/ example4a-content/2005-10-31.rdf [R=303]

(N.B. If a .htaccess file does not exist, create one.)

Step 5

Set up the following Partial Redirect PURL:

PR PURL: http://purl.oclc.org/NET/SWD/recipes/examples-A/example4a/
URL Root:  http://www.w3.org/2006/07/SWD/recipes/examples/example4a/

Notes

This configuration would be the most appropriate for Dublin Core Metadata Terms.


Recipe 5a. Extended configuration for a PURL 'slash namespace', using multiple HTML documents

This recipe gives an example configuration that satisfies the extended requirements for a vocabulary with a slash namespace within the http://purl.org/ URI space. Both machine-processable (RDF) and human-readable (HTML) content is served at the namespace URI with the HTML documentation being given as multiple hyperlinked HTML documents plus an overview document.

N.B. this example does not strictly conform with the TAG resolution on httpRange-14 [HTTPRANGE14] because the purl.org servers use a 302 redirect code, and not a 303.

For vocabulary …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example5a/

defining classes …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example5a/ClassA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example5a/ClassB

and properties …

http://purl.oclc.org/NET/SWD/recipes/examples-A/example5a/propA
http://purl.oclc.org/NET/SWD/recipes/examples-A/example5a/propB

Step 1

Create a file called 2005-10-31.rdf that contains a complete RDF/XML serialization of the vocabulary, as at 2005-10-31 (or whatever the current date is). I.e. all resources defined by the vocabulary are described in this file, and this file represents a 'snapshot' or 'version' of the vocabulary.

Step 2

Copy 2005-10-31.rdf to the directory /apachedocumentroot/examples/example5a-content/ on the server from which you wish to serve the content (in this example the server is www.w3.org).

Step 3

Create files ClassA.html ClassB.html propA.html propB.html each of which contains HTML content documentation relevant to the class or property with the corresponding local name, as at 2005-10-31 (or whatever the current date is). Create a file index.html that contains HTML content documentation about the vocabulary itself, with hyperlinks to all class or property documentation.

Step 4

Copy ClassA.html ClassB.html propA.html propB.html and index.html to the directory /apachedocumentroot/examples/example5a-content/2005-10-31-docs/ on the server from which you wish to serve the content (in this example the server is www.w3.org).

Step 5

Add the following directives to the .htaccess file in the /apachedocumentroot/examples/ directory:

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf

# Rewrite engine setup
RewriteEngine On
RewriteBase /examples

# Rewrite rule to serve HTML content from the namespace URI if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example5a/$ example5a-content/2005-10-31-docs/index.html [R=303]

# Rewrite rule to serve HTML content from class or prop URIs if requested
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^example5a/(.+) example5a-content/2005-10-31-docs/$1.html [R=303]

# Rewrite rule to serve RDF/XML content from the namespace URI by default
RewriteRule ^example5a/ example5a-content/2005-10-31.rdf [R=303]

(N.B. If a .htaccess file does not exist, create one.)

Step 6

Set up the following Partial Redirect PURLs:

PR PURL: http://purl.oclc.org/NET/SWD/recipes/examples-A/example5a/
Root URL:  http://www.w3.org/2006/07/SWD/recipes/examples/example5a/

Appendix B: URI namespaces

The URI that identifies your vocabulary is referred to here as the vocabulary namespace URI or just vocabulary URI (or ontology URI as vocabulary and ontology are used here interchangeably). For example, the following URI identifies the SKOS Core Vocabulary:

http://www.w3.org/2004/02/skos/core

… and the following URI identifies the FOAF ontology:

http://xmlns.com/foaf/0.1/

Vocabularies that use a 'hash namespace'

SKOS Core [SKOS] is an example of a vocabulary that uses a hash namespace. This is an informal expression which refers to how the URIs for the classes and properties in the vocabulary are constructed. In this case, the URIs for the classes and properties are constructed by appending first a hash character ('#') and then a 'local name' to the vocabulary URI. The 'local name' is a string of characters that uniquely identifies that class or property within the scope of the vocabulary, also known as a 'fragment identifier' [AWWW04] (the local name must be a legal [XML-NS] token NCName).

For example, the following URIs identify a class and a property from the SKOS Core vocabulary:

http://www.w3.org/2004/02/skos/core#Concept
http://www.w3.org/2004/02/skos/core#prefLabel

Vocabularies that use a 'slash namespace'

FOAF [FOAF] is an example of a vocabulary that uses a slash namespace. Again, this is an informal expression which refers to the way in which the URIs for the classes and properties defined by the vocabulary are constructed. In this case, the vocabulary URI ends with a forward slash character ('/'), and the URIs of classes and properties are constructed by appending the 'local name' of the class or property directly to the vocabulary URI. Again, the 'local name' is a string of characters that uniquely identifies that class or property within the scope of the vocabulary, and must be a legal [XML-NS] token NCName.

For example, the following URIs identify a class and a property from the FOAF vocabulary:

http://xmlns.com/foaf/0.1/Person
http://xmlns.com/foaf/0.1/maker

Note that a vocabulary whose URI ends with a forward slash character doesn't necessarily use a slash namespace. It could use a hash namespace, for example the vocabulary http://example.org/myvocabulary/ could define classes http://example.org/myvocabulary/#Foo and http://example.org/myvocabulary/#Bar.

Both hash namespaces and slash namespaces are supported within the architecture of the Web. However, certain behaviors are required of the Web server that differ between these two choices. Because both the requests received by the server and the responses returned by the server are different in each case, the mechanics of setting up an HTTP server to satisfy some or all of the requirements given below also differ, and hence these two cases are treated separately.

Vocabularies that use other types of namespace

Readers should be aware of a third type of vocabulary URI under discussion at the time of writing: URIs based on a 303-redirect service such as http://thing-described-by.org. Though simpler to implement than approaches described in this document, the 303-redirect approach has not yet been implemented for stable, published RDF vocabularies and is not used in any of the following recipes. Appendix C describes this approach in more detail.

Some considerations when choosing a URI namespace

This document is intended for creators and maintainers of existing vocabularies. Proper guidance on choosing the best URI namespace for any given situation is beyond the scope of this document. However, the recipes given here make assumptions and involve trade-offs with respect to functionality, so some considerations relevant to choosing a URI namespace are described in this section. If you have already chosen a URI namespace, skip to the section choosing a recipe.

The URI namespace you choose for your vocabulary should be a Web address (a URI) to which you have write access. Others who use your vocabulary will expect to be able to dereference both the vocabulary URI itself as well as the URIs of properties and classes defined by your vocabulary. The choice of URI namespace is a fundamental decision you make early in the design of your vocabulary.

While RDF permits a namespace name to start with any valid URI scheme, best practice for the Semantic Web is to use a URI scheme that can be resolved by any client without requiring the use of additional plug-ins or client setup configuration. The http URI scheme is the best known of these and is recognized by all Web clients. This document focuses exclusively on vocabularies whose namespace name begins with http:.

Best practice dictates that all RDF vocabularies use either a hash namespace or a slash namespace (see above). Which you choose depends in part on how big you expect your vocabulary to become, how often you expect to add new terms (i.e., properties or classes), and how you expect users to access information about individual terms in your vocabulary.

For small vocabularies, it may be most convenient to serve the entire vocabulary in a single Web access. Such a vocabulary would typically use a hash namespace, and a Web access (i.e., an HTTP GET request) for any term in the vocabulary would return a single information resource describing all of the terms in the vocabulary.

A vocabulary that is large, to which additions are anticipated frequently, or that defines more data than a typical user application will want to access at one time, should be arranged so that progressively greater detail about the terms in the vocabulary may be retrieved through multiple Web accesses. The full description of all of the terms may be divided among many information resources, or may be managed via a query service (e.g. [SPARQL] -- see Recipe 6). Such a vocabulary would typically use a slash namespace, which allows for the possibility that a Web access for any term in the vocabulary may return information principally about just that one term. (Such a configuration is not possible for a vocabulary that uses a hash namespace, because of the mechanics of the HTTP protocol.)

A more detailed discussion of issues related to URI design for the Semantic Web can be found in these documents:


Appendix C. Vocabulary URIs based on a 303-redirect service

URIs of this type are formed by appending the URI of a descriptive resource as a query string to the base URI of a 303-redirect service such as http://thing-described-by.org. The domain thing-described-by.org delegates authority for defining the meaning of such a query URI to the domain cited in the query string (i.e., the part following a question mark).

In principle, then, one might coin the URI http://thing-described-by.org?http://example.org/foo as an identifier for the Foo vocabulary. An HTTP GET request against the URI for the Foo vocabulary, or against a property or class in the Foo vocabulary, would result in a response code of 303, thus conforming to the second of the two minimum requirements articulated in this document for the publication of RDF vocabularies. If, in addition, the URI http://example.org/foo were to identify an authoritative RDF description for the vocabulary, and the server providing that description were to return a MIME type properly identifying it as such, then the use of http://thing-described-by.org?http://example.org/foo could be said to conform to first of the minimum requirements as well.


Appendix D: Apache configuration

An Apache HTTP server [APACHE20] is configured by directives written either inside the main Apache configuration files (usually 'httpd.conf' etc.) or inside per-directory configuration files (usually '.htaccess'). The recipes given here assume that you do not have access to the main Apache configuration files and that you therefore have to use a per-directory configuration using .htaccess files to supply the configuration directives. You may find more specific information about the use of .htaccess files in the Apache Tutorial: .htaccess files.

If you do have write access to the main Apache configuration files, you might consider writing the configuration directives directly there, as using per-directory configuration can negatively affect server performance and requires more careful configuration of directory-level security, see the Apache Tutorial: When (not) to use .htaccess files. It should be noted that AllowOverride is a directory-level directive and its performance and security side-effects don't usually extend beyond the directory trees in which it's enabled.

Note: The configurations given here have been tested on an Apache HTTP server version 2.0.46 only.

Server configuration

In order to support this use of per-directory configuration files, the server must be configured to allow certain overrides for the directories you are using. The required overrides are:

AllowOverride FileInfo Options

In addition, make sure that your version of Apache has been compiled with the mod_rewrite module, or that the mod_rewrite Dynamic Shared Object (DSO) has been installed and the following lines are in the Apache configuration file:

AddModule mod_rewrite.c
LoadModule rewrite_module modules/mod_rewrite.so

If you are having problems getting the recipes to work, it may be because the required override directives are not specified in the main Apache configuration files or mod_rewrite is not available.

Testing .htaccess parsing

To test whether your server will correctly parse a .htaccess file in a given directory, load a URL that accesses a file in the directory you wish to test into a web browser and verify that the file is served correctly. Next create (or edit) a .htaccess file in that directory that contains the line:

InvalidDirective Here

Reload the URL in your web browser. If the server is parsing the .htaccess files in that directory, the server should return an "Internal Server Error" page generated by the unparsable InvalidDirective. If the page redisplays normally, then you need to ask your sysadmin to enable .htaccess files in the directories that you'll be using with the Recipes. When you have confirmed that the server is parsing your .htaccess files, don't forget to remove the InvalidDirective line from the .htaccess file in that directory.

Testing mod_rewrite installed

To test whether mod_rewrite is installed, replace the InvalidDirective line from the first test with this:

RewriteEngine On

Reload the URL in your web browser. If mod_rewrite is not installed, or you don't have sufficient override permissions to enable it in .htaccess in that directory, then the server should return an "Internal Server Error" page. The AllowOverride directive must be set to FileInfo (or All) to allow you to enable mod_rewrite in a .htaccess file.

Setting the RDF/XML content type

The appropriate content type for serving RDF/XML content is 'application/rdf+xml', as defined in RFC3870. An Apache server can be configured to recognize files with the '.rdf' extension and serve them with the appropriate content type, by adding the following directive to the .htaccess file:

AddType application/rdf+xml .rdf

This directive may also be applied globally at the server level in the server configuration file. In which case it can be safely removed from the recipes.

Alternatives to rewrite rules

The example configurations described in this document implement content negotiation by means of rewrite rules (mod_rewrite) to redirect the requests to the most suitable representation. This mechanism is simple and allows great flexibility with respect to the location of the HTML and RDF/XML documents, which may even reside in different servers.

There are some cases in which the provided example configuration does not properly handle content negotiation. In particular, requests with an 'Accept:' header that contains q-values cannot be parsed with rewrite rules, and the server may respond with a representation different from the preferred one. While it is certainly possible to configure an Apache server to handle such requests, this configuration can't be performed within the limitations of .htaccess files. It is beyond the scope of this document to provide a complete server configuration example to handle these requests. Interested readers may wish to refer to content negotiation with type-maps in Apache.


Valid XHTML 1.0 Strict Valid CSS!