Extension:LinkedWiki/Sparql parser

From MediaWiki.org
Jump to navigation Jump to search

The SPARQL parser is able to build a visualization in your Wiki with results of a SPARQL query.

You can select two types of visualization: with Sgvizler2 (a Javascript lib) with a lot of charts/tables or via a HTML table where you can customize each columns with templates.

If your data is only accessible with credentials, you must use the HTML table generated by PHP to preserve your credentials. Moreover, by default, the HTML table of SPARQL results is saved in the wiki cache. In this manner, your SPARQL service is also less solicited (Details).

If your data is public, you can use the two methods.

Usage[edit]

With the default endpoint[edit]

  • Querying without the parameter "endpoint" is possible but the variable $wgLinkedWikiConfigDefaultEndpoint has to be in the localsettings (see installation). By default the extension uses the endpoint of Wikidata.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5}}
  • Querying the properties of the current page :
{{#sparql:select * where { <PAGEIRI> ?y ?z . } }}

With an endpoint defined in the configuration[edit]

{{#sparql:select * where { ?x ?y ?z . } LIMIT 5|config=https://query.wikidata.org}}

With a specific endpoint[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=https://query.wikidata.org/sparql}}

Parameters of Sgvizler2 charts and tables[edit]

Sgvizler2 is a javascript wrapper for easy visualisation of SPARQL result sets (and a jQuery plugin).

You can find the list of available visualizations in the "special:SPARQL editor" page and in the doc of Sgvizler.

Parameter: chart[edit]

  • Select the visualization :
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | chart=bordercloud.visualization.DataTable}}

Parameter: options[edit]

  • Each visualization has its own options, the options parameter contains the visualization's options and ! is their separator:
{{#sparql:
select * where { ?x ?y ?z . } LIMIT 5
| chart=bordercloud.visualization.DataTable
| options=width=100%!height=500px
}}

Parameters to customize the HTML table[edit]

Parameter: headers[edit]

  • Change the headers.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | endpoint = https://query.wikidata.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 = https://query.wikidata.org/sparql |headers= &nbsp;,name2,name3 |classHeaders= class="unsortable",, }}

Example:

Linkedwiki example2.png

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 = https://query.wikidata.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 = https://query.wikidata.org/sparql  |headers=Name1,Name2 |templates= Test1,Test1 }}

Parameter: footer[edit]

  • you can remove the footer of array:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = https://query.wikidata.org/sparql  |footer=NO }}


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 = https://query.wikidata.org/sparql |cache=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 = https://query.wikidata.org/sparql |templateBare=tableCell }}

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 = https://query.wikidata.org/sparql  |debug=YES }}

Parameter: log[edit]

You can control the log levels about possible SPARQL errors. If there is an SPARQL error :

  • level 0 : any messages
  • level 1 : a short message
  • level 2 : a short message and details, if available.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = https://query.wikidata.org/sparql  | log=2 }}