Does RDFx ignore the rel / rev settings when exporting RDF through restws?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
rogerhyam's picture

If the value of a text field is a URI and I set the 'Attribute Type' in the RDF Mappings panel to 'rel' then in the RDF produced by the restws this appears to be ignored. e.g. adding an owl:sameAs for a URI in a text field produces RDF/XML like this:

<owl:sameAs>http://scied04.rbge.org.uk/bci/cool/5dxa-1bav</owl:sameAs>

When is should look like this:

<owl:sameAs rdf:resource="http://scied04.rbge.org.uk/bci/cool/5dxa-1bav" />

The method in rdfx.module that appears to do the business here is this

function rdfx_add_statement(&$index, $uri, $property, EntityMetadataWrapper $wrapper, $name) {
if ($property instanceof EntityDrupalWrapper) {
// For referenced entities only add the resource's URI
rdfx_add_resource($index, $uri, $property, $wrapper, $name);
}
elseif ($property instanceof EntityValueWrapper) {
rdfx_add_literal($index, $uri, $property, $wrapper, $name);
}
}

i.e it makes the resource/literal split on whether we are looking at a drupal thing or a value. This works for internal drupal links to users and comments but not when we specify the URI in the data. I can't see anywhere in RDFx where the Attribute type is used.

Is this a design decision or a bug? How can one link to an external resource URI stored in a field? Am I supposed to be using a special field type? I have tried the link module but that doesn't appear in RDF output at all!

Also in the RDFa in the page it adds a rel="owl:sameAs" to the div surrounding the string but doesn't add an href attribute containing the data. I don't think this is valid RDFa because the parser won't know what to pick up as the URI - I may be wrong on this.

I've been trying to override the RDF mappings for a bundle from my module all day but I am finding it impossible to remove existing mappings. It is always additive in that Drupal/RDFx etc. It always adds back in the default mappings ... so my plan of removing page specific stuff like dc:created fails.

I've had a hard day and think I am going to give up unless someone says something nice to me. Tomorrow I'll have to go to Plan B - generating my own RDF!

Any thoughts most welcome.

Roger

Comments

Use a Link field, but ...

djevans's picture

It would seem to make more sense to use a Link field for this purpose. As you've discovered though, this doesn't help when generating RDF/XML through restws - the following code snippet from the function rdfx_get_rdf_model() illustrates why.

<?php
elseif ($property instanceof EntityStructureWrapper) {
 
$li_filtered = rdfx_property_access_filter($property);
  foreach (
$li_filtered as $li_name => $li_property) {
    if (
$li_property instanceof EntityDrupalWrapper || $li_property instanceof EntityValueWrapper) {
     
// This assumes that all literals have a 'value' array element
      // and that all resources have a 'uri' array element.
     
if ($li_name == 'value' || $li_name == 'uri'){
       
rdfx_add_statement($index, $entity_uri, $li_property, $wrapper, $name);
      }
    }
  }
}
?>

Because Link fields are split up into the components 'title' and 'url', the test of $li_name for 'value' or 'uri' fails and rdfx_add_statement() is never called.

You can fix this by applying the patch as described in Support for link field in the RDF model, which will pick up the 'url' component of the Link field while building the RDF mpdel for the relevant entity.

Note that this will apply a rel="owl:sameAs" attribute to the field's outer div and a @href attribute to the inner 'a' tag in the RDFa output - as far as I know this is valid RDFa, but I don't know whether it suits your purposes. Which parser were you thinking of?

This kind of limitation will

scor's picture

This kind of limitation will be difficult to fix without a better integration with entity API. That's why I started to work on http://drupal.org/project/entity_rdf, see the introductory post explaining the goals. It's still not recommended to be used in production (though I'm currently using it on one of my sites). For now you're probably better off generating your own RDF. Check out this issue/patch if you are interesting in building on top of the existing output: http://drupal.org/node/1240778.

valeriap's picture

Unfortunately I don't know how to create a patch, but I can tell you how I temporarily solved this (hoping that this is implemented in the module soon).

My aim was to allow to treat any field as a URI, and therefore relate it to a property as a resource and not a literal, based on the "rel" attribute set in the RDF mapping. Any time the site administrator sets the attribute type for the RDF mapping of a field to "rel", the RDF output treats the value as a resource.
Of course the value of the field using the "rel" attribute must be a valid URI, but this is up to the site administrator.

1) In rdfx.module, in the rdfx_add_statement function, I added these four lines at the beginning to detect which attribute type was selected for the property:

$entity = $wrapper->value();
$attrib = "";
  if(isset($entity->rdf_mapping[$name]['type']))
    $attrib = $entity->rdf_mapping[$name]['type'];

and then I changed the following line from:

  if ($property instanceof EntityDrupalWrapper) {

to:
  if ($property instanceof EntityDrupalWrapper || $attrib == "rel") {

in order to force the module to use rdfx_add_resource also for fields that are not references but have the "rel" attribute.

2) Then of course I had to add some code also in the rdfx_add_resource function:

I changed the first line from:

  if ($id = $property->getIdentifier()) {

to:
  if ($property instanceof EntityDrupalWrapper && $id = $property->getIdentifier()) {

in order not to get error (non-reference properties don't have an identifier).

And I added an "else" to the main IF:

  else {
    $predicates = rdfx_get_predicates($wrapper, $name);
    foreach ($predicates as $predicate) {
      $index[$uri][$predicate][] = $property->value();
  }
}

in order to use the property value as the URI of the resource.

Semantic Web

Group organizers

Group notifications

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

Hot content this week