Actions

Difference between revisions of "LinkedWiki-Mediawiki Extension"

From /oooooooooo.io/

Line 33: Line 33:
 
SELECT DISTINCT ?country ?countryName ?capital ?capitalName ?capitalPop  
 
SELECT DISTINCT ?country ?countryName ?capital ?capitalName ?capitalPop  
 
WHERE
 
WHERE
{
 
        SERVICE <https://query.wikidata.org/sparql>
 
 
         {
 
         {
             ?country wdt:P31 wd:Q6256 . # instance of: country
+
             ?country wdt:P31 wd:Q6256 .  
 
             ?country rdfs:label ?countryName .  
 
             ?country rdfs:label ?countryName .  
 
                 FILTER (LANG(?countryName) = "en").
 
                 FILTER (LANG(?countryName) = "en").
             ?country wdt:P30 wd:Q46 .   # continent: Europe
+
             ?country wdt:P30 wd:Q46 .
 
             ?country wdt:P36 ?capital .
 
             ?country wdt:P36 ?capital .
 
             ?capital rdfs:label ?capitalName .
 
             ?capital rdfs:label ?capitalName .
 
                 FILTER (LANG(?capitalName) = "en")
 
                 FILTER (LANG(?capitalName) = "en")
             ?capital wdt:P1082 ?pop . # how to display decimal
+
             ?capital wdt:P1082 ?pop .  
 
                 FILTER ( abs(?pop) > 1000000)
 
                 FILTER ( abs(?pop) > 1000000)
        }              BIND(round(?pop) as ?capitalPop ) # bind round(?pop) to var ?capitaPop
+
                BIND(round(?pop) as ?capitalPop )  
}
+
        }              
 
ORDER BY DESC(?capitalPop)  
 
ORDER BY DESC(?capitalPop)  
 
LIMIT 20
 
LIMIT 20

Revision as of 14:34, 15 May 2020


The LinkedWiki extension lets you reuse Linked Data in your wiki. You can get data from Wikidata or another source directly with a SPARQL query. This extension also provides Lua functions for building your modules so that you can write your data in your RDF database.

installation

You will need to install yarn , I have followed the instructions in https://classic.yarnpkg.com/en/docs/install/#debian-stable which as I have problems with the yarn packed from the Debian Stable apt source.


cd extensions
git clone https://github.com/wikimedia/mediawiki-extensions-LinkedWiki.git LinkedWiki
cd LinkedWiki

Install composer (locally). I prefer not to have composer installed system wide, so I will install it in the LinkedData extension dir.

curl -sS https://getcomposer.org/installer | php

Run composer install, to install the dependencies

php composer.phar install --no-dev

And finally run yarn install:

yarn install --production=true

Load the extension in LocalSettings.php, by adding to it:

wfLoadExtension( 'LinkedWiki' );

Check the installation by going to Special:Interwiki and Special:LinkedWikiConfig pages, note that the extension does not appear in Special:Version.

And we can make a Test SPARQL query against Wikidata in Special:SparqlQuery, with the query, which asks for the European capitals with a population of the more that 1 million

SELECT DISTINCT ?country ?countryName ?capital ?capitalName ?capitalPop 
WHERE
        {
            ?country wdt:P31 wd:Q6256 . 
            ?country rdfs:label ?countryName . 
                FILTER (LANG(?countryName) = "en").
            ?country wdt:P30 wd:Q46 .  
            ?country wdt:P36 ?capital .
            ?capital rdfs:label ?capitalName .
                FILTER (LANG(?capitalName) = "en")
            ?capital wdt:P1082 ?pop . 
                FILTER ( abs(?pop) > 1000000)
                BIND(round(?pop) as ?capitalPop ) 
        }               
ORDER BY DESC(?capitalPop) 
LIMIT 20


Setting up & Config

I like to add the LinkedWiki important pages to the side bar so i add to Mediawiki:Sidebar

* Interwiki
** Special:LinkedWikiConfig|LinkedWikiConfig
** Special:Interwiki|Interwiki Data
** Special:SparqlQuery|SparqlQuery
Code_Notes +
Date"Date" is a type and predefined property provided by Semantic MediaWiki to represent date values.
2020 +