Jump to content

Topic on Extension talk:LinkedWiki

Fail to insert to SPARQL endpoint

9
193.170.253.73 (talkcontribs)

Hello!

I am struggling to do insert from Mediawiki 1.39.5 to GraphDB SPARQL endpoint. I have installed the LinkedWiki 3.7.1 compatible with MW. Also, i am running SMW 4.1.1, PHP 8.1.2 and MySQL 8.0.35

In the Special:SparqlQuery I can perform SELECT queries no problem.

However, when I try to perform the following insert, I get Error message: Sorry, you have not configure the endpoint to update the database.

Which is strange since the same statement run just fine in the GraphDB sparql endpoint

PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT {
         GRAPH <http://example> {
          <http://example/book2> dc:title "A new book2" ;
                                 dc:creator "A.N.Other2" .
         }

Here is my setting in LocalSettings.php

wfLoadExtension( 'LinkedWiki' );

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

$wgLinkedWikiConfigSPARQLServices["http://localhost/graphdb"] = array(
	"debug" => true,
	"isReadOnly" => false,
	"typeRDFDatabase" => "graphdb",
	"endpointRead" => "http://localhost:3030/graphdb/myrepository",
	"endpointWrite" => "http://localhost:3030/graphdb",
	"login" => "test",
	"password" => "test",
	"HTTPMethodForRead" => "POST",
	"HTTPMethodForWrite" => "POST",
	"lang" => "en",
	"nameParameterRead" => "query",
	"nameParameterWrite" => "update",
    "storageMethodClass" => "GraphdbStorageMethod"
);

$wgLinkedWikiSPARQLServiceSaveDataOfWiki= "http://localhost:3030/graphdb";

And the GraphdbStorageMethod.php

<?php

class GraphdbStorageMethod extends StorageMethodAbstract {
    /**
     * @return string
     */

    private $graphNamed = "http://localhost/graphdb"; 

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

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

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

    /**
     * @return string
     */
    public function getQueryInsertValue() {
        return <<<EOT
INSERT DATA
    {
            ?subject ?property ?value .
    }
EOT;
    }

    /**
     * @return string
     */
    public function getQueryDeleteSubject() {
        return <<<EOT
DELETE
        { ?subject ?property ?value . }
WHERE
        { ?subject ?property ?value . }

EOT;
    }

    /**
     * @param string $url
     * @return string
     */
    public function getQueryLoadData( $url ) {
        return "";
    }

}
193.170.253.73 (talkcontribs)

I also noticed this while using {{#sparql ..}} in a page and used the same query that it sent wrong "POST" request to the SPARQL server. Instead of .../sparql?update=... it is sending .../sparql?query=...

Karima Rafes (talkcontribs)
193.170.253.73 (talkcontribs)

Thank you for the quick response and the information. I have changed the variable but i am still getting the same error.

Karima Rafes (talkcontribs)

I didn't test with GraphDB but I think, it's a problem in the configuration. You can use the special page LinkedWiki to check each parameter in your configuration.

193.170.253.73 (talkcontribs)

Special page LinkedWiki has the same parameters, which i defined in my LocalSettings.php.

$wgLinkedWikiConfigSPARQLServices["http://localhost/graphdb"] = array( "debug" => true, "isReadOnly" => false, "typeRDFDatabase" => "graphdb", "endpointRead" => "http://localhost/graphdb/myrepository", "endpointWrite" => "http://localhost/graphdb/myrepository/statements", "login" => "test", "password" => "test", "HTTPMethodForRead" => "POST", "HTTPMethodForWrite" => "POST", "lang" => "en", "nameParameterRead" => "query", "nameParameterWrite" => "update",

   "storageMethodClass" => "GraphdbStorageMethod"

);

$wgLinkedWikiSPARQLServiceSaveDataOfWiki= "http://localhost/graphdb";

I don't know what is the exact issue.

Karima Rafes (talkcontribs)

Try, debug= false

Karima Rafes (talkcontribs)

What is your version of PHP? 7 is only supported for the moment (php8 is not supported by MediaWiki officially)

If there is always a problem with php7: OPTION A: if you pay a license GraphDB, you can probably ask the help of GraphDB support to open the PHP code. OPTION B: switch on another database OPTION C: debug the PHP code yourself and send me the fix ;)

193.170.253.73 (talkcontribs)

I am using php 8 and I am using free version of GraphDB. If php version is causing the problem then i will try with php7 and then update you about the issue.

Reply to "Fail to insert to SPARQL endpoint"