Викиданные:Сервис запросов SPARQL/Помощник в составлении запросов

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 55% complete.
Outdated translations are marked like this.
Query.Wikidata.org

Помощник в составлении запросов позволяет создавать или изменять запросы без знания SPARQL.

Данный инструмент изменяет запрос SPARQL на основе того, что было введено через визуальный интерфейс, и наоборот.

Он отображается с левой стороны редактора запросов.

Каковы ограничения?

Это экспериментальный инструмент, и он может сломать запрос SPARQL.

  • JSON serialization не должна содержать переводов строк.
  • Шаблон может размещаться в любом месте запроса: например, наверху или внизу.
  • Содержимое шаблона включается в URL запроса. Некоторые проблемы могут быть связаны с этим.

Как создать запрос?

Создать запрос «Зоопарки, где содержатся полярные медведи и львы»

В этом разделе будет продемонстрировано, как создать запрос с нуля, используя Помощника в составлении запросов.

В этом примере мы запросим все объекты типа «зоопарк», в которых содержатся и белый медведь, и лев.

Добавление фильтров "частный случай понятия зоопарк", "содержащиеся виды - белый медведь", "содержащиеся виды - лев"

  1. Клик на '+ Фильтр'
  2. Клик на выпадающий список и ввод 'зоопарк'
  3. Выбор пункта 'зоопарк (Q43501)' в выпадающем списке
  4. Клик на '+ Фильтр' и выбор 'белый медведь (Q33609)'
  5. Клик на '+ Фильтр' и выбор 'лев (Q140)'

Добавление колонок "официальный сайт", 'изображение', 'географические координаты', 'дата основания/создания/возникновения' и 'содержащиеся виды'

  1. Клик на '+ Показать' и выбор пункта 'официальный сайт (P856)'
  2. Клик на '+ Показать' и выбор пункта 'изображение (P856)'
  3. Клик на '+ Показать' и выбор пункта 'географические координаты (P625)'
  4. Клик на '+ Показать' и выбор пункта 'дата основания/создания/возникновения (P571)'
  5. Клик на '+ Показать' и выбор пункта 'содержащиеся виды (P1990)'

Как изменить запрос?

Query Helper - Edit 'Cat Query'

В этом разделе будет показано, как редактировать запрос с помощью Помощника в составлении запросов

Change 'cat' to 'zoo'

  1. Select the 'Cats Query' from the examples
  2. Click on 'cat' to modify the value
  3. Click on the combo box and enter 'zoo'
  4. 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'

Добавить фильтр «страна Германия»

  1. Клик на '+ фильтр' кнопку
  2. Ввод 'Германия'
  3. Выбор 'Германия (Q183)'
  4. Клик на 'частный случай понятия' из 'частный случай понятия Германия', чтобы изменить значение
  5. Клик на поле выбора и ввод 'Страна'
  6. Выбор пункта 'Страна (P17)'

Теперь запрос найдёт только элементы, содержащие условия "частный случай понятия зоопарк" и при этом "страна Германия"

Добавить колонки 'дата основания' и 'изображение'

  1. Click on 'Show' button
  2. Enter 'inception'
  3. Select 'inception (P571)' item
  4. Click on 'Show' button
  5. Enter 'image'
  6. Select 'image (P18)'

The query result now has two additional columns 'image' and 'inception' and can be displayed as a Timeline or Image Grid.

Add a title

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 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.

Кликнув на синие элементы в этом текстовом представлении, можно их изменить.

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

При выборе элемента из списка он заменит элемент в текстовом представлении и запросе 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.

Создание шаблона запроса

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. }"
    }
  }
}
Ключ Значение Пример Описание Запрос SPARQL
шаблон

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

Для этих переменных должны быть заданы значения

in the SPARQL query.

BIND(wd:Q6581072 AS ?sex)

BIND(wd:Q515 AS ?c)
переменные

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