Extension:LinkedWiki
|
LinkedWiki Release status: stable |
|
|---|---|
| Implementation | Parser extension, Special page, Data extraction |
| Description | Print array or widget with a query Sparql on your Semantic MediaWiki, including a SPARQL Endpoint(optional) |
| Author(s) | Karima Rafes (Karima Rafestalk) |
| Last version | 1.0.1.2 version stable 2.0.0 version Alpha 1 |
| MediaWiki | 1.16.* or greater |
| License | CC-by-nc-sa V3.0 |
| Download | v2.0.0Alpha1 v1.0.1.2 |
| Example | http://en.sparql.pro |
| Check usage and version matrix | |
Version 2.0.0 Alpha 1 [edit]
New version of LinkedWiki is available :
- without ARC2 lib
- without dependencies with the extension Semantic MediaWiki
- You can use the extension without local endpoint
- very simple installation
What can this extension do? [edit]
So for the moment in this version ALPHA you can :
- read remote endpoint with SPARQL 1.1 or 1.0
- help you to build and test a SPARQL query with a special page
- print the result of your query in a page with a parser function. Example:
- print the result of your query in a mediawiki widget. Thus, you can build by yourself new widgets for your linked data in your Linked Wiki. Example with the Google maps widget with Worldwide Earthquakes :
Download instructions [edit]
Download the last version on GitHub at https://github.com/BorderCloud/LinkedWiki.
Installation VERSION 2 [edit]
To install this extension, add the following to LocalSettings.php:
require_once( "{$IP}/extensions/LinkedWiki/LinkedWiki.php" );
If, after the installation, you have errors about CURL in the log, probably you need to install the lib php5-curl in your server.
Example with ubuntu & fedora :
apt-get install php5-curl
or
yum install php5-curl
Usage [edit]
Parser functions : SPARQL [edit]
Basic Use: #sparql [edit]
Print a simple Array with the following results:
- Querying of the default endpoint and all the graphs of this endpoint.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |endpoint=http://dbpedia.org/sparql}}
- Querying of the default endpoint with one graph.
{{#sparql:select * where { graph <http://mygraph/test> { ?x ?y ?z . } } LIMIT 5 | endpoint = http://dbpedia.org/sparql }}
- Querying of the default endpoint with the graph of this wiki (define with the variable $wgLinkedWikiGraphWiki).
{{#sparql:select * where { graph <WIKIGRAPH> { ?x ?y ?z . } } LIMIT 5 | endpoint = http://dbpedia.org/sparql }}
- Querying the properties of the current page (3 equivalent queries) :
{{#sparql:select * where { <PAGEIRI> ?y ?z . } | endpoint = http://dbpedia.org/sparql }}
{{#sparql:PREFIX a:<http://yourURIResolver/> select * where { a:{{PAGENAMEE}} ?y ?z . } | endpoint = http://dbpedia.org/sparql }}
{{#sparql:select * where { <http://yourURIResolver/{{PAGENAMEE}}> ?y ?z . } | endpoint = http://dbpedia.org/sparql }}
- Querying with any language.
{{#sparql:PREFIX a:<http://fr.mywiki/Spécial:URIResolver/> select * where { a:Tête_à_claque ?y ?z . } | endpoint = http://dbpedia.org/sparql }}
{{#sparql:PREFIX a:<http://zh.mywiki/wiki/Spécial:URIResolver/> select * where { a:秦朝 ?y ?z . } | endpoint = http://dbpedia.org/sparql }}
Advanced Use: #sparql [edit]
Parameter: headers [edit]
- Change the headers.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |headers=name1,name2,name3}}
Parameter: classHeaders [edit]
- You can hide or change the style of your headers. Here, the first column has no header and is unsortable.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |headers= ,name2,name3 |classHeaders= class="unsortable",, }}
Example:
Parameter: templates [edit]
With an example of template like Template:Test1:
<includeonly>{{{x}}}, {{{y}}} and {{{z}}} </includeonly>
- You can use this template in the following way:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |headers=Name1 |templates= Test1 }}
- And you can use a different template for each column:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |headers=Name1,Name2 |templates= Test1,Test1 }}
Parameter: cache [edit]
- Your data may be very volatile and you need accordingly to refresh the result of this query each time. To do so, you can disable the cache with the cache parameter, as follows:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |cache=no }}
Parameter: debug [edit]
- Well, you can add several parameters at the same time but doing so, the wiki text can be very hard to debug. This parameter gives you the result of this parser before the last parsing of mediawiki :
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |debug=YES }}
[edit]
- you can remove the footer of array :
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |footer=NO }}
Parameter: templateBare [edit]
- you can remove the footer and the header. With the value "tableCell", you can catch only the cells.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql |templateBare=tableCell }}
With the Widget extension: #wsparql [edit]
Usage [edit]
You want to use your SPARQL results with Google Maps, Youtube, Flickr, etc. It's very hard if not impossible to develop all the possibilities in a mediawiki extension. So, the wsparql function can pre-format the parameters for a widget.
- The parameters of the query, endpoint, cache and debug are the same as for #sparql, with a slightly different syntax:
{{#wsparql: WIDGET_NAME |query= SPARQL_QUERY | endpoint= ENDPOINT | cache = NO/YES (optional) | debug = NO/YES (optional) | PARAMETERS_OF_WIDGET }}
- Example with the Google Static Maps widget:
{{#wsparql: Google_Static_Maps
|query=
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX cat:<http://fr.test2.daria/wiki/Spécial:URIResolver/Catégorie:>
PREFIX prop:<http://fr.test2.daria/wiki/Spécial:URIResolver/Attribut:>
select ?point
where { ?x rdf:type cat:Ville; prop:Position ?point}
LIMIT 5
|endpoint = http://dbpedia.org/sparql
|defaultcolor=blue
|center=France
|zoom=5
|size=512x512
|maptype=roadmap}}
- Result of wsparql before the parsing of mediawiki:
{{#widget:Google_Static_Maps
|defaultcolor=blue
| center=France
| zoom=5
| size=512x512
| maptype=roadmap
| rows.0.point=43.30, 5.38
| rows.1.point=48.83, 2.3
| rows.2.point=49.93, 2.3}}
And after parsing:
As you can see, the wsparql aggregates the sparql results in one list, with this pattern : rows.NUMBER_LINE.VARIABLE_NAME = VARIABLE_VALUE
- Like that:
rows.0.point=43.30, 5.38 | rows.1.point=48.83, 2.3 | rows.2.point=49.93, 2.3
You have to find a widget compatible with this syntax or you can create/change a widget of mediawikiwidgets.
Build your widget [edit]
- Install the extension Widgets
- Create the page Widget:NAME_OF_YOUR_WIDGET
- Insert your code, example with google static maps :
<noinclude>__NOTOC__
This widget allows you to embed
'''[http://code.google.com/apis/maps/documentation/staticmaps/ Google Static Maps]'''
on your wiki page.
==== Sample result ====
{{#widget:{{PAGENAME}}
|defaultcolor=blue
|center=France
|zoom=5
|size=512x512
|maptype=roadmap
|sensor=false
|rows.0.color= red
|rows.0.point= 43.30,2.3
|rows.1.point= 48.83,2.3
|rows.2.point= 48.73,2.3}}
</noinclude>
<includeonly>
<img
src="http://maps.google.com/maps/api/staticmap?
center=<!--{$center|default:'France'|escape:'html'}-->
&zoom=<!--{$zoom|default:'5'|escape:'html'}-->
&size=<!--{$size|default:'512x512'|escape:'html'}-->
&maptype=<!--{$maptype|default:'roadmap'|escape:'html'}-->
&sensor=<!--{$sensor|default:'false'|escape:'html'}-->
<!--{if is_array($rows)}-->
<!--{foreach from=$rows key=myId item=i}-->
&markers=label:<!--{$myId|escape:'html'}-->
|color:<!--{$i.color|default:$defaultcolor|escape:'html'}-->
|<!--{$i.point|escape:'html'}-->
<!--{/foreach}-->
<!--{/if}-->"/>
</includeonly>
And to share your widget in mediawikiwidgets.org.
Now, let's summarize!
- To read one list like rows.NUMBER_LINE.VARIABLE_NAME = VARIABLE_VALUE, you have to perform a foreach of rows and read keys and items, like that:
<!--{foreach from=$rows key=myId item=i}-->
<!--{$myId|escape:'html'}--> <!--{$i.point|escape:'html'}-->
<!--{/foreach}-->
It's a bit hard the first time. Use the group google, if you face a problem.
Version 1.0.1.2 [edit]
Use LinkedWiki if you want to use data from external endpoints and expose such data to the rest of the world (linked data).
The LinkedWiki extension will allow integrating Semantic Mediawiki with a SPARQL 1.1 endpoint via a RESTful API (ie, HTTP GET).
Quick video : First video of tutorials
Tutorials (subtitles in english and VO in french) : 12 videos
Training : 2 days in french, send a email if you want a training in english.
What can this extension do? [edit]
The LinkedWiki extension can:
- read a local or remote endpoint with SPARQL 1.0 (lib ARC2, tested with DBpedia and 4store)
- write a local or remote endpoint with the functions Insert DATA and Delete DATA of SPARQL 1.1 (lib 4store-php, tested only with 4store)
- help you to build and test a SPARQL query with a special page
- from the special page, share your SPARQL query, thanks to the tutorial generation feature.
- print the result of your query in a page with a parser function. Example:
- print the result of your query in a mediawiki widget. Thus, you can build by yourself new widgets for your linked data in your Linked Wiki. Example with the Google maps widget with Worldwide Earthquakes :
Comparison of Semantic MediaWiki triplestore connectors [edit]
There are important differences among Extension:Halo Extension, Extension:SparqlExtension and Extension:RDFIO :
- LinkedWiki doesn't change the real ontology of your semantic mediawiki. Interoperability!
- LinkedWiki uses 4Store because 4Store is an efficient, scalable and stable RDF database, more than jena or ARC2 (LinkedWiki does not use the ARC endpoint, only the SPARQL 1.0 parser API).
- LinkedWiki uses SPARQL 1.1 in order to write in a local or remote endpoint (Insert DATA and Delete DATA).
- LinkedWiki can use Extension:Widgets in order to print a result because anybody can customize a widget without changing the PHP code.
- LinkedWiki is an Open Source project. The project has an active maintenance.
Tutorials [edit]
- Demonstration of the extension (quick video)
- First step in Semantic Mediawiki
- How to print an image with a SPARQL query ?
- Defining an infobox and association of a list of values to a property
- Creating an ID for sharing data with a machine
- Creating a property with a limited set of allowed values
- Display the result of a SPARQL query with a MediaWiki template
- Formatting an infobox
- How to build the template of the infobox
- How to use the template of the infobox
- How to share SPARQL queries
- How to realign the dynamic internal ontology of a wiki with a stable ontology
Usage [edit]
Parser functions : SPARQL [edit]
Basic Use: #sparql [edit]
Print a simple Array with the following results:
- Querying of the default endpoint and all the graphs of this endpoint.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 }}
- Querying of the default endpoint with one graph.
{{#sparql:select * where { graph <http://mygraph/test> { ?x ?y ?z . } } LIMIT 5 }}
- Querying of the default endpoint with the graph of this wiki (define with the variable $wgLinkedWikiGraphWiki).
{{#sparql:select * where { graph <WIKIGRAPH> { ?x ?y ?z . } } LIMIT 5 }}
- Querying the properties of the current page (3 equivalent queries) :
{{#sparql:select * where { <PAGEIRI> ?y ?z . } }}
{{#sparql:PREFIX a:<http://yourURIResolver/> select * where { a:{{PAGENAMEE}} ?y ?z . } }}
{{#sparql:select * where { <http://yourURIResolver/{{PAGENAMEE}}> ?y ?z . } }}
- Querying with any language.
{{#sparql:PREFIX a:<http://fr.mywiki/Spécial:URIResolver/> select * where { a:Tête_à_claque ?y ?z . } }}
{{#sparql:PREFIX a:<http://zh.mywiki/wiki/Spécial:URIResolver/> select * where { a:秦朝 ?y ?z . } }}
Advanced Use: #sparql [edit]
Parameter: endpoint [edit]
- Querying of another endpoint.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |endpoint=http://dbpedia.org/sparql }}
Parameter: headers [edit]
- Change the headers.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |headers=name1,name2,name3}}
Parameter: classHeaders [edit]
- You can hide or change the style of your headers. Here, the first column has no header and is unsortable.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |headers= ,name2,name3 |classHeaders= class="unsortable",, }}
Example:
Parameter: templates [edit]
With an example of template like Template:Test1:
<includeonly>{{{x}}}, {{{y}}} and {{{z}}} </includeonly>
- You can use this template in the following way:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |headers=Name1 |templates= Test1 }}
- And you can use a different template for each column:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |headers=Name1,Name2 |templates= Test1,Test1 }}
Parameter: cache [edit]
- Your data may be very volatile and you need accordingly to refresh the result of this query each time. To do so, you can disable the cache with the cache parameter, as follows:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |cache=no }}
Parameter: debug [edit]
- Well, you can add several parameters at the same time but doing so, the wiki text can be very hard to debug. This parameter gives you the result of this parser before the last parsing of mediawiki :
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 |debug=yes }}
With the Widget extension: #wsparql [edit]
Usage [edit]
You want to use your SPARQL results with Google Maps, Youtube, Flickr, etc. It's very hard if not impossible to develop all the possibilities in a mediawiki extension. So, the wsparql function can pre-format the parameters for a widget.
- The parameters of the query, endpoint, cache and debug are the same as for #sparql, with a slightly different syntax:
{{#wsparql: WIDGET_NAME |query= SPARQL_QUERY | endpoint= ENDPOINT (optional) | cache = NO/YES (optional) | debug = NO/YES (optional) | PARAMETERS_OF_WIDGET }}
- Example with the Google Static Maps widget:
{{#wsparql: Google_Static_Maps
|query=
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX cat:<http://fr.test2.daria/wiki/Spécial:URIResolver/Catégorie:>
PREFIX prop:<http://fr.test2.daria/wiki/Spécial:URIResolver/Attribut:>
select ?point
where { ?x rdf:type cat:Ville; prop:Position ?point}
LIMIT 5
|defaultcolor=blue
|center=France
|zoom=5
|size=512x512
|maptype=roadmap}}
- Result of wsparql before the parsing of mediawiki:
{{#widget:Google_Static_Maps
|defaultcolor=blue
| center=France
| zoom=5
| size=512x512
| maptype=roadmap
| rows.0.point=43.30, 5.38
| rows.1.point=48.83, 2.3
| rows.2.point=49.93, 2.3}}
And after parsing:
As you can see, the wsparql aggregates the sparql results in one list, with this pattern : rows.NUMBER_LINE.VARIABLE_NAME = VARIABLE_VALUE
- Like that:
rows.0.point=43.30, 5.38 | rows.1.point=48.83, 2.3 | rows.2.point=49.93, 2.3
You have to find a widget compatible with this syntax or you can create/change a widget of mediawikiwidgets.
Bug in this version with #wsparql [edit]
In the file LinkedWiki.php, you need to change the line :
if(preg_match_all('#^([^= ]+)=(.*)$#i', $args[$i],$match)){
with this line :
if(preg_match_all('#^([^= ]+)=((.|\n)*)$#i', $args[$i],$match)){
Build your widget [edit]
- Install the extension Widgets
- Create the page Widget:NAME_OF_YOUR_WIDGET
- Insert your code, example with google static maps :
<noinclude>__NOTOC__
This widget allows you to embed
'''[http://code.google.com/apis/maps/documentation/staticmaps/ Google Static Maps]'''
on your wiki page.
==== Sample result ====
{{#widget:{{PAGENAME}}
|defaultcolor=blue
|center=France
|zoom=5
|size=512x512
|maptype=roadmap
|sensor=false
|rows.0.color= red
|rows.0.point= 43.30,2.3
|rows.1.point= 48.83,2.3
|rows.2.point= 48.73,2.3}}
</noinclude>
<includeonly>
<img
src="http://maps.google.com/maps/api/staticmap?
center=<!--{$center|default:'France'|escape:'html'}-->
&zoom=<!--{$zoom|default:'5'|escape:'html'}-->
&size=<!--{$size|default:'512x512'|escape:'html'}-->
&maptype=<!--{$maptype|default:'roadmap'|escape:'html'}-->
&sensor=<!--{$sensor|default:'false'|escape:'html'}-->
<!--{if is_array($rows)}-->
<!--{foreach from=$rows key=myId item=i}-->
&markers=label:<!--{$myId|escape:'html'}-->
|color:<!--{$i.color|default:$defaultcolor|escape:'html'}-->
|<!--{$i.point|escape:'html'}-->
<!--{/foreach}-->
<!--{/if}-->"/>
</includeonly>
And to share your widget in mediawikiwidgets.org.
Now, let's summarize!
- To read one list like rows.NUMBER_LINE.VARIABLE_NAME = VARIABLE_VALUE, you have to perform a foreach of rows and read keys and items, like that:
<!--{foreach from=$rows key=myId item=i}-->
<!--{$myId|escape:'html'}--> <!--{$i.point|escape:'html'}-->
<!--{/foreach}-->
It's a bit hard the first time. Use the contact page, if you face a problem.
Parser function : Tools [edit]
#properties [edit]
Add values of one property in one time like a list of one parameter of an infobox.
{{#properties:Ingrédient|sel, glutamate, inosinate, gualanylate de sodium,sucre,huile végétale,origan,oignon, extrait de levure,basilic, persil, céleri, laurier, romarin, noix de muscade}}
Download instructions [edit]
Download the version 1.0.1.2 on GitHub at http://github.com/BorderCloud/LinkedWiki/downloads.
Installation VERSION 1 (NOT FOR VERSION 2) [edit]
The extension works with or without a triplestore. You can have a graph for your wiki without triplestore. You can host your graph with the service BorderCloud.
So, there are 3 configurations :
- with the remote triplestore of BorderCloud
- with a local triplestore 4Store
- without triplestore
If, after the installation, you have errors about CURL in the log, probably you need to install the lib php5-curl in your server.
Example with ubuntu & fedora :
apt-get install php5-curl
or
yum install php5-curl
with the remote triplestore of BorderCloud [edit]
Go on the website BorderCloud and to rent a graph.
Install Extension:Semantic MediaWiki.
If you want to use a widget with SPARQL, install Extension:Widgets.
Extract the downloaded archive into your extension/directory. The folder name of the destination is LinkedWiki.
To install this extension, add the following to LocalSettings.php:
require_once( $IP."/extensions/LinkedWiki/lib/bordercloud/SparqlTools.php"); require_once( "{$IP}/extensions/LinkedWiki/LinkedWiki.php" ); $smwgDefaultStore = "SMW_LinkedWikiStore"; //put the address of your 4store endpoint or SPARQL 1.1-compatible endpoint //WARNING! this address has to be accessible only by the wiki! $wgLinkedWikiEndPoint = "http://lod.bordercloud.com/"; //put the graph name where the data of your wiki will be recorded $wgLinkedWikiGraphWiki = "http://fr.sparql.pro/wiki/"; //put the address of your endpoint where the user can perform an Http Get request without the right to Write in your endpoint. $wgLinkedWikiLocalEndPoint = "http://lod.bordercloud.com/"; //put the tag lang of your wiki $wgLinkedWikiLanguageTag = "fr"; //put the access code of BorderCloud $wgLinkedWikiBorderCloudJeton = "000000";
With a local triplestore : 4Store [edit]
Install Extension:Semantic MediaWiki.
If you want to use a widget with SPARQL, install Extension:Widgets.
Extract the downloaded archive into your extension/directory. The folder name of the destination is LinkedWiki.
To install this extension, add the following to LocalSettings.php:
require_once( $IP."/extensions/LinkedWiki/lib/4store/SparqlTools.php"); require_once( "{$IP}/extensions/LinkedWiki/LinkedWiki.php" ); $smwgDefaultStore = "SMW_LinkedWikiStore"; //put the address of your 4store endpoint or SPARQL 1.1-compatible endpoint //WARNING! this address has to be accessible only by the wiki! $wgLinkedWikiEndPoint = "http://localhost:8080/"; //put the graph name where the data of your wiki will be recorded $wgLinkedWikiGraphWiki = "http://fr.linkedwiki.org/wiki/"; //put the address of your endpoint where the user can perform an Http Get request without the right to Write in your endpoint. $wgLinkedWikiLocalEndPoint = "http://fr.linkedwiki.org/";
Installation of 4Store [edit]
See also the site of 4store
Without triplestore for your Wiki [edit]
Install Extension:Semantic MediaWiki.
If you want to use a widget with SPARQL, install Extension:Widgets.
Extract the downloaded archive into your extension/directory. The folder name of the destination is LinkedWiki.
To install this extension, add the following to LocalSettings.php:
require_once( $IP."/extensions/LinkedWiki/lib/4store/SparqlTools.php"); require_once( "{$IP}/extensions/LinkedWiki/LinkedWiki.php" ); $wgLinkedWikiEndPoint = "http://fr.linkedwiki.org/"; //put address of your endpoint 4store or endpoint $wgLinkedWikiGraphWiki = "http://fr.linkedwiki.org/wiki/"; //put the graph by default in this endpoint $wgLinkedWikiLocalEndPoint = $wgLinkedWikiEndPoint ;
Mailing list / Google Group [edit]
- FAQ and problems : http://groups.google.com/group/linkedwiki


