SPARQL

Run SPARQL queries and template their results via Lua

On this page

External links

SPARQL for MediaWiki

Executing SPARQL queries and templating their results via Lua.

Professional Wiki created SPARQL. We are MediaWiki developers that provide professional MediaWiki services.

We thank Freie Universität Berlin for funding initial development.

Usage Documentation

Define a Lua module that requires the SPARQL binding and uses its runQuery method.

Example:

Create page Module:MySPARQL

local sparql = require('SPARQL') -- Load the SPARQL binding

local p = {}

function p.showFirstValue(frame)
  local sparqlQuery = frame.args[1]
  local queryResults = sparql.runQuery(sparqlQuery) -- Use the runQuery method

  local firstColName = queryResults['head']['vars'][0]
  return queryResults['results']['bindings'][0][firstColName]['value']
end

return p

Which can then be invoked via Scribunto's normal mechanisms from within wikitext.

Example:

{{#invoke:MySPARQL|showFirstValue|your SPARQL query here}}

Lua module Examples:

Installation

Requirements

  • PHP 8.1 or later
  • MediaWiki 1.39 or later
  • Scribunto

Load and enable

Load the extension using Composer:

COMPOSER=composer.local.json composer require --no-update professional-wiki/sparql:~1.0

Enable the extension by adding the following to your LocalSettings.php:

wfLoadExtension( 'SPARQL' );

You can verify the installation by checking your wiki's Special:Version page.

More MediaWiki Extensions

View all our extensions

Professional MediaWiki Services

MediaWiki services by the authors of SPARQL