Linking data.gov to Linked Data Cloud

From Data-gov Wiki

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

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


Contents

Overview

When dumping spreadsheets from data.gov 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 http://data-gov.tw.rpi.edu/vocab/p/92/title

install SMW

There are two issues

  • the URL of the property is ugly: the name of property have to use "Property:" as namespace
http://<wikiurl>/Property:<myproperty>
  • the URL of the export page is ugly:
http://<my.wiki.org>/wiki/SpecialExportRDF/Property-3A<myproperty>
  • we need either (i) set <wikiurl> as http://<my.wiki.org>/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://<my.wiki.org>/vocab/";

add a php proxy

make sure php has been installed.

http://<my.wiki.org>/vocab.php

<?php
$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/",
			"/(&property;)(.)/e",
			"/(<property:)(.)/e",
			"/&wikiurl;Special:ExportRDF\/Property:(.)([^\"]+)/e",
			"/&wikiurl;Special:ExportRDF\/Property%3A(.)([^\"]+)/e",
			"/&wikiurl;Special:ExportRDF\/Category:([^\"]+)/e",
			"/&wikiurl;Special:ExportRDF\/Category%3A([^\"]+)/e",
			"/&wikiurl;Special:ExportRDF\/([^\"]+)/e",
			),
		array(	"vocab/p/",
			"'\\1'.strtolower('\\2')", 
			"'\\1'.strtolower('\\2')",
			"'$url_property'.strtolower('\\1').'\\2'",
			"'$url_property'.strtolower('\\1').'\\2'",
			"'$url_class'.('\\1')",
			"'$url_class'.('\\1')",
			"'$url_instance'.('\\1')",
			),
		$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 data.gov to Linked Data CloudRDF feed
Dcterms:created27 June 2009  +
Dcterms:creatorLi Ding  +
Dcterms:descriptionwe link RDF version of data.gov datasets to linked data cloud using semantic mediawiki.
Dcterms:modified2009-11-18
Foaf:nameLinking data.gov to Linked Data Cloud
Skos:altLabelLinking data.gov to Linked Data Cloud  +, linking data.gov to linked data cloud  +, and LINKING DATA.GOV TO LINKED DATA CLOUD  +
Personal tools
internal pages