Wikidata:SPARQL query service/Query Helper

From Wikidata
Jump to navigation Jump to search
This page is a translated version of the page Wikidata:SPARQL query service/Query Helper and the translation is 45% complete.
Query.Wikidata.org

Query Helper ermöglicht dir, eine vorhandene Abfrage zu erstellen oder bearbeiten, ohne SPARQL zu kennen.

Wenn du mit dem Tool arbeitest, ändert es die SPARQL-Abfrage basierend auf den Eingaben, die du in der visuellen Schnittstelle machst, und umgekehrt.

Sie wird auf der linken Seite des Abfrage-Editors angezeigt.

Was sind die Grenzen?

Dies ist ein experimentelles Tool und könnte deine SPARQL-Abfrage kaputt machen.

  • Die JSON-Serialisierung sollte keine neuen Zeilen enthalten.
  • Die Vorlage kann an beliebiger Stelle in der Abfrage platziert werden: z.B. am Anfang oder am Ende.
  • Der Inhalt der Vorlage wird der URL der Abfrage hinzugefügt. Aus diesem Grund kann es zu Problemen kommen.

Wie erstellt man eine Abfrage?

Erstelle einen Abfragezoo, der Eisbär und Löwe hält

In diesem Abschnitt wird gezeigt, wie du mit dem Query Helper eine Abfrage von Grund auf erstellen kannst.

In diesem Beispiel werden wir alle Instanzen des Zoos abfragen, die einen Eisbären und einen Löwen halten.

Füge die Filter 'instance of zoo', 'species kept polar bear' und 'species kept lion' hinzu

  1. Klick auf "Filter".
  2. Klicke auf das Kombinationsfeld und gib "zoo" ein.
  3. Wähle den Eintrag "Zoo (Q43501)" aus dem Kombinationsfeld aus.
  4. Klicke auf "Filter" und wähle "Eisbär (Q33609)".
  5. Klicke auf "Filter" und wähle "Löwe (Q140)".

Füge die Spalten 'official website', 'image', 'coordinate location', 'inception' und 'species kept' hinzu

  1. Klicke auf "Anzeigen" und wähle "offizielle Website (P856)".
  2. Klicken Sie auf "Anzeigen" und wählen Sie "Bild (P18)".
  3. Klicke auf "Anzeigen" und wähle "geographische Koordinaten (P625)".
  4. Klicke auf "Anzeigen" und wähle "Datum der Gründung, Erstellung, Entstehung, Erbauung (P571)".
  5. Klicke auf "Anzeigen" und wähle "gehaltene Arten (P1990)".

Wie ändere ich eine Abfrage?

Query Helper - Bearbeite 'Cat Query'

In diesem Abschnitt wird gezeigt, wie du eine Abfrage mit dem Query Helper bearbeiten kannst

Ändere "Katze" in "Zoo"

  1. Wähle die 'Cats Query' aus den Beispielen
  2. Klicke auf 'Katze', um den Wert zu ändern
  3. Klicke auf das Kombinationsfeld und gib 'Zoo' ein
  4. Wähle das Element "Zoo (Q43501)" aus der Combobox aus.

Die Abfrage findet nun Elemente, die "Instanz von Zoo" statt "Instanz von Katze" haben.

Füge den Filter "Land Deutschland" hinzu

  1. Klicke auf die Schaltfläche "Filter".
  2. Gib "Deutschland" ein
  3. Wähle "Deutschland (Q183)".
  4. Klicke auf "Instanz von" von "Instanz von Deutschland", um den Wert zu ändern
  5. Klicke auf das Auswahlfeld und gib "Land" ein.
  6. Wähle den Eintrag "Land (P17)".

Die Abfrage findet jetzt nur Artikel, die "Instanz von Zoo" und "Land Deutschland" haben.

Hinzufügen der Spalten "Inception" und "Image"

  1. Klicke auf die Schaltfläche "Anzeigen".
  2. Gib "Datum der Gründung, Erstellung, Entstehung, Erbauung" ein
  3. Wähle den Eintrag "Datum der Gründung, Erstellung, Entstehung, Erbauung (P571)".
  4. Klicke auf die Schaltfläche "Zeigen".
  5. Gib "Bild" ein
  6. Wähle "Bild (P18)".

Das Abfrageergebnis hat jetzt zwei zusätzliche Spalten 'image' und 'inception' und kann als Timeline oder Image Grid angezeigt werden.

Einen Titel hinzufügen

In the code view, in the right-hand pane, add #title: Your title at the beginning of the query; changing "Your title" to whatever you would like the title to be.

Query Templates

Use a Query Template

Query Helper - Query Template Largest cities with female head of government

Queries that have a Query Template defined will show the defined textual representation of this query inside of the Query Helper.Query Helper allows you to create or modify an existing query without knowing SPARQL.

When working with the tool it will modify the SPARQL query, based on the input you provide in the visual interface, and vice versa.

It is displayed on the left side of the query editor.

Blue items in this textual representation can be clicked to modify them.

Defined suggestions will be shown or a text can be entered to search for a replacement.

When selecting one of the items in the list it will replace the item in the textual representation and the SPARQL query.

You can find all the queries in the Query Examples List that have a defined Query Template by searching for '#TEMPLATE' in the page text.

Create a Query Template

Query templates can be created by providing a template definition. Here is an example query with a template definition.

The definition is expressed in JSON and inserted as SPARQL comment to the query like this:

#TEMPLATE=[JSON_DEFINITION]

JSON definition example:

{
  "template": "Largest ?c with ?sex head of government",
  "variables": {
    "?sex": {},
    "?c": {
      "query": "SELECT DISTINCT ?id WHERE {  ?c wdt:P31 ?id.  ?c p:P6 ?mayor. }"
    }
  }
}
Key Value Example Description SPARQL Query
template

This text will be shown to the user as description for the query. In the text you can define variables that will be replaced by actual values.

Largest ?c with ?sex head of government

This will define two variables within the text: ?c and ?sex

The values for this variables must be defined

in the SPARQL query.

BIND(wd:Q6581072 AS ?sex)

BIND(wd:Q515 AS ?c)
variables

In this section you have to define the variables from the template. You can optionally define a SPARQL query that is used for suggesting values for that variable.

"?sex": {},
"?c": {
  "query": "[SPARQL]"
}

This will define two variables: ?c and ?sex

For the variable ?c there is a SPARQL query defined that will suggest Items.

SELECT DISTINCT ?id WHERE
{ ?c wdt:P31 ?id.?c p:P6 ?mayor. }
The SPARQL query from the Query Template will be embedded into this query to display the result with label, description. If ?count is provided then it will be sorted by desc(?count):
SELECT ?id ?label ?description WITH {				 

[QUERY]		

} AS %inner			
WHERE {	
INCLUDE %inner				
?id rdfs:label ?label.				
?id schema:description ?description.				
FILTER((LANG(?label)) = "en")				
FILTER((LANG(?description)) = "en")			} 
ORDER BY DESC(?count)			
LIMIT 20