Category Archives: FOAF

http://www.foaf-project.org/ FOAF Project

Summer of FOAF

This is turning out to be a very interesting summer – even if the weather here in Denmark doesn’t really make it feel like it’s actually summer.

In June I was in Madrid for the Image Description Workshop organised by SWAD-Europe, in two weeks time I’ll be at the SWAD-E workshop on Metadata for a multilingual world, held locally in Copenhagen, just today a community FOAF Camp in Twente in August was announced, and then of course there’s FOAFcon, the 1st Workshop on Friend of a Friend, Social Networking and the Semantic Web in Galway in September, also by SWAD-E.

Phew.

It’s a good thing that this coincides with a favourable tax return…

(Post title credit goes to danbri in #rdfig.)

Semantic Comments Feeds from WordPress

As hinted to last week, I now have my WordPress installation output comments as RSS 1.0, both as a blog-wide feed and as a feed per post.

At the core they are just like other feeds, but comments are a little more diverse than posts. There are regular comments, entered in the comment form for each post, and PingBack‘s and TrackBack‘s, both of which are “remote” — a notification of reference from somewhere else.

Each of these three types of comments are different from each other, and need to be handled differently.

Continue reading Semantic Comments Feeds from WordPress

FOAF Explorer update

It has bothered me for a while, that the FOAF Explorer wasn’t able to handle duplicate statements. It would either repeat the entire property/value pair, or in some situations “just” show the values next to each other without whitespace or other separators in between.

That last issue really isn’t fixed yet, but at least it now only happens with different values – I managed to remove duplicate statements with some crude PHP hacking.

I was already doing a parse and custom (re-)serialise with Redland/Raptor (the PHP source is available) before passing it on to the XSLT, so it was “just” a matter of making sure the same statement wasn’t serialised twice.

Since part of the point of reserialising was to group statements by subject, I had an index in the form of an array of statements per subject. Even though it can be optimized, I simply added a loop to check for the presence of the current predicate/object pair:

$found=0; 
  $os=librdf_node_to_string($object); 
  reset($Nodes[$node]); 
  while(!$found && list(,$pso)=each($Nodes[$node])) { 
    $p=key($pso); 
    list($s,$o)=current($pso); 
    $found=($p==$predicate && librdf_node_to_string($o)==$os); 
  }

It works (try it!), and while the entire FE processing should now take longer, it actually helps somewhat that the XSLT doesn’t have to cope with too much…

While I was at it, I added support for the use of XFN as an RDF vocabulary, with the namespace http://gmpg.org/xfn/1#. It is now treated the same way as the Relationship vocabulary and the Trust vocabulary, which means that it’s handled as if all the properties are rdfs:subPropertyOf foaf:knows. It’s not perfect, the display could use some collapsing, but it works (try it!).

Oh, almost forgot: Also added support for the Quaffing vocabulary by Leigh Dodds.

If only FE really knew about rdfs:subPropertyOf

FOAF output from WordPress

Note: Please see FOAF Output Plugin for newer versions of WordPress.

A few days ago, Christopher Schmidt mentioned in a comment that he had been hacking on FOAF export for WordPress. He kindly let me take a look at his work, and in addition posted a message to rdfweb-dev.

In short, he had created a set of dynamic stand-alone profile pages, one with HTML output and one with RDF/XML output using FOAF, in a single file, /profile2.php.

Seeing that, it dawned on me: WordPress already has a “profile” page for each of the authors, likely at /archives/author/<login>/ (depending on the permalink structure defined) — and it even has a template name: the_author_posts_link. In its default incarnation it’s simply a list of the posts by that author, but turning it into a profile page by also showing the basic information and linked friends didn’t seem too hard.

Continue reading FOAF output from WordPress

Improving RSS output from WordPress

The default syndication output from WordPress is okay, but does leave room for improvement – even though it “defaults” to RSS 2.0, there’s RSS 1.0 hidden behind the scenes.

The first order of action is to fix the default page template to point to the RDF/XML output instead of RSS 2.0. In the file /index.php there are link elements in the head section of the HTML output, switching to RSS 1.0 is quite easy, simply change the RSS 2.0 line to the following (and remove the link to the 0.92 version):

<link rel="alternate" type="application/rdf+xml" title="RSS 1.0" href="<?php bloginfo('rdf_url'); ?>" />

In the meta section there is also a couple of links, one for RSS 2.0 that will be replaced by a link to RSS 1.0, and one for comments that is just dropped (an RDF/XML version may be added at a later date):

<li><a href="<?php bloginfo('rdf_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>"><?php _e('<abbr title="RDF Site Summary">RSS</abbr> 1.0'); ?></a></li>

Now to the actual content of the RSS file: The default template includes, for each post, a dc:creator property that looks like this:

<dc:creator>mortenf (mailto:mort&#101;n&#64;&#119;as&#97;b.dk)</dc:creator>

That’s not terribly helpful for the Semantic Web, so I’ve hacked the template wp-rdf.php to include the following FOAF structure instead:

<foaf:maker>
  <foaf:Person>
    <foaf:name><?php the_author_firstname(); print ' '; the_author_lastname() ?></foaf:name>
    <foaf:nick><?php the_author_login() ?></foaf:nick>
    <foaf:mbox_sha1sum><?php print(bin2hex(mhash(MHASH_SHA1,'mailto:'.$authordata->user_email))) ?></foaf:mbox_sha1sum>
    <foaf:weblog rdf:resource="<?php bloginfo_rss('url') ?>"/>
  </foaf:Person>
</foaf:maker>

In addition to this improvement, the indication of categories could also use a little tune-up. The default output shows categories through the use of dc:subject, which is quite allright but somewhat too vague – how could anyone know that my category SemWeb/FOAF is essentially the same as Danny AyersKnowledge/FOAF category? To make up for this, it is possible to use the Description field in WordPress’ category system to assign a URI to each (or some) of the categories, and then generate appropriate statements by adding two lines to the the_category_rss template function in /wp-includes/template-functions-category.php:

if(preg_match('|^w+:.+/|',$category->category_description))
    $the_list .= '<foaf:topic rdf:parseType="Resource"><dc:title>'.$category->cat_name.'</dc:title><foaf:page rdf:resource="'.$category->category_description.'"/></foaf:topic>';

The results of these tweakings should show up nicely in the RSS feed – check it out here.