Page MenuHomePhabricator

Documentation of example local item/federated property SPARQL queries
Closed, ResolvedPublic1 Estimated Story Points

Description

As a data reuser, I want to make make SPARQL queries of the local Wikibase using federated properties so that I can combine and reuse data in the Wikibase.

We need to document example queries of a WB configured to use federated properties with local items so that users know how to accomplish this task.

Documentation Requirements

  1. Provide an example query based on this Wikidata query that returns all local items that use the same federated property from Wikidata
  2. Explain how this query differs from a query that looks only at local items and local properties (e.g. what do you have to modify so that you are looking at local items and federated properties)
  3. Point to the Wikidata example queries as a place to look for additional queries that could be modified and tried out in your own Wikibase

Event Timeline

Adding Dan in case he has bandwidth to provide the fed. properties team with some feedback on our documentation once we reach the point of verification.

Query for searching the local instance and wikidata of written works with a publication date greater than 2000-01-01.

# This example describes an example use case of Federated Properties
# being used in conjunction with a Federated Query.
#
# In this example we are setting up a local wikibase repository for publications where
# we have created a few items and assigned them the statement of P577 (Publication date).
# With this setup we querying the local database and the federated source wiki for 
# any written work (Q47461344) with a publication date after 2000-01-01.
#
# Uncomment row 31 to narrow down the search for a specific genre

#defaultView:Timeline
PREFIX wd-wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd-wd: <http://www.wikidata.org/entity/>

SELECT ?item ?itemLabel ?pubDate ?image
WHERE
{
  {
    SELECT ?item ?itemLabel ?pubDate 
    WHERE
    {
      ?item wdt:P577 ?pubDate .
      OPTIONAL { ?item wd:P18 ?image }
    }
  }
  UNION
  {
   SERVICE <https://query.wikidata.org/sparql> {
     ?item wd-wdt:P577 ?pubDate .
     ?item wd-wdt:P31 wd-wd:Q47461344 .
     #?item wd-wdt:P136 wd-wd:Q8261 . # genre novel (Q8261)
     OPTIONAL { ?item wd-wdt:P18 ?image }
   } 
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  FILTER (?pubDate > "2000-01-01T00:00:00+00:00"^^xsd:dateTime)
}
ORDER BY DESC(?pubDate)
LIMIT 100

Here is another one showing how to search a local instance and a remote using the ISNI external-identifier.

(More GLAM identifiers here https://www.wikidata.org/wiki/Wikidata:GLAM)

# This example describes an example use case of Federated Properties
# being used in conjunction with a Federated Query.
#
# In this example we have setup a local wikibase repository and created an 
# item with the federated property International Standard Name Identifier (P213)
#
# Running this query we are asking the local instance and the federated source wiki
# to return all items that are identified by INSI "0000 0001 1364 8293" which on
# wikidata.org returns Berlin and on your local instance could be just about anything.

PREFIX wd-wdt: <http://www.wikidata.org/prop/direct/>

SELECT ?item ?ISNI
WHERE
{
  VALUES ?ISNI {"0000 0001 1364 8293"}
  {
    SELECT ?item ?ISNI 
    WHERE
    {
        ?item wdt:P213 ?ISNI;
    }
  }
  UNION
  {
   SERVICE <https://query.wikidata.org/sparql> {
        ?item wd-wdt:P213 ?ISNI;
   } 
  }
}
Addshore triaged this task as Medium priority.Jul 8 2020, 10:35 AM

The examples all worked fine for me. They should probably be transferred to a more visible place. Like a section in federated properties documentation

Change 611274 had a related patch set uploaded (by Tobias Andersson; owner: Tobias Andersson):
[mediawiki/extensions/Wikibase@master] FP: Move sparql queries to documentation

https://gerrit.wikimedia.org/r/611274

I started reviewing this and we have found out, that the entitysource configuration (T257907 and T257908) needs to happen before the WDQS examples will work and can be reviewed.

On second attempt to review this, it has to be postponed again until after T258507 has been fixed, so we can actually try out both examples and confirm they are working on one of the test systems.

Silvan_WMDE changed the task status from Open to Stalled.Jul 22 2020, 7:46 AM
Addshore raised the priority of this task from Medium to Needs Triage.Jul 22 2020, 8:10 AM
Addshore subscribed.

Resetting priority at start of new sprint (so it can be aligned with the sprint goals)

Addshore changed the task status from Stalled to Open.Jul 23 2020, 9:51 AM

Change 611274 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] FP: Add sparql queries to documentation

https://gerrit.wikimedia.org/r/611274

  1. Example queries are now added to the Federated Properties repo doc page. They both combine two result sets in one query, one from the local, federated properties enabled repository and one from wikidata.org.
  2. This way they elegantly illustrate the difference between querying repositories with or without federated properties. Detailed explanations are given as comments in the query source code.
  3. A link to a SPARQL tutorial, which includes further examples, has been added.