Correct formatting of RDFa?

Events happening in the community are now at Drupal community events on www.drupal.org.
joelrichard's picture

I'm learning/exploring RDF/RDFa in Drupal and something I see doesn't quite make sense... I have a pretty vanilla installation of Drupal 7 (v7.8) using the Bartik theme. On a page with a book and some info for the book, I have a Link field mapped to "owl:sameAs" which generates this code:

<div class="field-item even" property="owl:sameAs">
    <a href="http://www.worldcat.org/oclc/1184647" target="_blank">
        http://www.worldcat.org/oclc/1184647
    </a>
</div>

I'm not certain this is proper RDFa, from the examples I can find on the web. Shouldn't it be more like:

<div class="field-item even" property="owl:sameAs" resource="http://www.worldcat.org/oclc/1184647">
    <a href="http://www.worldcat.org/oclc/1184647" target="_blank">
        http://www.worldcat.org/oclc/1184647
    </a>

Or am I simply barking up the wrong tree? I think this could also be an effect of the Theme, but I haven't jumped into the code to see what could be affecting this.

Thanks!
--Joel

Comments

Silly spam filter

joelrichard's picture

Since the groups.drupal.org spam filter won't let me edit my OWN post, here's the corrected code in a more legible format:

Current, possibly incorrect code:

<div class="field-item even" property="owl:sameAs">
    <a href="http://www.worldcat.org/oclc/1184647" target="_blank">
        http://www.worldcat.org/oclc/1184647
    </a>
</div>

Potential correct RDFa code:

<div class="field-item even" property="owl:sameAs" resource="http://www.worldcat.org/oclc/1184647">
    <a href="http://www.worldcat.org/oclc/1184647" target="_blank">
        http://www.worldcat.org/oclc/1184647
    </a>
</div>

Jeez!

The problem here isn't that

linclark.research's picture

The problem here isn't that you need to have a resource attribute. Instead, you should change the 'property' attribute to 'rel'. In RDFa, property is used for text values and rel is used for URI/resource values.

I would recommend Mark Birbeck's Getting Started with RDFa. I always use the Check RDFa tool he built to test my RDFa.

I think I tried that already,

joelrichard's picture

I think I tried that already, but let's looking at it again... When I change the Attribute Type to "rel" in the RDF Mappings, I get this:

<div class="field-item even" rel="owl:sameAs">
<a href="http://www.worldcat.org/oclc/1184647" target="_blank">
      http://www.worldcat.org/oclc/1184647
   </a>
</div>

So "property" changed to "rel". Should my field be a Node Reference? (I don't think so). Currently it's defined as Link. I'm wondering if perhaps the "Link" field type is not behaving, but I tried this with a plain text field and I get this. (not much difference)

<div class="field-item even" rel="owl:sameAs">
http://www.worldcat.org/oclc/1184647
</div>

I think I'll jump into the code later today to try to identify what's going on in the template and work my way backwards from there.

namespace not defined?

scor's picture

Make sure to have the owl namespace defined. Installing the RDFx module will do that for you automatically. Otherwise you can do it in code with

/**
* Implements hook_rdf_namespaces.
*/
function mymodule_rdf_namespaces() {
  return = array(
    'owl'      => 'http://www.w3.org/2002/07/owl#',
  );
}

What tool are you using to check your RDFa? You can use http://rdfa.digitalbazaar.com/live-loop/ for pasting RDFa snippets.

The namespace is defined, but

joelrichard's picture

The namespace is defined, but I'm going to play with that live-loop URL some more. It took me a moment to understand how it works, so I'll paste in bits of code from my page to see what results I get.

I'll report back here later. :)

The results are in!

joelrichard's picture

The results are in!

This actually is working perfectly, even though it's not the same as some of the examples I've found. (I suppose I should RTFM, too.)

For posterity's sake, the live-loop page referenced above returns identical results for the following forms of the sameAs predicate.

<div class="field-item even" rel="owl:sameAs" resource="http://www.worldcat.org/oclc/1184647">
    View at OCLC!
</div>

<div class="field-item even" rel="owl:sameAs">
    <a href="http://www.worldcat.org/oclc/1184647" target="_blank">View at OCLC!</a>
</div>

Both of these return the triple:

<http://example.com/sample.html>
    <http://www.w3.org/2002/07/owl#sameAs>
    <http://www.worldcat.org/oclc/1184647>

Thanks for the input, scor and linckark. I'm one step closer to becoming an expert in this stuff.

Nice work, congrats :)

linclark.research's picture

Nice work, congrats :)

@joelrichard: keep up the

scor's picture

@joelrichard: keep up the good work! feel free to ping us in IRC #drupal-rdf or in the issue queues if you have more questions.

Semantic Web

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: