Wikidata Query Service/User Manual/de

Der Wikidata Query Service (WDQS) ist ein Softwarepaket und öffentlicher Dienst, der einen SPARQL-Endpunkt zur Abfrage des Wikidata-Datensets bieten soll.

Diese Seite oder andere relevante Dokumentationsseiten werden entsprechend aktualisiert; es wird empfohlen, dass du sie beobachtest, wenn du den Dienst nutzt.

Du kannst dir Beispiele für SPARQL-Abfragen auf der SPARQL-Beispielseite ansehen.

Datensatz
Der Wikidata Query Service arbeitet mit einem Datensatz von Wikidata.org, der, wie in der Dokumentation des RDF-Dump-Formats beschrieben, in RFD dargestellt wird.

Der Datensatz des Dienstes stimmt nicht exakt mit dem Datensatz überein, der von RDF-Dumps erzeugt wird, hauptsächlich aus Gründen der Performance; Die Dokumentation beschreibt eine kleine Reihe von Unterschieden.

Du kannst dir einen wöchentlichen Dump der gleichen Daten herunterladen:

https://dumps.wikimedia.org/wikidatawiki/entities/

Grundlagen - SPO (Subjekt, Prädikat, Objekt; auch bekannt als semantisches Tripel) verstehen
SPO oder "Subjekt, Prädikat, Objekt" ist bekannt als ein Tripel und wird in Wikidata häufig als Aussage über Daten bezeichnet.

Die Aussage "Die Hauptstadt der Vereinigten Staaten ist Washington, D.C." besteht aus dem Subjekt "Vereinigte Staaten" (Q30), dem Prädikat "Hauptstadt" (P36) und einem Objekt "Washington, D.C." (Q61). Diese Aussage kann in Form von drei URIs dargestellt werden:

Dank den Präfixen (siehe unten) kann die gleiche Aussage in einer prägnanteren Form geschrieben werden. Beachte, dass der Punkt am Ende das Ende der Aussage repräsentiert.

/entity/ (wd:) steht für ein Wikidata-Datenobjekt (Werte mit einer Q-Nummer). /prop/direct/ (wdt:) ist eine "wahre" Eigenschaft — ein Wert, den wir am häufigsten erwarten würden, wenn wir uns die Aussage ansehen. Die wahren Eigenschaften werden benötigt, da manche Aussagen "wahrer" sein können, als andere. Beispielsweise ist die Aussage "Die Hauptstadt der Vereinigten Staaten ist New York City" wahr — jedoch nur im historischen Kontext des Jahres 1790. WDQS nutzt Ränge, um zu bestimmen, welche Aussagen als "wahr" genutzt werden sollen.

Zusätzlich zu den wahren Aussagen speichert der WDQS alle Aussagen (wahre und unwahre), jedoch nutzen sie nicht das gleiche Präfix wdt:. Die Hauptstadt der Vereinigten Staaten hat drei Werte: Washington, D.C., Philadelphia, und New York City. Und jeder von diesen Werten hat "Qualifikatoren" - zusätzliche Informationen, wie Start- und Enddatum, was den Umfang jeder Aussage einengt. Um diese Informationen als Tripel zu speichern, hat der WDQS ein automatisches "Aussagen"-Subjekt eingefügt, was im Wesentlichen eine zufällige Zahl ist:

Siehe SPARQL-Tutorial - Qualifikatoren für weitere Informationen.

SPO wird auch als Form eines grundlegenden Syntax-Layouts zur Abfrage von RDF-Datenstrukturen, Graph-Daten oder einem Tripelspeicher, wie dem Wikidata Query Service (WDQS), der auf Blazegraph, einer Graph-Datenbank mit hoher Performance, läuft, genutzt.

Fortgeschrittene Nutzungen eines Tripels (SPO) umfassen die Nutzung von Tripels als Objekten oder Subjekten anderer Tripel!

Grundlagen - Präfixe verstehen
Die Subjekte und Prädikate (erster und zweiter Wert des Tripels) müssen immer als URIs gespeichert werden. Wenn das Subjekt beispielsweise das Universum (Q1) ist, wird es als    gespeichert. Präfixe ermöglichen es uns, diesen langen URI in einer kürzeren Form zu schreiben: wd:Q1. Im Gegensatz zu Subjekten und Prädikaten kann das Objekt (dritter Wert des Tripels) entweder ein URI oder ein Wort sein, z.B. eine Zahl oder eine Zeichenkette.

WDQS versteht viele Abkürzungen, bekannt als Präfixe. Manche sind Wikidata-intern, z.B. wd, wdt, p, ps, bd, und manche sind häufig genutzte externe Präfixe, wie rdf, skos, owl, schema.

In der folgenden Abfrage suchen wir Datenobjekte mit der Aussage "P279 = Q7725634" oder vollständiger ausgedrückt Subjekte, die ein Prädikat "Unterklasse von" mit einem Objekt = "literarisches Werk" haben.

Die Ausgabe-Variablen:

Erweiterungen
Der Abfragedienst unterstützt die folgenden Erweiterungen der Standard-SPARQL-Fähigkeiten:

Bezeichnungs-Dienst
Du kannst die Bezeichnung, Alias oder Beschreibung von Einträgen unter Berücksichtigung der Sprach-Rückfallkette erhalten, indem du den spezialisierten Dienst mit dem URI  nutzt. Dieser Dienst ist sehr hilfreich, wenn du Bezeichnungen abrufen möchtest, da er die Komplexität von SPARQL-Abfragen, die du sonst benötigen würdest, um das gleiche Ergebnis zu erzielen, reduziert.

Der Dienst kann in zwei unterschiedlichen Modi genutzt werden: manuell und automatisch.

Im automatischen Modus musst du nur die Vorlage des Dienstes angeben, z.B.:

Der WDQS generiert dann automatisch wie folgt Bezeichnungen:


 * If an unbound variable in  is named , then WDQS produces the label  for the entity in variable.
 * If an unbound variable in  is named , then WDQS produces the alias  for the entity in variable.
 * If an unbound variable in  is named , then WDQS produces the description  for the entity in variable.

In each case, the variable in  should be bound, otherwise the service fails.

Automatic mode only inspects the projection of the query – for instance, in, only the first label is recognized, and   is not supported by automatic mode at all. In such cases, you will need to use manual mode (see below).

You specify your preferred language(s) for the label with one or more of  triples. Each string can contain one or more language codes, separated by commas. WDQS considers languages in the order in which you specify them. If no label is available in any of the specified languages, the Q-id of the entity (without any prefix) is its label.

The Wikidata Query Service website automatically replaces  with the language code of current user's interface. For example, if the user's UI is in French, the SPARQL's code  will be converted to   before being sent to the query service.

Example, showing the list of US presidents and their spouses:

In this example WDQS automatically creates the labels  and   for properties.

In the manual mode, you explicitly bind the label variables within the service call, but WDQS will still provide language resolution and fallback. Example:

This will consider labels and descriptions in French, German and English, and if none are available, will use the Q-id as the label.

Geospatial search
The service allows to search for items with coordinates located within a certain radius of a central point or within a certain bounding box.

Search around point
Beispiel:

The first line of the  service call must have format     , where the result of the search will bind   to items within the specified location and   to their coordinates. The parameters supported are:

Search within box
Example of box search:

oder:

Coordinates may be specified directly:

The first line of the  service call must have format     , where and the result of the search will bind   to items within the specified location and   to their coordinates. The parameters supported are:

and  should be used together, as well as   and , and cannot be mixed. If  and   predicates are used, then the points are assumed to be the coordinates of the diagonal of the box, and the corners are derived accordingly.

Entfernungs-Funktion
The function  returns distance between two points on Earth, in kilometers. Example usage:

Koordinaten-Funktionen
Functions,   &   return parts of a coordinate - globe URI, latitude and longitude accordingly.

URL-Entschlüsselungs-Funktionen
Function  decodes (i.e. reverses percent-encoding) given URI string. This may be necessary when converting Wikipedia titles (which are encoded) into actual strings. This function is an opposite of SPARQL encode_for_uri function.

Automatische Präfixe
Most prefixes that are used in common queries are supported by the engine without the need to explicitly specify them.

Erweiterte Daten
The service supports date values of type  in the range of about 290B years in the past and in the future, with one-second resolution. WDQS stores dates as the 64-bit number of seconds since the Unix epoch.

Blazegraph-Erweiterungen
Blazegraph platform on top of which WDQS is implemented has its own set of SPARQL extension. Among them several graph traversal algorithms which are documented on Blazegraph Wiki, including BFS, shortest path, CC and PageRank implementations.

Please also refer to the Blazegraph documentation on query hints for information about how to control query execution and various aspects of the engine.

There is no documentation in the BlazeGraph wiki about the bd:sample extension. It's documented only in a comment in the code.

Federation
We allow SPARQL Federated Queries to call out to a selected number of external databases. Please see the full list of federated endpoints on the dedicated page.

Example federated query:

Please note that the databases that the federated endpoints serve use ontologies that may be very different from the Wikidata one. Please refer to the owner documentation links to learn about the ontologies and data access to these databases.

MediaWiki API
Please see full description on MediaWiki API Service documentation page.

MediaWiki API Service allows to call out to MediaWiki API from SPARQL, and receive the results from inside the SPARQL query. Example (finding category members):

Wikimedia-Dienst
Wikimedia runs the public service instance of WDQS, which is available for use at http://query.wikidata.org/.

The runtime of the query on the public endpoint is limited to 60 seconds. That is true both for the GUI and the public SPARQL endpoint.

GUI
The GUI at the home page of http://query.wikidata.org/ allows you to edit and submit SPARQL queries to the query engine. The results are displayed as an HTML table. Note that every query has a unique URL which can be bookmarked for later use. Going to this URL will put the query in the edit window, but will not run it - you still have to click "Execute" for that.

One can also generate a short URL for the query via a URL shortening service by clicking the "Generate short URL" link on the right - this will produce the shortened URL for the current query.

The "Add prefixes" button generates the header containing standard prefixes for SPARQL queries. The full list of prefixes that can be useful is listed in the RDF format documentation. Note that most common prefixes work automatically, since WDQS supports them out of the box.

The GUI also features a simple entity explorer which can be activated by clicking on the "🔍" symbol next to the entity result. Clicking on the entity Q-id itself will take you to the entity page on wikidata.org.

Standard-Ansichten

 * Main article: wikidata:Special:MyLanguage/Wikidata:SPARQL query service/Wikidata Query Help/Result Views

If you run the query in the WDQS GUI, you can choose which view to present by specifying a comment:  at the beginning of the query.

Display a title
If you run the query in the WDQS GUI, you can display a title on top of the results by specifying a comment:  at the beginning of the query.

SPARQL-Endpunkte
SPARQL queries can be submitted directly to the SPARQL endpoint with a GET or POST request to.

GET requests have the query specified in the URL, in the format, e.g..

POST requests can alternatively accept the query in the body of the request, instead of the URL, which allows running larger queries without hitting URL length limits. (Note that the POST body must still include the  prefix (that is, it should be   rather than just  ), and the SPARQL query must still be URL-escaped.)

The result is returned as XML by default, or as JSON if either the query parameter  is included in the URL, or the header   is provided with the request.

The JSON format is standard SPARQL 1.1 Query Results JSON Format.

It is recommended to use GET for smaller queries and POST for larger queries, as POST queries are not cached.

Unterstützte Formate
The following output formats are currently supported by the SPARQL endpoint:

Query limits
There is a hard query deadline configured which is set to 60 seconds. There are also following limits:


 * One client (user agent + IP) is allowed 60 seconds of processing time each 60 seconds
 * One client is allowed 30 error queries per minute

Clients exceeding the limits above are throttled with HTTP code. Use  header to see when the request can be repeated. If the client ignores 429 responses and continues to produce requests over the limits, it can be temporarily banned from the service. Clients who don’t comply with the User-Agent policy may be blocked completely – make sure to send a good  header.

Every query will timeout when it takes more time to execute than this configured deadline. You may want to optimize the query or report a problematic query here.

Also note that currently access to the service is limited to 5 parallel queries per IP. The above limits are subject to change depending on resources and usage patterns.

Explain Query
Blazegraph allows to show query analysis that explains how the query has been parsed and which optimizations were applied. To see this information, add  parameter to the query string, for example:.

Namensräume
The data on Wikidata Query Service contains the main namespace,, to which queries to the main SPARQL endpoint are directed, and other auxiliary namespaces, listed below. To query data from different namespace, use endpoint URL https://query.wikidata.org/bigdata/namespace/NAMESPACENAME/sparql.

Kategorien
'' Please see full description on Categories documentation page. ''

Wikidata Query Service also provides access to the category graph of select wikis. The list of covered wikis can be seen here: https://noc.wikimedia.org/conf/dblists/categories-rdf.dblist

The category namespace name is. The SPARQL endpoint for accessing it is https://query.wikidata.org/bigdata/namespace/categories/sparql.

Please see Categories page for detailed documentation.

DCAT-AP
The DCAT-AP data for Wikidata is available as SPARQL at https://query.wikidata.org/bigdata/namespace/dcatap/sparql endpoint.

The source for the data is: https://dumps.wikimedia.org/wikidatawiki/entities/dcatap.rdf

Example query to retrieve data:

Linked Data Fragments endpoint
We also support querying the database using Triple Pattern Fragments interface. This allows to cheaply and efficiently browse triple data where one or two components of the triple is known and you need to retrieve all triples that match this template. See more information at the Linked Data Fragments site.

The interface can be accessed by the URL:. This service is implemented on the top of Blazegraph database, so it will have the same lag as the Query Service. Beispielabfragen:


 * https://query.wikidata.org/bigdata/ldf?subject=http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ146 - all triples with subject
 * https://query.wikidata.org/bigdata/ldf?subject=&predicate=http%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23label&object=%22London%22%40en - all triples that have English label "London"

Note that only full URLs are currently supported for the,   and   parameters.

By default, HTML interface is displayed, however several data formats are available, defined by  HTTP header.

The data is returned in pages, page size being 100 triples. The pages are numbered starting from 1, and page number is defined by  parameter.

Eigenständiger Dienst
As the service is open source software, it is also possible to run the service on any user's server, by using the instructions provided below.

The hardware recommendations can be found in Blazegraph documentation.

If you plan to run the service against non-Wikidata Wikibase instance, please see further instructions.

Installieren
In order to install the service, it is recommended that you download the full service package as a ZIP file, e.g. from Maven Central, with group ID  and artifact ID " ", or clone the source distribution at https://github.com/wikimedia/wikidata-query-rdf/ and build it with "mvn package". The package ZIP will be in the  directory under.

The package contains the Blazegraph server as a .war application, the libraries needed to run the updater service to fetch fresh data from the wikidata site, scripts to make various tasks easier, and the GUI in the  subdirectory. If you want to use the GUI, you will have to configure your HTTP server to serve it.

By default, only the SPARQL endpoint at http://localhost:9999/bigdata/namespace/wdq/sparql is configured, and the default Blazegraph GUI is available at http://localhost:9999/bigdata/. Note that in the default configuration, both are accessible only from localhost. You will need to provide external endpoints and an appropriate access control if you intend to access them from outside.

Using snapshot versions
If you want to install an un-released snapshot version (usually this is necessary if released version has a bug which is fixed but new release is not available yet) and do not want to compile your own binaries, you can use either:
 * https://github.com/wikimedia/wikidata-query-deploy - deployment repo containing production binaries. Needs  working. Check it out and do " ".
 * Archiva snapshot deployments at https://archiva.wikimedia.org/#artifact/org.wikidata.query.rdf/service - choose the latest version, then Artifacts, and select the latest package for download.

Daten laden
Further install procedure is described in detail in the Getting Started document which is part of the distribution, and involves the following steps:


 * 1) Download recent RDF dump from https://dumps.wikimedia.org/wikidatawiki/entities/ (the RDF one is the one ending in  ).
 * 2) Pre-process data with the   script. This creates a set of TTL files with preprocessed data, with names like , etc. See options for the script below.
 * 3) Start Blazegraph service by running the   script.
 * 4) Load the data into the service by using  . Note that loading data is usually significantly slower than pre-processing, so you can start loading as soon as several preprocessed files are ready. Loading can be restarted from any file by using the options as described below.
 * 5) After all the data is loaded, start the Updater service by using.

Kategorien laden
If you also want to load category data, please do the following:


 * 1) Create namespace, e.g.  :
 * 2) Load data into it:

Note that these scripts only load data from Wikimedia wikis according to Wikimedia settings. If you need to work with other wiki, you may need to change some variables in the scripts.

Skripte
The following useful scripts are part of the distribution:

munge.sh
Pre-process data from RDF dump for loading.

Beispiel:

loadData.sh
Load processed data into Blazegraph. Requires  to be installed.

Beispiel:

runBlazegraph.sh
Run the Blazegraph service.

Beispiel:

Inside the script, there are two variables that one may want to edit: Also, the following environment variables are checked by the script (all of them are optional):

runUpdate.sh
Run the Updater service.

It is recommended that the settings for the  and   options (or absence thereof) be the same for munge.sh and runUpdate.sh, otherwise data may not be updated properly.

Beispiel:

Also, the following environment variables are checked by the script (all of them are optional):

Aktualisierungsoptionen
The following options works with Updater app.

They should be given to the  script as additional options after , e.g.:.

Konfigurierbare Eigenschaften
The following properties are configurable via adding them to the script run command in the scripts above:

Fehlende Funktionen
Below are features which are currently not supported:


 * Redirects are only represented as owl:sameAs triple, but do not express any equivalence in the data and have no special support.

Kontakt
If you notice anything wrong with the service, you can contact the Discovery team by email on the list  or on the IRC channel.

Bugs can also be submitted to and tracked on the Discovery Phabricator board.

Siehe auch

 * WDQ to SPARQL syntax translator
 * SPARQL Query examples
 * Discovery team
 * WDQS Implementation notes
 * An introduction to SPARQL query syntax