Community Documentation

RDF API hooks

Last updated February 17, 2008. Created by Arto on February 10, 2008.
Log in to edit this page.

The RDF API exposes the following Drupal hooks that third-party extension modules can implement to provide extended functionality:

hook_rdf()

Allows modules to take action when RDF statements are inserted or deleted.

Example of usage

<?php
/**
* Implementation of hook_rdf().
*/
function mymodule_rdf($op, $subject, $predicate, $object) {
  switch (
$op) {
    case
'insert':
     
// A new statement was asserted
     
break;
    case
'delete':
     
// An existing statement was unasserted
     
break;
  }
}
?>

hook_rdf_namespaces()

Defines URI abbreviations for use in CURIEs and QNames.

Example from the RDF API module

<?php
/**
* Implementation of hook_rdf_namespaces().
*/
function rdf_rdf_namespaces() {
  return array(
   
'_'        => 'http://bnode.net/',
   
'rdf'      => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
   
'rdfs'     => 'http://www.w3.org/2000/01/rdf-schema#',
   
'xsi'      => 'http://www.w3.org/2001/XMLSchema-instance#',
   
'xsd'      => 'http://www.w3.org/2001/XMLSchema#',
   
'owl'      => 'http://www.w3.org/2002/07/owl#',
   
'dc'       => 'http://purl.org/dc/elements/1.1/',
   
'dcterms'  => 'http://purl.org/dc/terms/',
   
'dcmitype' => 'http://purl.org/dc/dcmitype/',
  );
}
?>

hook_rdf_contexts()

Defines contexts, also known as named graphs.

Example from the RDF API module

<?php
/**
* Implementation of hook_rdf_contexts().
*/
function rdf_rdf_contexts() {
  return array(
   
url(NULL, array('absolute' => TRUE)),
  );
}
?>

hook_rdf_repositories()

Defines RDF repositories.

Example from the RDF DB module

<?php
/**
* Implementation of hook_rdf_repositories().
*/
function rdf_db_rdf_repositories() {
 
$repos = array();
  foreach (
rdf_db_get_repository_names() as $name => $table) {
   
$repos[$name] = array(
     
'title'      => $name,
     
'type'       => 'local',
     
'persistent' => TRUE,
     
'mutable'    => TRUE,
     
'enabled'    => TRUE,
     
'statements' => rdf_db_count_repository_triples($name),
     
'callbacks'  => array(
       
'insert'   => array(
         
'function' => 'rdf_db_rdf_insert',
         
'arguments' => array($table)
        ),
       
'delete'   => array(
         
'function' => 'rdf_db_rdf_delete',
         
'arguments' => array($table)
        ),
       
'query'    => array(
         
'function' => 'rdf_db_rdf_query',
         
'arguments' => array($table)
        ),
      ),
    );
  }
  return
$repos;
}
?>

hook_rdf_formats()

Defines RDF serialization formats.

Example from the RDF API module

<?php
/**
* Implementation of hook_rdf_formats().
*/
function rdf_rdf_formats() {
  return array(
   
'rdf+php' => array(
     
'title'       => t('RDF/PHP'),
     
'mime_type'   => 'application/vnd.php.serialized',
     
'encoding'    => 'ascii',
     
'file_ext'    => 'txt',
     
'serialize'   => 'rdf_serialize_php',
     
'unserialize' => 'rdf_unserialize_php',
    ),
  );
}
?>

About this page

Drupal version
Drupal 6.x

Develop for Drupal

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here