Extension:LinkedWiki/Configuration

From MediaWiki.org
Jump to navigation Jump to search

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 use the LocaSettings.php of your wiki.

Quick start[edit]

In the special pages of your Wiki, you will find a new special page LinkedWiki configuration where you can see the details of your current configuration. When you change your configuration, you can check in this page if your wiki reads correctly your configuration.

The default parameters of SPARQL services are in the file LinkedWiki/extension.json. Before to change it, save a copy of the precedent configuration. The configuration http://www.example.org gives the configuration by default of unknown endpoint and for uncompleted configurations. For example : If users use the parameter endpoint of parser #SPARQL, it's the http://www.example.org's configuration will use to build the HTTP request (by default a HTTP POST request).

After installation, Wikidata is the service SPARQL by default that means, if you do a SPARQL query without precise an endpoint or a configuration, Wikidata will be use to resolve the query. You can change the service by default with this parameter $wgLinkedWikiSPARQLServiceByDefault in the LocalSettings.php of wiki.

Example, if you add a new SPARQL service:

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

The system completes the configuration with the configuration by default so at the end the configuration of this new SPARQL service will be :

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

Easily, you can use the other parameters in your configuration. The credentials doesn't show in the special page.

See examples of configuration : basic endpoints in the Linked Open Data

Wikidata and other use their own RDF schemas. The Lua functions can simplify the users's works without learn all these schemas but you need to define a new storageMethodClass for each schema used by your SPARQL services. Here, an example : #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"
);