Skip to content
petermr edited this page Jul 15, 2020 · 17 revisions

Wikidata/SPARQL Query Service:

  • Wikidata is a free and open knowledge base that can be read and edited by both humans and machines.
  • Wikidata acts as central storage for the structured data of its Wikimedia sister projects including Wikipedia, Wikivoyage, Wiktionary, Wikisource, and others.

Usage of Wikidata/SPARQL Query Service:

  • Creating a dictionary using Wikidata Query Service/SPARQL saves time and energy. Wikidata is a knowledge database and SPARQL is a language to formulate queries using knowledge databases.

  • To start with, open the home page of WDQS/SPARQL : https://www.wikidata.org/wiki/Wikidata:WikiFactMine/Core_SPARQL

  • From the list on the left hand side of the home page, go to Query Service, this takes you to: https : //query.wikidata.org/

  • This opens the SPARQL query page where you can add your query. If you find any trouble in creating a SPARQL Query, you can create it from: https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/Query_Helper#How_to_create_a_Query?

    OR You can create a query without knowing SPARQL, it's too easy. Go to Query Helper on the left side of Query Editor and apply filters to your search, then test it by running the query and so on.

  • Wikidata Query Service provides various tools to build a SPARQL Query. One of them is Wikidata Query Builder :

    https://tools.wmflabs.org/wd-query-builder/
    
  • Just do the related search and Click on 'Show Query', this has built a SPARQL Query for you. eg. in my case, the property is Crossref Funder ID (P3153).

  • Set the limit of your results, it is by default 20, you can change it by clicking on to 'Query Options', I changed it to 20000 and got 13442 results.

  • Go to 'Search results': You will get a list of the items which you are searching for.

  • Go to 'link' and then 'SPARQL endpoint' and it's done.

  • The dictionary created is : https://github.com/petermr/openVirus/blob/master/dictionaries/funders/sparql%20(4)

  • Reference TUTORIAL for creating queries : https://www.youtube.com/watch?v=kJph4q0Im98

adding labels

We often need the human-readable labels for an Item. Almost all items have labels. However you have to use a label SERVICE for this:

SELECT ?funder ?funderLabel WHERE {
  ?funder wdt:P3153 ?crossrefid .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Every item has a label defined by adding Label as a suffix. So funder has funderLabel . The label is not a property but has to be generated. This is through a SERVICE

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

This is not easy to remember.

Clone this wiki locally