Linking to Linked Data Cloud

From Data-gov Wiki

Jump to: navigation, search
Infobox (Tech Report) edit with form
  • name: Linking to Linked Data Cloud

  • description: we link RDF version of datasets to linked data cloud using semantic mediawiki.
  • creator(s): Li Ding
  • created: June 27,2009
  • modified: 2009-11-18



When dumping spreadsheets from into RDF, we frequently encountered the need of creating URIs for properties and instances. Although it is possible to find a good URI for each of the properties and instances, the mapping time is quite costly. With a Semantic Wiki based online vocabulary management service, we can simply point all such URIs to SMW and be lazy, i.e. delay the mapping work and leverage collective intelligence in the future.

Unfortunately, SMW does not provide native support to the following two objectives at the same time:

  1. a property and the RDF page describing the property should be referred by different URIs
  2. users can get the RDF description of the property by following its namespace

The main reason for that is RDF resource defined in SMW does not have fragment "#", so objective 1 must be violated to ensure objective 2. Therefore, the current RDF export of SMW is not very friendly to RDF browsers such as tabulator.

Hacking SMW

To avoid the above difficulties, here is a hack. An example is available at

install SMW

There are two issues

  • the URL of the property is ugly: the name of property have to use "Property:" as namespace
  • the URL of the export page is ugly:
  • we need either (i) set <wikiurl> as http://<>/wiki/SpecialExportRDF; or (ii) set redirection for <wikiurl>, to ensure we can retrieve the RDF/XML definition of the Property by following its namespace.
  • the "content-type" of that export page is "application/xml"

configure wiki (optional)

in LocalSettings.php, add the following declaration

$smwgNamespace = "http://<>/vocab/";

add a php proxy

make sure php has been installed.


$property = $_GET['property'];
$class = $_GET['class'];
$instance = $_GET['instance'];

$url_host =$_SERVER[HTTP_HOST];
$url_property = sprintf("http://%s%s?property=",$_SERVER[HTTP_HOST], $_SERVER[SCRIPT_NAME]);
$url_class = sprintf("http://%s%s?class=",$_SERVER[HTTP_HOST], $_SERVER[SCRIPT_NAME]);
$url_instance = sprintf("http://%s%s?instance=",$_SERVER[HTTP_HOST], $_SERVER[SCRIPT_NAME]);

if (!empty($property)){
	$url = "http://".$url_host."/wiki/Special:ExportRDF/Property:".$property;
}else if (!empty($class )){
	$url = "http://".$url_host."/wiki/Special:ExportRDF/Category:".$class;
}else if (!empty($instance )){
	$url = "http://".$url_host."/wiki/Special:ExportRDF/".$instance;

if (!empty($url)){
	header("Content-Type: application/rdf+xml; charset=UTF-8");
	$ret = file_get_contents($url);
	$ret = preg_replace(
		array(	"/vocab\/Property-3A/",
		array(	"vocab/p/",
		$ret );

	echo $ret;


configure redirection

ensure apache has MOD_REWRITE install and turned on. Then edit the ".htaccess" file by adding

RewriteEngine On
RewriteRule ^vocab/p/(.*)$ /vocab.php?property=$1 [R=301] 
RewriteRule ^vocab/c/(.*)$ /vocab.php?class=$1 [R=301] 
RewriteRule ^vocab/(.*)$ /vocab.php?instance=$1 [R=301] 
Facts about Linking to Linked Data CloudRDF feed
Dcterms:created27 June 2009  +
Dcterms:creatorLi Ding  +
Dcterms:descriptionwe link RDF version of datasets to linked data cloud using semantic mediawiki.
Dcterms:modified2009-11-18  +
Foaf:nameLinking to Linked Data Cloud
Skos:altLabelLinking to Linked Data Cloud  +, linking to linked data cloud  +, and LINKING DATA.GOV TO LINKED DATA CLOUD  +
Personal tools
internal pages