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 ...
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.
<?phpelseif ($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
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.