Wikidata : service d'aide SPARQL/assistant de requête
L'assistant de requête vous permet de créer ou de modifier une requête existante sans connaître le langage SPARQL.
En travaillant avec l'outil, il modifiera la requête SPARQL, en fonction de l'entrée que vous fournissez dans l'interface visuelle, et vice versa.
Il s'affiche sur le côté gauche de l'éditeur de requêtes.
Quelles sont les limites ?
Cet outil est expérimental et détériorer votre requête SPARQL.
- la sérialisation Json ne doit pas contenir de retour à la ligne.
- les « templates » peuvent être placés n'importe où : au début ou à la fin.
- le « template » sera ajouté à l'URL. Ce qui peut engendrer des problèmes.
Comment créer une requête ?
Cette section va montrer comment vous pouvez créer une requête depuis rien avec l'assistant de requête.
Dans cet exemple, nous allons interroger toutes les instances de zoo qui hébergent un ours polaire et un lion.
Add 'instance of zoo', 'species kept polar bear' and 'species kept lion' filter
- Click on 'Filter'
- Click on the combo box and enter 'zoo'
- Select the 'zoo (Q43501)' item from the combo box
- Click on 'Filter' and select 'polar bear (Q33609)'
- Click on 'Filter' and select 'lion (Q140)'
Add 'official website', 'image', 'coordinate location', 'inception' and 'species kept' columns
- Click on 'Show' and select 'official website (P856)'
- Click on 'Show' and select 'image (P18)'
- Click on 'Show' and select 'coordinate location (P625)'
- Click on 'Show' and select 'inception (P571)'
- Click on 'Show' and select 'species kept (P1990)'
Comment modifier une requête ?
This section will show how you can edit a query with the Query Helper
Changer 'cat' en 'zoo'
- Select the 'Cats Query' from the examples
- Click on 'cat' to modify the value
- Click on the combo box and enter 'zoo'
- Select the 'zoo (Q43501)' item from the combo box
The query will now find items that have 'instance of zoo' instead of 'instance of cat'
Ajouter un filtre 'pays Allemagne'
- Click on 'Filter' button
- Enter 'Germany'
- Select 'Germany (Q183)'
- Click on 'instance of' from 'instance of Germany' to modify the value
- Click on the select box and enter 'Country'
- Select country (P17) item
The query will now only find items that have 'instance of zoo' and 'country Germany'
Ajouter les colonnes 'inception' et 'image'
- Click on 'Show' button
- Enter 'inception'
- Select 'inception (P571)' item
- Click on 'Show' button
- Enter 'image'
- Select 'image (P18)'
The query result now has two additional columns 'image' and 'inception' and can be displayed as a Timeline or Image Grid.
Ajouter un titre
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.
Modèles de requête
Utiliser un modèle de requête
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.
Elle est affichée dans la partie gauche de l'éditeur de requêtes.
Les éléments bleus de cette représentation textuelle peuvent être modifiés en cliquant dessus.
Des suggestions définies s'affichent ou un texte peut être saisi pour rechercher un substitut.
La sélection de l'un des éléments de la liste remplacera l'élément dans la représentation textuelle et la requête SPARQL.
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.
Créer un modèle de requête
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. }"
}
}
}
Clé | Valeur | Exemple | Description | Requête SPARQL |
---|---|---|---|---|
modèle | Ce texte sera affiché à l'utilisateur en tant que description de la requête.
Dans le texte, vous pouvez définir des variables qui seront remplacées par des valeurs réelles. |
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. }
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
|