The SPARQL endpoint is http://wdqs-beta.wmflabs.org/bigdata/namespace/wdq/sparql and it has a Web form to fire queries. However http://www.wikidata.org/prop/direct/P31
(« instance of ») tells you what the entity is.
The repository doesn’t have named graphs, or at least the SPARQL endpoint rejects graph queries. The classes of entities (rdf:type
) are not described in the repository.
To find the HTML page of an entity (such as https://www.wikidata.org/entity/Q866405
), simply replace /entity/
with /wiki/
.
By default the SPARQL endpoint returns the results in SPARQL Results XML format but
- adding
-H "Accept: application/json"
to the cURL command gets them in JSON Query Results - adding
-H "Accept: text/csv"
to the cURL command gets them in CSV format (the most readable).
Don’t forget to URL encode the query 😉
The list of entity types
Description of an entity (East Antarctica)
describe
queries return all the triples in which the selected entity is subject (position 1/3). Certain SPARQL endpoints (such as this one) also return the triples in which the entity is object (position 3/3). The query result being a graph and not a table like for SPARQL Results, the default format is RDF/XML. JSON and Turtle (text/turtle
) can also be requested.
As Lucas Werkmeister suggested, Unix users don’t necessarily need to URL encode their query as cURL can take care of it:
curl -G https://wdqs-beta.wmflabs.org/bigdata/namespace/wdq/sparql –data-urlencode query=’
select distinct ?type where {
?thing ?type
}
limit 20
‘
La commande
curl -G https://query.wikidata.org/bigdata/namespace/wdq/sparql –data-urlencode query=’
select distinct ?type where {
?thing ?type
}
limit 20′ -H « Accept: text/csv »
fonctionne très bien. Maintenant, quand la requête est complexe, j’aimerais pouvoir stocker la requête SPARQL dans un fichier sparql.txt et requête avec une commande du type :
curl -G https://query.wikidata.org/bigdata/namespace/wdq/sparql –data-urlencode query=sparql.txt -H « Accept: text/csv »
Mais je n’arrive pas à comprendre comment écrire cette requête.
Eureka, j’ai trouvé la solution sur [StackExchange](http://unix.stackexchange.com/questions/17375/command-line-curl-submit-form-from-other-files?rq=1)
curl -G https://query.wikidata.org/bigdata/namespace/wdq/sparql –data-urlencode query= »$(< sparql.txt)" -H 'Accept: text/csv'
Content que tu aies trouvé la solution 🙂
Je suis en train de développer un service de publication et partage de requêtes SPARQL, tu seras le premier averti quand il sera en ligne !
http://sparql-router.herokuapp.com/