Extension:SparqlExtension

This extension allows to integrate Semantic Mediawiki with a SPARQL endpoint via a web-service.

While this has been set up and tested to work with Joseki and Jena TDB, with some modifications, this should be configurable to work with other triplestores as well.

This extension is an open-source alternative to the triplestore connector in the Extension:Halo Extension.

Features

 * Synchronizes semantic data with the triple store and exposes it via Joseki endpoint.


 * Embed Sparql query output into a wiki page using a parser extension #sparql.


 * Use foreign endpoints (so far only dbpedia and factbook are "built-in")


 * Querying the properties of the current page:

Where the function sparqlencode encodes the current page name ( variable) into the sparql-suitable format. The function is equivalent to except that it leaves the forward slashes un-encoded, which is required for querying sub-pages.


 * Dealing with sub-pages as recommended in Linked Data Patterns:

Here instead of using prefixes we are forced to use BASE keyword because the prefixed local part cannot contain any forward slashes. Using the BASE keyword allows to rephrase the IRI, so the following are equivalent:  article:France  SparqlExtension takes care of setting the correct prefixes and BASE keyword (equivalent to $smwgNamespace).


 * Multiple output formats: table, maps, graph, template

Template
The following query:

...would feed the following template:
 * Article belongs to a category : called

Maps querying DBpedia (requires Extension:Maps)
Maps output format requires the query to have a "point" variable of type http://www.georss.org/georss/point (or a string with lat and lon separated by a space).

Charts (requires jQuery Visualization)
The following query creates a pie chart for Spain's fuel source mix querying CIA Factbook and using jQuery Visualization to produce HTML5-based chart.

Prerequisites

 * Requires Extension:Semantic_MediaWiki
 * Requires Joseki

Installation
Alternatively you can check out the latest version: svn co https://svn.eeni.tbm.tudelft.nl/SparqlExtension/
 * Install SMW and Joseki first.
 * Configure Joseki to accept named graphs and "SELECT FROM" statements (see example joseki config here)
 * Download zip and extract it into your_mediawiki_path/extensions/
 * Add the following to the end of your LocalSettings.php

$smwgNamespace = 'http://YOURHOST/wiki/'; $sparqlJosekiUpdateUrl = "http://YOURHOST:8080/joseki/update/service"; // wherever the joseki servlet is running $sparqlRdfExportUrl = "http://YOURHOST/wiki/Special:ExportRDF/"; $sparqlJosekiSparqlUrl = "http://lYOURHOST:8080/joseki/sparql?default-graph-uri=&output=csv&query="; // again adjust this to match joseki configuation require_once("$IP/extensions/SparqlExtension/SparqlExtension.php"); $smwgDefaultStore = "JosekiStore"; $sparqljQueryVizPath = "/extensions/jQueryViz";
 * 1) optional support for fancy HTML5 charts
 * 2) you have to download charts from http://code.google.com/p/dwpe/downloads/detail?name=dwpe-code-public-latest.zip and extract them here

In order to configure additional endpoints add the following to your LocalSettings.php: $sparqlEndpoints["factbook"] = array(	"url" => "http://www4.wiwiss.fu-berlin.de/factbook/sparql?output=json&query=",	"type" => "json" ); ...where "url" is the url of the sparql enpoint. The query will be appended to the end. "type" (result format) can be either json or csv, which is sufficient for most sparql endpoints out there.

The endpoint defined can be used in the following way:


 * You can import all your current SMW data using a utility script: your_mediawiki_path/extensions/SparqlExtension/importPagesIntoEndpoint.php

Known issues

 * N.B. Even though TDB allows multiple read single write (MRSW) policy only, Joseki allows simultaneous writes to TDB (or so it seems). Consider this a Joseki bug that hopefully will be fixed in the nearest future.
 * The Graphviz output format needs to be further standardized.