2003-05-05 Danny Ayers
This document describes by example how an RSS module developer can use the Simple Semantics Resolution module to minimise the ambiguity in their RSS 2.0 module definition, and thus make feeds using it suitable for use on the Semantic Web. It is a straightforward process and the amount of work required will depend on the complexity of the module. A simple RSS 2.0 module will need very little effort indeed . The example used in this document (a module for media reviews), is relatively simple but has been designed to demonstrate the all the operations that may be required.
Existing module specifications don't need to change at all, you can just skip the first step of the process described below.
It's worth noting right away that for many RSS 2.0 modules it won't be necessary to write any XSLT or RDF at all : the base rss2rdf.xsl transformation (courtesy Sjoerd Visscher) may suffice for the transformation; its handling of simple structures within the XML can provide the required RDF mapping. It is however essential that this is confirmed by the module developer, and the module developer must provide the RDF definition, but this may simply consist of an example of the RSS 2.0 together with the RDF/XML produced using the base transformation.
Tools Required : any standard XSLT engine; RDF validator
There are command-line processors for XSLT available for all the common platforms, and several integrated tools are available such as Cooktop for MS Windows (free). There is an online RDF validator available at W3C @@URL and the IsaViz @@URL RDF graphic visualization tool carries out validation too.
The process can be broken down into 5 steps:
Each of these steps generates a deliverable, and an SSR-enabled RSS 2.0 module specification will contain at least three of these.
The example used here will be a module that may be used to syndicate reviews of media called the RSS 2.0 Review Module. As an RSS 2.0 module it inherits the definitions contained in the XML specification.
Namespace Definitions
The RSS 2.0 Review Module uses material from the Dublin Core namespace as well as its own :
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rev="http://www.purl.org/stuff/rev/"
Elements and Attributes
The work under review will be identified by the RSS 2.0 <link>
element.
The RSS 2.0 <description>
element will contain the review
itself.
The media type (Book, Film, Music etc) will be given in a <rev:type>
element.
The rating of the work will be an integer value 1 - 10, in a <rev:rating>
element scaled with 1 for Truly, Madly, Deeply and 10 for Terminator.
The creator of the work (author, director...) will be expressed using the Dublin
Core vocabulary's <dc:creator>
element.
The reviewer will be named in a <rev:reviewer>
element.
Example
...
<item>
...
<description>A great SF thriller set in a future DisneyWorld.</description>
<rev:type>Book</rev:type>
<rev:rating>9</rev:rating>
<dc:creator>Cory Doctorow</dc:creator>
<rev:reviewer>danja</rev:reviewer>
</item>
...
Full listing : review-rss2.xml
It should be possible to to obtain a formal RDF interpretation of the new module by combining the the RSS 2.0 definition (above) with the XSLT and RDF Schema definitions (below). However it is strongly recommended that a human-readable version is provided.
We could make a trivial mapping from RSS 2.0 Review Module to RDF, with
all the properties pointing towards the URI of the item, but this could be inviting
interpretation problems, especially with the <description>
(which is the review) and <dc:creator>
elements. To remove
all ambiguity, we'll define a tidily encapsulated set of RDF terms, defining
a Review class.
In human terms then a work can have a review. The review will have various properties as defined in the RSS 2.0 definition.
The identification of the work under review is provided as the content of the
<link>
element in the RSS 2.0 Review Module. In the
RDF interpretation this URL will used as the URI of the resource being described,
the resource being an RSS item.
We then need to define a relationship between the work (item
)
and the review (Review
) . This is easily achieved by defining a
hasReview property that can apply to items.
The text of the review in the RDF version will be contained in a literal element
<rev:text>.
The <description>
element
within the RSS 2.0 Review Module will thus be mapped to <rev:text>
.
The <description>
element is still valid as a description
of the item so this is also carried through into <dc:description>
in the RDF version.
[@@should ditch content:encoded]
The creator specified in the RSS 2.0 Review Module is the creator of
the <item>
resource, not the Review
, and this
potential ambiguity is avoided by the striping of the RDF syntax (class-property->class-property->class...).
<item rdf:about="http://www.craphound.com/down/">
...
<rev:hasReview>
<rev:Review>
<rev:type>Book</rev:type>
<rev:rating>9</rev:rating>
<rev:reviewer>danja</rev:reviewer>
<rev:text>A great SF thriller set in a future DisneyWorld.</rev:text>
</rev:Review>
</rev:hasReview>
...
<dc:creator>Cory Doctorow</dc:creator>
</item>
...
Full example : review.rdf
The RDF version of the RSS 2.0 Review Module has one class: Review and the properties type, rating, text, hasReview and reviewer. It's pretty easy to express this formally in an RDF Schema :
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns="http://purl.org/stuff/rev">
<rdfs:Class rdf:ID="Review">
<rdfs:comment>A review of an artistic work</rdfs:comment>
</rdfs:Class>
<rdf:Property rdf:ID="type">
<rdfs:comment>The type of media of a work under review</rdfs:comment>
</rdf:Property>
<rdf:Property rdf:ID="rating">
<rdfs:comment>A mark out of 10</rdfs:comment>
</rdf:Property>
<rdf:Property rdf:ID="text">
<rdfs:comment>The review itself</rdfs:comment>
</rdf:Property>
The definitions above are really minimal, it is possible to be a lot more descriptive in RDF Schema. For example in this module we have said that the hasReview property is applied to an RSS item and has as a value a Review :
<rdf:Property rdf:ID="hasReview">
<rdfs:comment>Used to associate a work of art with a a review</rdfs:comment>
<rdfs:domain rdf:resource="http://purl.org/rss/1.0/item"/>
<rdfs:range rdf:resource="#Review"/>
</rdf:Property>
We can add a bit more information about the reviewer property too - the creator of a review can been described as a specialised kind of dc:creator :
<rdf:Property rdf:ID="reviewer">
<rdfs:comment>The person that has written the review</rdfs:comment>
<rdfs:subPropertyOf rdf:resource="http://purl.org/dc/elements/1.1/creator"
/>
</rdf:Property>
Full schema : review.rdfs
Our aim here is to be able to convert RSS 2.0 source to valid RDF that has semantics as specified in the module definition. At this stage we only need to look at the parts of the RSS 2.0 source that appear in our module. The following is the required transformation to get the parts of the RSS 2.0 Review Module into the appropriate form for RDF interpretation.
<?xml version="1.0"?>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:r="http://backend.userland.com/rss2"
xmlns="http://purl.org/rss/1.0/"
xmlns:rev="http://www.purl.org/stuff/rev/"
version="1.0">
<xsl:template match="item/rev:type">
<rev:hasReview>
<rev:Review>
<xsl:copy-of select=".|../rev:rating|../dc:creator" />
</rev:Review>
</rev:hasReview>
</xsl:template>
<xsl:template match="rev:type" />
<xsl:template match="rev:rating" />
<xsl:template match="dc:creator" />
</xsl:transform>
The language combination that anyone using the RSS 2.0 Review Module
will need is RSS 2.0 Core plus the RSS 2.0 Review Module. The
core can be transformed using Sjoerd's rss2rdf
stylesheet, and handling of the additional elements is defined above. These
can be combined using <xsl:include>
:
<?xml version="1.0"?>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:r="http://backend.userland.com/rss2"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rev="http://www.purl.org/stuff/rev/"
version="1.0">
<xsl:include href="http://ideagraph.net/xmlns/ssr/source/rss2rdf.xsl"
/>
<xsl:include href="http://ideagraph.net/xmlns/ssr/source/rev2rdf.xsl"
/>
</xsl:transform>
Other modules made be used in the same fashion, but it is essential to check that the result of the combined transformation is valid RDF that expresses the intended semantics.
Anyone can now use the SSR module together with the review module :
<?xml version="1.0" encoding="UTF-16"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ssr="http://purl.org/stuff/ssr"
xmlns:rev="http://www.purl.org/stuff/rev/" >
<ssr:rdf transform="http://ideagraph.net/xmlns/ssr/source/rev+rss2rdf.xsl"
/>
<channel>
<title>A Reviews Feed</title>
<link>http://www.example.org/reviews</link>
<description>For demonstration purposes</description>
<item>
<title>Down and Out in the Magic Kingdom</title>
<link>http://www.craphound.com/down/</link>
<guid>http://www.example.org/reviews/2003/05/04.html</guid>
<pubDate>Tue, 08 Apr 2003 10:28:59 GMT</pubDate>
<description>A great SF thriller set in a future DisneyWorld.</description>
<rev:type>Book</rev:type>
<rev:rating>9</rev:rating>
<dc:creator>Cory Doctorow</dc:creator>
<rev:reviewer>danja</rev:reviewer>
</item>
</channel>
</rss>