Please show your support of Waihekepedia by adding a link to us from your web site. Waihekepedia T Shirts now available at the Ostend Market

Sparql Result Format Documentation

Jump to navigation Jump to search

Step 1. Define one or more sparql endpoint in LocalSettings.php

$wgSparqlEndpointDefinition['<endpoint name>'] = array(
'url' =>'<endpoint url>',
'basicAuth' => array( /*optional*/
'user' => '<basic auth user>',
'password' => '<basic auth password>'
),
'connectionTimeout' => 0, /*in seconds*/
'requestTimeout' => 30,/*in seconds*/
'verifySSLCertificate' => false, /*to disable server certificate verification*/
'prefixes' => array( /*optional*/
'skos' => 'http://www.w3.org/2004/02/skos/core#',
'foaf' => 'http://xmlns.com/foaf/0.1/',
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
'owl' => 'http://www.w3.org/2002/07/owl#',
'<prefix>' => '<namespace>',
...
)
);
If more than one endpoint is specified, ensure that the endpoint name is unique.
You can optionally specify credentials for http basic authentication.
You can optionally specify a list of prefixes. These are automatically added to sparql query (No need to redefine each time).

Step 2. Export sparql result in different format using magic words described below

Html Table

Description

Convert the result of a sparql query to an html table

Usage

{{#sparql2table:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEscapedQuery Sparql query to execute True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
spinnerImagePath Url of image to show while the query is in execution. False
divStyle css definitions to put inline the container div False
tableClass output html table css class False
columnConfiguration

Javascript array of object for data presentation (see table below).
In cellValuePattern and cellLinkPattern you can use some usefull placeholders:

  • {%s} - the current cell value from the SPARQL query.
  • {%s[<fieldName>]} If you want to get the value of other field from query.
  • {%n[<outputFormat>]@<locale>}. If you want to format numeric values. For output format see [1]. locale attribute is optional. You can configure the global default value in LocalSettings with $wgSparqlResultFormatTableNumberDefaultLocale variable. If not defined 'en' value is used.
NameDescription MandatoryDefault valueExample
queryField Name of the column in the sparql query (without ?) True
label Column header shown in table True
showLink true or false if you want every cell of this column have links Truefalse
cellValuePattern the pattern to format the cell value True
cellLinkPattern the pattern to generate the link for the cell True
visible true or false if you don't want to output the specific column Truetrue
FalsecolumnConfiguration=[{queryField:'type_label', label:'Asset type', showLink:'false',cellValuePattern:'value={%s}'}]
columnConfiguration=[{queryField:'totalCost', label:'Total cost', showLink:'false',cellValuePattern:'€ {%n[0,00.00]@it}'}]
cssEvenRowClass Css class of even elements of output table False
cssOddRowClass Css class of odd elements of output table False
cssEvenTdClass Css class of all elements of all even rows of output table False
cssOddTdClass Css class of all elements of all odd rows of output table False
noResultMessage Text message to be shown when the query returns no elements False
csvExport true/false. If true, generates a link to download the content of the table as csv file Falsefalse
csvFileName The name of the output csv file Falseexport.csv
csvLinkLabel Label of the link to download the csv False
linkBasePath deprecated ⧼sprf.param.linkBasePath⧽ False

Sparql query structure

No constraint on sparql query. All fields in select list will be columns in output table.

CSV

Description

Produce a link to download the result of a sparql query as csv file

Usage

{{#sparql2csv:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
sparqlEscapedQuery Sparql query to execute True
divStyle css definitions to put inline the container div False
scriptPath deprecated Value of variable {{SCRIPTPATH}} False
headerMapping JSON object to map each column in the sparql query to another label False|headerMapping={comp_label:"Application Component",app_label:"Application", proc_label:"Business Process"}
filename Name of the output csv file Falseexport.csv
separator Separator char to be used in csv file False;
linkButtonLabel If defined, the magic word will produce a <button> element with this parameter as label False
linkButtonCSSClass if linkButtonLabel is defined you can specify the css class to the <button> element False
label if linkButtonLabel is not defined, the magic word will produce a <a> element with this parameter as label FalseDownload as CSV

Sparql query structure

No constraint on sparql query. All fields in select list will be exported in csv.

Pie Chart

Description

Convert the result of a sparql query to a piechart

Usage

{{#sparql2piechart:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
sparqlEscapedQuery Sparql query to execute True
divStyle css definitions to put inline the container div False
spinnerImagePath Url of image to show while the query is in execution. False
divCssClass Css class applied to container div False
divCssClassFullScreen Css class applied to container div in fullscreen mode False
extraOption You can specify as many extraOption parameter as you want. Each option must be specified in the following format: propName:propValue.The list of all supported options is listed in the table below. False

Extra Options

NameDescription MandatoryDefault valueExample
chart.title Title of the chart False|extraOption=chart.title:New Title
chart.series.color List of colour to use in series False|extraOption=chart.series.color:[ 'red','#000000','FFAACC']
chart.serie.label Label of the series False|extraOption=chart.serie.label:series label
chart.tooltip.label.link.show true or false to specify if the label in tooltip is linkable False|extraOption=chart.tooltip.label.link.show:false
chart.tooltip.label.link.pattern Pattern to generate the url in label link False|extraOption=chart.tooltip.label.link.pattern:http://www.google.it?q={%s}
chart.tooltip.label.pattern Pattern applied to label in tooltip False{%s}|extraOption=chart.tooltip.label.pattern:Category {%s}
chart.tooltip.value.pattern Pattern applied to the numeric value in tooltip False{%d}|extraOption=chart.tooltip.value.pattern:{%d} €

Sparql query structure

The query must adjust to the following rules:

  • The first column in select list represent each slice of the pie.
  • The second column in select list must be composed by numerical values.

select ?person count(?property) as ?num

where { ?person rdf:type foaf:Person. ... }

Donut Chart

Description

Convert the result of a sparql query to a donutchart

Usage

{{#sparql2donutchart:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
sparqlEscapedQuery Sparql query to execute True
divStyle css definitions to put inline the container div False
spinnerImagePath Url of image to show while the query is in execution. False
divCssClass Css class applied to container div False
divCssClassFullScreen Css class applied to container div in fullscreen mode False
extraOption You can specify as many extraOption parameter as you want. Each option must be specified in the following format: propName:propValue.The list of all supported options is listed in the table below. False

Extra Options

NameDescription MandatoryDefault valueExample
chart.title Title of the chart False|extraOption=chart.title:New Title

Sparql query structure

The query must adjust to the following rules:

  • The first column in select list represent each slice of the donut.
  • The following columns in select list must be composed by numerical values. Each of these columns represent a numerical series.

select ?person count(?property) as ?num count(?property2)as ?num2

where { ?person rdf:type foaf:Person. ... }

Bar Chart

Description

Convert the result of a sparql query to a barchart

Usage

{{#sparql2barchart:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
sparqlEscapedQuery Sparql query to execute True
divStyle css definitions to put inline the container div False
spinnerImagePath Url of image to show while the query is in execution. False
divCssClass Css class applied to container div False
divCssClassFullScreen Css class applied to container div in fullscreen mode False
seriesConfiguration

JSON array to configure every series. For each element you can specify:

  • label
  • color
  • assetPattern
  • assetLinkPattern
  • showLink
  • valuePattern
False|seriesConfiguration=[{label:'Applications', color:'blue',showLink:'true',assetLinkPattern:'http://www.google.it?q={%s}' },{label:'Components',color:'red' ,showLink:'true',assetLinkPattern:'http://www.google.it?q={%s}'} ]
extraOption You can specify as many extraOption parameter as you want. Each option must be specified in the following format: propName:propValue.The list of all supported options is listed in the table below. False

Extra Options

NameDescription MandatoryDefault valueExample
chart.title Title of the chart False|extraOption=sprf.options.chart.title:New title
chart.direction Direction of bars (vertical or horizontal) Falsevertical|extraOption=chart.direction:horizontal
chart.bar.width Width of the bar in pixels Falseauto|extraOption=chart.bar.width:10
chart.bar.margin Number of pixels between groups of bars at adjacent axis values False8|extraOption=chart.bar.margin:10
chart.bar.padding Number of pixels between adjacent bars at the same axis value False10|extraOption=chart.bar.margin:10
chart.axis.x.label Name of x axis False
chart.axis.y.label Name of y axis False
chart.axis.x.label.font.size Font size for x axis label False14pt|extraOption=chart.axis.x.label.font.size:20pt
chart.axis.y.label.font.size Font size for y axis label False14pt|extraOption=chart.axis.y.label.font.size:20pt
chart.axis.x.font.size Font size for values in x axis False10pt|extraOption=chart.axis.x.font.size:14pt
chart.axis.y.font.size Font size for values in y axis False10pt|extraOption=chart.axis.y.font.size:14pt
chart.axis.x.angle Angle of text of x axis values, measured clockwise False-30|extraOption=chart.axis.x.angle:-20
chart.axis.y.angle Angle of text of y axis values, measured clockwise False0|extraOption=chart.axis.y.angle:-20
chart.legend.show True or false to specify to show the legend Falsetrue|extraOption=chart.legend.show:false
chart.legend.location Location for legend. Possible values: nw, n, ne, e, se, s, sw, w Falsene|extraOption=chart.legend.location:s
chart.height.automatic Only for horizontal barchart it computes automatically the height of the container based on number of results Falsefalse|extraOption=chart.height.automatic:true
chart.axis.label.max.length Maximum value for automatic height False15|extraOption=chart.axis.label.max.length:30

Sparql query structure

The query must adjust to the following rules:

  • The first column in select list represent each element in the x axis (for vertical chart) or y axis (for horizontal chart).
  • The following columns in select list must be composed by numerical values. Each of these columns represent a numerical series.

select ?person count(?property) as ?num count(?property2)as ?num2

where { ?person rdf:type foaf:Person. ... }

Bubble Chart

Description

Convert the result of a sparql query to a bubblechart

Usage

{{#sparql2bubblechart:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
sparqlEscapedQuery Sparql query to execute True
divStyle css definitions to put inline the container div False
spinnerImagePath Url of image to show while the query is in execution. False
divCssClass Css class applied to container div False
divCssClassFullScreen Css class applied to container div in fullscreen mode False
extraOption You can specify as many extraOption parameter as you want. Each option must be specified in the following format: propName:propValue.The list of all supported options is listed in the table below. False

Extra Options

NameDescription MandatoryDefault valueExample
chart.title Title of the chart False|extraOption=sprf.options.chart.title:New title
chart.axis.x.label Name of x axis False
chart.axis.y.label Name of y axis False
chart.axis.x.label.font.size Name of x axis False14pt|extraOption=chart.axis.x.label.font.size:20pt
chart.axis.y.label.font.size Font size for y axis label False14pt|extraOption=chart.axis.y.label.font.size:20pt
chart.axis.x.font.size Font size for values in x axis False10pt|extraOption=chart.axis.x.font.size:14pt
chart.axis.y.font.size Font size for values in y axis False10pt|extraOption=chart.axis.y.font.size:14pt
chart.legend.column.asset The column name in legend for asset element (the single bubble element name) False|extraOption=
chart.legend.column.radius The column name in legend for the r coordinate False|extraOption=
chart.legend.show True or false to specify to show the legend False|extraOption=
chart.tooltip.x.label Name of x coordinate shown in tooltip False|extraOption=chart.tooltip.x.label:
chart.tooltip.y.label Name of y coordinate shown in tooltip False|extraOption=
chart.tooltip.r.label Name of r coordinate shown in tooltip False|extraOption=
chart.tooltip.asset.label.pattern Text pattern applied to show the asset element (the single bubble element) in tooltip. Refer to current name using the placeholder {%s} False|extraOption=
chart.tooltip.asset.link.show true or false if the asset label must be also a link False|extraOption=
chart.tooltip.asset.label.link.pattern Text pattern to generate the link for asset label. Refer to current name using the placeholder {%s} False|extraOption=
chart.tooltip.x.value.pattern Text pattern applied to show the value of x coordinate. Refer to current value using the placeholder {%d} False|extraOption=
chart.tooltip.y.value.pattern Text pattern applied to show the value of y coordinate. Refer to current value using the placeholder {%d} False|extraOption=
chart.tooltip.r.value.pattern Text pattern applied to show the value of r coordinate. Refer to current value using the placeholder {%d} False|extraOption=

Sparql query structure

The query must adjust to the following rules:

  • The first column in select list represent each bubble on the chart.
  • The 2nd, 3rd e 4th column in select list must be composed by numerical values. They represent the x, y and r coordinate of the bubble.

select ?person count(?property) as ?x count(?property2) as ?y count(?property3) as ?r

where { ?person rdf:type foaf:Person. ... }

Treemap

Description

Convert the result of a sparql query to a zoomable treemap

Usage

{{#sparql2treemap:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
sparqlEscapedQuery Sparql query to execute True
divStyle css definitions to put inline the container div False
spinnerImagePath Url of image to show while the query is in execution. False
divCssClass Css class applied to container div False
divCssClassFullScreen Css class applied to container div in fullscreen mode False
rootElement The top element in the hierarchy. This could be styled in different way from other nodes. If the sparql query return object uris you must specify the uri ot the root element. Otherwise you must specify the label. True
leavesLinkPattern Pattern to generate url in leaves node. Refer to leaf value using {%s} False
openLinkOnLeaves true/false. If specified on leaves node it will open the url specified. False

Sparql query structure

The query must adjust to the following rules:

  • All rows must represent a couple: parent value e child value with an optional numerical value
  • The first column is the parent. The second is the child. The third (optional) is the weight for leaves node.
  • If the third column is not specified the weight of all leaves will be set to 1

select ?parent ?child

where { ?parent ?relation ?child. ... }

Node Graph

Description

Convert the result of a sparql query to a connected graph

Usage

{{#sparql2graph:|divId=table1 |sparqlEndpoint=endpoint1|sparqlEscapedQuery=select ?parent ?....}}

Parameters

NameDescription MandatoryDefault valueExample
divId Identifier of this element. Must be unique inside the page True
sparqlEndpoint Name of the endpoint to invoke defined in LocalSettings.php True
sparqlEscapedQuery Sparql query to execute True
queryTimeout Maximum time for execution of a query (in milliseconds) False20000
divStyle css definitions to put inline the container div False
spinnerImagePath Url of image to show while the query is in execution. False
divCssClass Css class applied to container div False
nodeConfiguration Configuration of nodes aspect based on their category (rdf:type). JSON syntax of array containing a definition for each node category.

For each element you can specify:

  • category
  • nodeColor
  • image
  • dataTypeProps
  • objectProps
False|nodeConfiguration=[ { category:"Application",nodeColor:"#000000", image:"{{filepath:Application_icon.png}}"}, { category:"Application Component",nodeColor:"#00FF00", image:"{{filepath:Component_icon.png}}"}, { category:"Person",nodeColor:"#FF0000",image:"{{filepath:Person.png}}", dataTypeProps:[ {prop:'foaf:name', format:'Name: {%s}'}, {prop:'foaf:surname', format:'Surname: {%s}'} ], objectProps:[ {prop:'skos:broader',direction:'OUT', label:'Has broader'} ]} ]
edgeConfiguration Configuration of edges aspect based on the relationship. JSON syntax of array containing a definition for each object property.

For each element you can specify:

  • relation
  • edgeColor
False|edgeConfiguration=[{ relation:"Belongs to application",edgeColor:"#00FF00"}]
rootElement The top element in the hierarchy. This could be styled in different way from other nodes. If the sparql query return object uris you must specify the uri ot the root element. Otherwise you must specify the label. False
rootElementColor The color of rootElement node False
rootElementImage The image of rootElement node (this will override the rootElementColor property) False
showLegend true/false False
defaultNodeColor Html default color for nodes (if not specified in nodeConfiguration param) False|defaultNodeColor=#CCC
defaultEdgeColor Html default color for edge (if not specified in edgeConfiguration param) False|defaultEdgeColor=#CCC
splitQueryByUnion If the sparql param contains UNION parts and this parameter is set to 'true' it will split the query with n unions in n query with 1 query condition. False
minZoom Min value for zoom False
maxZoom Max value for zoom False
layout Name of layout to use. Possible values: dagre, random, preset, grid, circle, concentric, breadthfirst, cose. [1] Falsedagre
layoutOptions Extra layout options. [1] False|layoutOptions={rankSep:200}
maxWordLength Maximum word lenght in node label. False
maxLabelLength Maximum label lenght False
nodeStyle Style of all nodes. [1] False|nodeStyle={shape:'roundrectangle', width:120, height:80,'text-valign': 'center','text-halign': 'center','font-size':'12','border-color' : '#000','border-width' : 1,'text-max-width':120}
edgeStyle Style of all edges [1] False
labelLinkPattern Text pattern to generate the link of node label in tooltip. Refer to node label with placeholder {%s} False
categoryLinkPattern Text pattern to generate the link of node category in tooltip. Refer to node category with placeholder {%s} False
maxNumNodes Maximum number of nodes to be drawn. If the sparql query returns more records than this parameter no graph will be shown False200
action.fullscreen.visible since 1.0.15Specify if the fullscreen button must be visible or not Falsetrue|action.fullscreen.visible=false
action.donwload.image.visible since 1.0.15Specify if the download image button must be visible or not Falsetrueaction.donwload.image.visible|false
action.zoom.controls.visible since 1.0.15Specify if zoom controls must be visible or not Falsetrue|action.zoom.controls.visible=false

Sparql query structure

The query must adjust to the following rules:

  • The select list must contains exactly this variable names: ?parent_uri ?parent_name ?child_uri ?child_name ?parent_type ?parent_type_uri ?child_type ?child_type_uri ?relation_uri ?relation_name

select distinct ?parent_uri ?parent_name ?child_uri ?child_name ?parent_type ?parent_type_uri ?child_type ?child_type_uri ?relation_uri ?relation_name

where { ... }

Old Version (for retro-compatibility) Do not use!

The query must adjust to the following rules:

  • The select list must contains exactly this values: ?parent_name ?child_name ?parent_type ?child_type ?relation_name

select distinct ?parent_name ?child_name ?parent_type ?child_type ?relation_name

where { ... }