In version 6.x-1.0-beta1, it seems that Relations API supports only one fixed predicate,

http://www.w3.org/2000/01/rdf-schema#seeAlso

I have a patch that expands the predicate selection to include all terms from a specified vocabulary, so for example you can say that your post was http://yoursite/yourvocab#inspired_by someone else's. (However, the actual exposure of the vocabulary terms as RDF is not included in this patch, it can be done manually or perhaps could be done thru a patch to taxonomy_xml)

My goal is to come closer to the ability to use any verb as a predicate. Having a free-tagging vocabulary exposed for use as predicates comes pretty close to this; another option would be to use wordnet. Soapbox: I'd love to see more semantic web apps that also use the existing semantics of language - say a standard en:[anyword] vocabulary that encourages users to enter a short word or phrase as the predicate.

Ok, off soapbox. To use this patch:

- install the patch file provided as an attachment, or available here relations.diff
- edit relations.module and set RELATIONS_VOCABULARY_ID to the id of the vocabulary you would like to use for predicates
- under the Relations tab for nodes which you have enabled the Relations API for, you will now see a drop-down selection with your
vocabulary terms as choices for the relation
- optionally edit your theme to include the relations in your node output. Sample code from bteaching.com included below. I also clean the terms so they just show up as words to the user. Hope to submit a future patch that will make it easy to output relations in RDFa.

There is still a good bit I'd like to do, but the patch in its current state works and expands the functionality a little, so I'm releasing it now. Would love to hear from anyone else who wants this sort of thing.

Example code in template.php:

function bteach_preprocess_node(&$vars, $hook) {

// For now, we only need to preprocess teasers
if ($vars["teaser"] != 1) {

return;
}

$s = '';

// generate content for right-hand column of node display

// images
if (is_array($vars["field_example_image"]) && ! empty($vars["field_example_image"])) {
foreach ($vars["field_example_image"] as $imgobj) {
$s .= "Only local images are allowed.";
}
$vars["field_example_image"] = NULL; //ONLY for teaser
}

// relations
if ($s != '') {
$s .= "

\n";
}
list($relations, $relations_as_object) = relations_directional_lookup($vars["nid"]);
bteach_clean_predicates($relations);
bteach_clean_predicates($relations_as_object);
foreach ($relations_as_object as $pred => $rnodelist) {
$newpred = bteach_inverse_lookup($pred);
if ($newpred) {
// append nodelist by predicate; could do one by one
foreach ($rnodelist as $rnid => $rnode) {
$relations[$newpred][$rnid] = $rnode;
}
}
}
if (is_array($relations) && ! empty($relations)) {
$s .= '

';
foreach ($relations as $pred => $rnodes) {
$matches = array();
foreach ($rnodes as $r_nid => $rnode) {
$s .= $pred.' '.bteach_simple_link($rnode).'
';
}
}
}

$vars["bteach_content"] = $s;
}

function bteach_clean_predicates(&$plist) {
foreach ($plist as $key => $value) {
if (preg_match('/[#:]([^#:]+)$/', $key, $matches)) {
$clean_key = $matches[1];
unset($plist[$key]);
$plist[$clean_key] = $value;
}
}
}

function bteach_inverse_lookup($pred) {
// this is very inefficient but it did not appear to work as a global

// This could be done using the triple store itself; but out of time for now so hardcoding
$LOOKUP_INVERSES = array(
'inspires' => 'inspired by',
'implements' => 'implemented by',
'uses' => 'used for',
'applies' => 'applied by',
'recommends' => 'recommended by',
'teaches' => 'taught by',
'inspired by' => 'inspires',
'inspired-by' => 'inspires',
'implemented by' => 'implements',
'used for' => 'uses',
'applied by' => 'applies',
'recommended by' => 'recommends',
'taught by' => 'teaches',
'has_local_resource' => 'is resource for',
'has_related_event' => 'is related to',
);
// global $LOOKUP_INVERSES;
return $LOOKUP_INVERSES[$pred];
}

// TODO add rdfa
function bteach_simple_link($nodeobj) {

$s = '';
$s .= "path."'>".$nodeobj->title."";
return $s;
}

CommentFileSizeAuthor
relations.diff9.63 KBgvelez17