Extension:LinkedWiki/Configuration

From mediawiki.org

By default, LinkedWiki uses the file extension.json to describe the SPARQL services usable by the users of your Wiki, such as Wikidata. For your local SPARQL services, you can also use LocalSettings.php of your wiki.

Quick Start[edit]

LinkedWiki provides a new special page LinkedWiki configuration where you can see the details of your current configuration. When you change your configuration, this page can tell you if your wiki reads the configuration correctly.

The default parameters of SPARQL services are specified in the file LinkedWiki/extension.json. Before changing it, save a copy of this configuration as backup. The configuration http://www.example.org contains the default settings for all unknown endpoints and for incomplete configurations. For example: If users use the parameter endpoint of the #SPARQL parser function, the settings from the http://www.example.org configuration will be used to create the HTTP request (by default a HTTP POST request).

After installation, Wikidata will be the default SPARQL service, i.e. if you do a SPARQL query without specifying an endpoint or a configuration, Wikidata will be used to resolve the query. You can change the default service with the global variable $wgLinkedWikiSPARQLServiceByDefault in LocalSettings.php of your wiki.

Example, if you add a new SPARQL service:

$wgLinkedWikiConfigSPARQLServices["http://myEndpoint"] = array(
	"endpointRead" => "http://myEndpoint/sparql"
);

The system completes this configuration with the settings from the default configuration, i.e. in the end the configuration of this new SPARQL service will look like this:

	"isReadOnly": true,
	"debug": false,
	"proxyHost": "",
	"proxyPort": 0,
	"endpointRead": "http://myEndpoint/sparql",
	"endpointWrite": "",
	"login": "",
	"password": "",
	"HTTPMethodForRead": "POST",
	"HTTPMethodForWrite": "POST",
	"nameParameterRead": "query",
	"nameParameterWrite": "update",
	"lang": "en",
	"storageMethodClass": "SimpleStorageMethod"

In the same way you can set the other parameters in your configuration. See examples for configurations: basic endpoints in the Linked Open Data

The credentials will never be shown in the special page.

Wikidata and other services use their own RDF schemas. The Lua functions can make it easier for users to add and query data without learning all these schemas. You need to define a new storageMethodClass for each schema used by your SPARQL services, e.g. #Basic example with a private database and a simple ontology

If you have a question, you can use the talk page.

Basic example with a private database and a simple RDF schema[edit]

In the LocalSettings.php for a Virtuoso SPARQL service:

$wgLinkedWikiConfigSPARQLServices["http://database-test/data"] = array(
	"debug" => false,
	"isReadOnly" => false,
	"typeRDFDatabase" => "virtuoso",
	"endpointRead" => "http://database-test:8890/sparql/",
	"endpointWrite" => "http://database-test:8890/sparql-auth/",
	"login" => "dba",
	"password" => "dba",
	"HTTPMethodForRead" => "POST",
	"HTTPMethodForWrite" => "POST",
	"lang" => "en",
	"storageMethodClass" => "DatabaseTestDataMethod",
	"nameParameterRead" => "query",
	"nameParameterWrite" => "update"
);

If you want to replace Wikidata by this new SPARQL service, you need to add this line:

$wgLinkedWikiSPARQLServiceByDefault= "http://database-test/data";

If you want to use this SPARQL service to save all RDF data of wiki, you need to add this line:

$wgLinkedWikiSPARQLServiceSaveDataOfWiki= "http://database-test/data";

To save/delete correctly each triple in the good graph, you have to create a new class. In this example, we created the class DatabaseExampleMethod in the folder "LinkedWiki/storageMethod":

<?php
class DatabaseExampleMethod extends StorageMethodAbstract
{
    private $graphNamed = "http://databaseExample";

    public function setGraph($graphNamed)
    {
        $graphNamed = trim($graphNamed);
        $this->graphNamed = $graphNamed;
    }

    public function getGraph()
    {
        return $this->graphNamed;
    }

    public function getQueryReadStringWithTagLang()
    {
        return <<<EOT
SELECT DISTINCT  ?value  
WHERE 
    {GRAPH <$this->graphNamed>  
        { 
            ?subject ?property ?value . 
        } 
    FILTER langMatches( lang(?value), ?lang )
    }
EOT;
    }

    public function getQueryReadStringWithoutTagLang()
    {
        return <<<EOT
SELECT DISTINCT  ?value  
WHERE 
    {GRAPH <$this->graphNamed>  
        { 
            ?subject ?property ?value . 
        } 
    FILTER ( lang(?value) = "" )
    }
EOT;
    }

    public function getQueryReadValue()
    {
        return <<<EOT
SELECT DISTINCT  ?value  
WHERE 
    {GRAPH <$this->graphNamed>  
        { 
            ?subject ?property ?value . 
        } 
    }
EOT;
    }

    public function getQueryInsertValue()
    {
        return <<<EOT
INSERT DATA 
    {GRAPH <$this->graphNamed>  
        { 
            ?subject ?property ?value . 
        } 
    }
EOT;
    }

    public function getQueryDeleteSubject()
    {
        return <<<EOT
DELETE  
    {GRAPH <$this->graphNamed>  
        { ?subject ?property ?value . } 
    } 
WHERE 
    {GRAPH <$this->graphNamed>  
        { ?subject ?property ?value . } 
    }
EOT;
    }
}

With this new class, you need to add it in the LocalSettings.php to use it in the configuration of your SPARQL service.

$wgAutoloadClasses['DatabaseDaapMethod'] = "$IP/extensions/LinkedWiki/storageMethod/DatabaseExampleMethod.php";

Examples of configuration[edit]

Wikidata[edit]

Wikidata doesn't support the POST method.

$wgLinkedWikiConfigSPARQLServices["http://www.wikidata.org"] = array(
        "debug" => false,
        "isReadOnly" => true,
        "endpointRead" => "https://query.wikidata.org/sparql",
        "typeRDFDatabase" => "blazegraph",
        "HTTPMethodForRead" => "GET",
        "storageMethodClass" => "WikidataStorageMethod",
        "lang" => "en"
);

The storage method for Wikidata:

<?php
class WikidataStorageMethod extends StorageMethodAbstract
{

    public function getQueryReadStringWithTagLang()
    {
        return <<<EOT
SELECT DISTINCT  ?value
WHERE
        {
            ?subject ?property ?value .
            FILTER ( lang(?value) = ?lang )
        }
EOT;
    }

    public function getQueryReadStringWithoutTagLang()
    {
        return <<<EOT
SELECT DISTINCT  ?value
WHERE
        {
            ?subject ?property ?value .
            FILTER ( lang(?value) = "" )
        }
EOT;
    }

    public function getQueryReadValue()
    {
        return <<<EOT
SELECT DISTINCT  ?value
WHERE
        {
            ?subject ?property ?value .
        }
EOT;
    }

    public function getQueryInsertValue()
    {
        return ""
    }

    public function getQueryDeleteSubject()
    {
        return ""
    }

}

BNF[edit]

$wgLinkedWikiConfigSPARQLServices["http://data.bnf.fr"] = array(
        "endpointRead" => "http://data.bnf.fr/sparql",
        "typeRDFDatabase" => "virtuoso",
        "HTTPMethodForRead" => "GET"
);

Jena Fuseki[edit]

$wgLinkedWikiConfigSPARQLServices["http://example-jena.com"] = array(
        "isReadOnly" => true,
        "typeRDFDatabase" => "fuseki",
        "endpointRead" => "http://localhost/test/sparql",
        "HTTPMethodForRead" => "GET"
);