Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Simplifying RDFa Notation : Page 4

Discover how to use namespace prefixes to define taxonomies and categorization through compact URI encoding (CURIE) to make the semantic web more accessible for web development.


advertisement
Unique Taxonomy
In some cases, however, the text content of a given element may not correspond directly with the desired content to be used in the RDFa. For instance, the publication date for an article may be "September 5, 2007," but it would be preferable instead for the RDFa to use the ISO date format—2007-09-05, which is more readily amenable to sorting. In this case, you can use two additional attributes, content to hold the desired content for this particular statement and datatype for indicating how the RDFa should be interpreted.

This approach creates four distinct RDF triples. Expressed in shorthand triple notation, these triples are:

<> dc:title "CURIE Eleison"^^XMLLiteral . <> dc:subtitle "Simplifying RDFa Notation"^^XMLLiteral . <> dc:creator "Kurt Cagle"^^XMLLiteral . <> dc:date "2007-09-05"^^xs:date .

where <> indicates that these properties are associated directly with the current containing document, whatever that may be.



One advantage to such coding is that you can also use CSS selectors with CURIEs to help with the final rendering. For instance, the CSS given in the previous sample is used to control the display of the relevant elements:

<style type="text/css"> body {width:6in;margin-left:0.5in;} p {text-align:justify;} * [property="dc:title"] {font-size:21pt;font-family:Times New Roman;} * [property="dc:subtitle"] {font-size:18pt;font-family:Times New Roman;} * [property="dc:creator"] {font-size:14pt;font-family:Times New Roman; font-style:italic;} * [property="dc:date"] {font-size:14pt;font-family:Times New Roman; font-style:italic;color:gray;} h1 {font-size:14pt;} </style>

The expression * [property="dc:subtitle"], for instance, indicates that a match should be made for any element that has a property attribute with the value "dc:subtitle". The output is illustrated in Figure 1.

Note that you can use advanced CSS 2 and CSS 3 functionality to do a quick scan of RDFa properties. For instance, if you replace the previous style block with this one:

body {color:lightGray;} *[property ^= "dc:"] {color:black;font-size:12pt;} *[property ^= "dc:"]:before {content:"[" attr(property) " - ";color:blue;} *[property ^= "dc:"]:after {content:"]";color:blue;}

the CSS engine will turn everything light gray except elements that have a property attribute beginning with dc: (see Figure 2); those elements expand to display the attribute values, which display in blue. The predicate [property ^= "dc:"] is a CSS shorthand for finding all properties that start with the dc: prefix. Note that if you change the namespace prefix, you must also change the CSS style selector, as it doesn't reference the XML namespace at all.
 
Figure 1. Using the property Attribute in CSS: A match is made for any element that has a property attribute for the associated value.   Figure 2. RDFa Properties in a CURIE Namespace: The CSS engine turns the body text light gray in contrast to elements having property attributes that hold a Dublin Core value.

Of course, there may be times where the focus you want is not on the whole document, but rather on just a small section of it. For instance, suppose that you have a web site that contains a listing for an upcoming meeting (the CURIE Society annual picnic) as part of a larger article:

<p>Also announced today was the CURIE Society's third-annual picnic that will be held at Marie Curie Park in downtown Victoria on Sunday, the 29th of September, from 1 to 5 <span style="font-variant: small-caps">pm</span>. Guest speakers will include Max Planck and Niels Bohr talking about uncertainty in taxonomic divisions and modeling atomic predicates, respectively.</p>

There's a lot of information here, but obviously it will take a little bit of creative tagging to put it into a form that's accessible by a computer. To do so, the first thing that's necessary is to identify the context of this paragraph as being of a certain basic type or class. The most logical choice for this class is an event. While there are a number of event taxonomies out there, to illustrate that such taxonomies do not necessarily have to be established ones, here's a unique one:

xmlms:event="http://www.metaphoricalweb.org/xmlns/event"

The first pass to this event class would then be (assuming the taxonomy has already been defined elsewhere) to indicate that the paragraph is an event and to give that event a name:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev= "http://www.metaphoricalweb.org/xmlns/event" > ... <p class="ev:event" id="annual_picnic" about="#annual_picnic">Also announced today was the CURIE Society's third-annual picnic that will be held at Marie Curie Park in downtown Victoria on Sunday, the 29th of September from 1 to 5 <span style="font-variant: small-caps">pm</span>. Guest speakers will include Max Planck and Niels Bohr talking about uncertainty in taxonomic divisions and modeling atomic predicates, respectively.</p>

The class attribute defines the paragraph as also being the "holder" or container of an event, with the event itself given a formal name through the id attribute. Note that the use of this class attribute more closely approaches Tim Berners-Lee's original intent for the tag: it was meant as a way for specifying which class a given entity belonged to, though this usage was later swamped when CSS began using it as a way to provide a name for a style rule.

The double use of an id and the new about tag may seem a bit redundant, until you recognize that the about attribute is a pointer that indicates in the document what the RDFa properties are referring to. This summary metadata will likely be contained within the block that has the corresponding id, but there is no guarantee, and conceivably such RDFa properties could also point to external documents altogether (and contain fully realized URLs, rather than just hashed indexes).

After defining it, you can apply properties to the particular event class:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.metaphoricalweb.org/xmlns/event" > ... <p class="ev:event" id="annual_picnic" about="#annual_picnic" name="annual_picnic"> Also announced today was the <span property="ev:title content="CURIE Society 3rd Annual Picnic">CURIE Society's third-annual picnic</span> that will be held at <span property="ev:venue">Marie Curie Park</span> in downtown <span ev:property="street" content="3129 N. Douglas St."/> <span ev:property="ev:city">Victoria</span> <span ev:property="province" content="British Columbia."/>on <span property="date" datetype="xs:dateRange" content="2007-09-29T13:00:00 - 2007-09-29T17:00:00"> Sunday, the 29th of September from 1 to 5</span> <span style="font-variant: small-caps">pm</span>. Guest speakers will include <span property="ev:speaker">Max Planck</span> and <span property="ev:speaker">Niels Bohr</span> talking about <span property="ev:topic">uncertainty in taxonomic divisions</span> and <span property="ev:topic">modeling atomic predicates</span>, respectively.</p>

This class produces a surprising number of useful RDF triples:

<#annual_picnic> ev:title "CURIE Society 3rd Annual Picnic"^^XMLLiteral . <#annual_picnic> ev:venue "Marie Curie Park"^^XMLLiteral . <#annual_picnic> ev:street "3129 N. Douglas St."^^XMLLiteral . <#annual_picnic> ev:city "Victoria"^^XMLLiteral . <#annual_picnic> ev:province "British Columbia"^^XMLLiteral . <#annual_picnic> ev:date "2007-09-29T13:00:00 - 2007-09-29T17:00:00" ^^xs:dateRange . <#annual_picnic> ev:speaker "Max Planck"^^XMLLiteral . <#annual_picnic> ev:speaker "Neils Bohr"^^XMLLiteral . <#annual_picnic> ev:topic "uncertainty in taxonomic divisions"^^XMLLiteral . <#annual_picnic> ev:topic "modeling atomic predicates"^^XMLLiteral .

Note that in a few cases, such as with ev:street or ev:province, the metadata was embedded into the description despite not having any text children; this embedding is knowledge that comes from the editor's notes, not from the text itself (and as such it really is metadata in the purest sense). The overriding theme here is that the RDFa should annotate its host XHTML, but shouldn't have a direct impact on the presentation of that content. (CSS referencing is an indirect impact but doesn't change the core data—if the CSS doesn't mention the RDFa code, it should not be a factor in the layout.)

RDFa works on the assumption that any metadata properties are about the current document, and the about attribute doesn't need to be stated explicitly. However, as the prior event class example shows, it is possible to narrow the scope to one particular section. In this case, the about attribute must be included, and it should point to an element with an associated id attribute. Therefore, for an element where id="annual_picnic" the corresponding about attribute would be "http://www.myserver.com/ns/events#annual_picnic", where "http://www.myserver.com/ns/events" is the URL to document itself.

In general, when you have an attribute reference to some point within the document, you can drop the full URL and just include the hash-marked anchor "#annual_picnic" to refer to the same thing. (Of course, you can also define a null namespace in the document—xmlns:doc="#"—and then use CURIEs: about="doc:annual_picnic".)



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap