Mediawiki with Fuseki triplestore backen: Difference between revisions

From artserver wiki
m (Text replacement - "Code_Notes" to "Code Notes")
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
In this page I will go over the steps required to setup Semantic Mediawiki with a Triple Storage graph database, with Apache Jena Fuseki<ref>https://jena.apache.org/documentation/</ref> SPARQL server.
{{#set: Section=Code Notes|
Date=2020}}
 
In this page I will go over the steps required to  
* setup Semantic Mediawiki with a Triple Storage graph database, with Apache Jena Fuseki<ref>https://jena.apache.org/documentation/</ref> SPARQL server.
* include a simple SPARQL endpoint interface within the wiki with LinkedWiki extension<ref>https://www.mediawiki.org/wiki/Extension:LinkedWiki</ref>
 


According to SMW documentation:<ref>https://www.semantic-mediawiki.org/wiki/Help:Using_SPARQL_and_RDF_stores</ref>
According to SMW documentation:<ref>https://www.semantic-mediawiki.org/wiki/Help:Using_SPARQL_and_RDF_stores</ref>
Line 10: Line 16:
See '''[[Fuseki SPARQL server]]'''
See '''[[Fuseki SPARQL server]]'''


 
==SMW Setting for Fuseki==
 
 
=SMW Setting for Fuseki=
With SMW installed and enabled
With SMW installed and enabled
  enableSemantics( 'localhost' );
  enableSemantics( 'localhost' );
Line 37: Line 40:
So we will rebuild the semantic wiki data
So we will rebuild the semantic wiki data
  php rebuildData.php -v -s 1000 -e 2999
  php rebuildData.php -v -s 1000 -e 2999
=SPARQL interface and embbed SPARQL queries with LinkedData extension=
In '''[[LinkedWiki-Mediawiki Extension]]''' I go over the process of installing, configuring and testing the [https://www.mediawiki.org/wiki/Extension:LinkedWiki LinkedWiki extension], which provides this wiki with:
* a SPARQL interface within the wiki at [[Special:SparqlQuery]]
** from which the wiki triple storage, but also other SPARQL endpoints
* syntax to embed SPARQL queries and display their results on wiki pages.


=Test queries=
=Test queries=
==All triples==
'''
In SPARQL interface'''
<source lang="sparql">
SELECT *
{
?s ?p ?v .
}
LIMIT 20
</source>
In curl:
curl http://sparql.oooooooooo.io/wiki/query -X POST --data 'query=%0ASELECT+*%0A%7B%0A%3Fs+%3Fp+%3Fv+.%0A%7D%0ALIMIT+20' -H 'Accept: application/sparql-results+json,*/*;q=0.9'
In SPARQL query run by ARQ
file: query.rq
<source lang="sparql">
SELECT * 
WHERE {
SERVICE <http://sparql.oooooooooo.io/wiki/query>
{
?s ?p ?v .
}
}
</source>
==Property:Section value:"Blog"==
Or, a query for all the triples that have ''Property:'' wiki:Property:Section  ''Value:'' "Blog"
<source lang="sparql">
PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX wiki: <http://oooooooooo.io/index.php/Special:URIResolver/>
SELECT ?s 
WHERE {
SERVICE <http://sparql.oooooooooo.io/wiki/query>
{
?s wiki:Property-3ASection "Blog" .
}
}
</source>
Which can be run by ARQ
arq --query wiki_query.rq
==In Fuseki interface==
==In Fuseki interface==


Line 54: Line 120:
PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
SELECT *
SELECT *
{?o swivt:page ?v}
</source>
All Page type properties:
<source lang="sparql">
PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX wiki: <http://oooooooooo.io/index.php/>
SELECT *
{
?s ?p "Blog" .
}
</source>
</source>
{?o swivt:page ?v}

Latest revision as of 13:53, 25 August 2022


In this page I will go over the steps required to

  • setup Semantic Mediawiki with a Triple Storage graph database, with Apache Jena Fuseki[1] SPARQL server.
  • include a simple SPARQL endpoint interface within the wiki with LinkedWiki extension[2]


According to SMW documentation:[3]

By default, Semantic MediaWiki (SMW) stores all data in the same relational database (usually, a MySQL database) that is used by MediaWiki. This ensures a simple setup, but a relational database is not an ideal type of storage for semantic data. A more natural data model for SMW data is RDF, a data format that organizes information in graphs rather than in fixed database tables.

See more in SMW2.0 Release Notes [4]

Running Fuseki

See Fuseki SPARQL server

SMW Setting for Fuseki

With SMW installed and enabled

enableSemantics( 'localhost' );

The following settings are added to LocalSettings.php

$smwgDefaultStore = 'SMWSparqlStore';
$smwgSparqlRepositoryConnector = 'fuseki';

$smwgSparqlEndpoint["query"] = 'http://localhost:3030/test/query';
$smwgSparqlEndpoint["update"] = 'http://localhost:3030/test/update';
$smwgSparqlEndpoint["data"] = '';

And an update needs to be performed:

php maintenance/update.php


After setting triple storage

After the configuration was changed, there is no data yet in the RDF database. To fill it with the current content of the wiki, it is necessary to refresh all data.[5]

So we will rebuild the semantic wiki data

php rebuildData.php -v -s 1000 -e 2999


SPARQL interface and embbed SPARQL queries with LinkedData extension

In LinkedWiki-Mediawiki Extension I go over the process of installing, configuring and testing the LinkedWiki extension, which provides this wiki with:

  • a SPARQL interface within the wiki at Special:SparqlQuery
    • from which the wiki triple storage, but also other SPARQL endpoints
  • syntax to embed SPARQL queries and display their results on wiki pages.



Test queries

All triples

In SPARQL interface

SELECT *
{
?s ?p ?v .
}
LIMIT 20

In curl:

curl http://sparql.oooooooooo.io/wiki/query -X POST --data 'query=%0ASELECT+*%0A%7B%0A%3Fs+%3Fp+%3Fv+.%0A%7D%0ALIMIT+20' -H 'Accept: application/sparql-results+json,*/*;q=0.9'

In SPARQL query run by ARQ

file: query.rq

SELECT *  
	WHERE {
		SERVICE <http://sparql.oooooooooo.io/wiki/query>
		{
		?s ?p ?v .
		}
	}

Property:Section value:"Blog"

Or, a query for all the triples that have Property: wiki:Property:Section Value: "Blog"

PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX wiki: <http://oooooooooo.io/index.php/Special:URIResolver/>

SELECT ?s  
	WHERE {
		SERVICE <http://sparql.oooooooooo.io/wiki/query>
		{
		?s 	wiki:Property-3ASection "Blog" .
		}
	}

Which can be run by ARQ

arq --query wiki_query.rq 


In Fuseki interface

All Page type properties:

swivt:page

Note: SWIVT is the Semantic Wiki Vocabulary and Terminology[6]

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX triplewiki: <http://localhost/triplestorage/index.php/>
PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
SELECT *
{?o swivt:page ?v}

All Page type properties:


PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX wiki: <http://oooooooooo.io/index.php/>
SELECT *
{
?s ?p "Blog" .
}
Code Notes +
Date"Date" is a type and predefined property provided by Semantic MediaWiki to represent date values.
2020 +