I'm a long-time fan of the graph visualization tool Gephi and since Wikimania 2019 I got involved with Wikidata. I was aware of the Gephi plugin "Semantic Web Importer", but when I check it out, I only find old tutorials connecting to DBpedia, not Wikidata:
- "Visualising Related Entries in Wikipedia Using Gephi" by Tony Hirst, 2012-07-03
- "Let’s Play Gephi: Dbpedia, RDF, Sparql and your favorite Actors" by Matthieu Totet, 2015-10-06
- "Gephi tutorials: Semantic Web Importer" by Matthieu Totet, 2017-01-31
It took a tiny bit of fiddling, but turns out Wikidata seems perfectly compatible with the Semantic Web Importer plugin. Get the REST endpoint for the Wikidata:SPARQL query service (EndPoint URL: https://query.wikidata.org/sparql
, query tag name: query
), explicitly supply the needed prefixes and then it should work to adapt the WDQS example "Groups of characters in the Marvel universe" for Gephi (it requires a CONSTRUCT rather than a SELECT):
#defaultView:Graph
SELECT ?char ?charLabel ?group ?groupLabel ("7FFF00" as ?rgb)
WHERE {
?group wdt:P31 wd:Q14514600 ; # group of fictional characters
wdt:P1080 wd:Q931597. # from Marvel universe
?char wdt:P463 ?group # member of group
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}
}
Example Gephi Semantic Web Import SPARQL query:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#Groups of characters in the Marvel universe
CONSTRUCT {
?group gephi:label ?groupLabel .
?group gephi:category "group" .
?char gephi:label ?charLabel .
?char gephi:category "character" .
?char wdt:P463 ?group
} WHERE {
?group wdt:P31 wd:Q14514600 ; # group of fictional characters
wdt:P1080 wd:Q931597. # from Marvel universe
?char wdt:P463 ?group # member of group
SERVICE wikibase:label { bd:serviceParam wikibase:language "en".}
}
From there on, you should be able to fetch, process and analyse Wikidata straight into Gephi!
How search example: https://es.wikipedia.org/wiki/España?
Best regards