Load queries from repositories on the web into an IDE-like environment in your browser, execute them - and start modifying and playing with them.
The SPARQL Lab installation at http://zbw.eu/beta/sparql-lab primarily aims at supporting ZBW Labs projects such as sparql-queries and skos-history. Additionally, it is used in STW Thesaurus for Economics Change Reports (beta). Feel free to use the publicly available installation for other purposes - without any warranties.
This project provides mainly glue code. It makes heavy use of Laurens Rietveld's great YASQE and YASR javascript libraries, part of his YASGUI project.
The script is controlled by the following URL arguments:
Argument | Description |
---|---|
endpoint | URL of a SPARQL endpoint (defaults to an endpoint with the STW version history). Remote endpoints have to be CORS enabled. |
query | URL-encoded query text (takes precedence over queryRef if both are defined, defaults to the YASQE built-in example query if neither). |
queryRef | URL of a query on the web (no default). Works with GitHub API as in the example below, and presumably with other public repository URLs (CORS on the repository server required). |
hide | With hide=1 , the query pane is hidden from display (defaults to hide=0). |
Example: The URL
retrieves and views the query stored at
https://github.com/zbw/sparql-queries/blob/master/class_overview.rq
via the GitHub API and executes it on the
endpoint http://data.nobelprize.org/sparql
.
If stored SPARQL queries contain a VALUES clause, this can be used to inject variables into the code of queries. URL arguments other than the above listed ones are parsed and replaced, when their names match VALUES variables in the query.
This mechanism can be used for providing defaults in queries, which can be overridden by URL arguments. It is supposed to work for a single set of values in a single VALUES clause. To be replaced correctly, literal values in the VALUES clause have be enclosed in double quotes. 'undef' variables are presumed to be literals.
Example: The URL
loads the query (shown below in a heavily abbreviated form) and replaces the value for the ?language
variable in the VALUES clause.
SELECT *
WHERE {
# parameters
VALUES ( ?versionHistoryGraph ?oldVersion ?newVersion ?language ) {
( <http://zbw.eu/stw/version> undef undef "en" )
}
# ...
# restrict output to a certain language
FILTER ( lang(?prefLabel) = ?language )
}
When the datasets addressed in a query are not available through public endpoints, cached result files can be provided instead of interactively executed queries.
The functionality is available via the URI "/result", e.g., http://zbw.eu/beta/sparql-lab/result
The result script is controlled by the following URL arguments:
Argument | Description |
---|---|
queryRef | URL of a sparql-json result on the web (no default). Works with GitHub API as in the example below, and presumably with other public repository URLs (CORS on the repository server required). |
Example: The URL
retrieves and views the result stored at
https://github.com/zbw/sparql-queries/blob/master/wikidata/results/count_persons_by_wp_language.wikidata_2016-11-07.json
via the GitHub API.
The following naming convention is used:
- A result file resides in the same repository as the query in a directory "results" below the directory containing the query.
- The base name of the result file is equal to the base name of the query.
- The versions of the datasets, which were queried, should be indicated in further file name parts, with
_
as separator between the dataset name and the version name, and.
as seperator between multiple dataset_version statements.
For example, the result of the resultRef
in the example above was retrieved by the query https://github.com/zbw/sparql-queries/blob/master/wikidata/count_persons_by_wp_language.rq
against the dataset wikidata
in version 2016-11-07
.
- Joachim Neubert: Publishing SPARQL queries live (ZBW Labs)
- Laurens Rietveld/Rinke Hoekstraa: The YASGUI Family of SPARQL Clients (Submission to Semantic Web Journal)