Title: | API Client Library for 'Wikidata Query Service' |
---|---|
Description: | An API client for the 'Wikidata Query Service' <https://query.wikidata.org/>. |
Authors: | Mikhail Popov [aut, cre] (@bearloga on Twitter), Wikimedia Foundation [cph] |
Maintainer: | Mikhail Popov <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-09 04:53:09 UTC |
Source: | https://github.com/wikimedia/wikidataqueryservicer |
Gets the specified example(s) from SPARQL query service examples page using Wikidata's MediaWiki API.
get_example(example_name)
get_example(example_name)
example_name |
the names of the examples as they appear on this page |
If you are planning on extracting multiple examples, please provide all the names as a single vector for efficiency.
The SPARQL query as a character vector.
## Not run: sparql_query <- extract_example(c("Cats", "Horses")) query_wikidata(sparql_query) # returns a named list with two data frames # one called "Cats" and one called "Horses" sparql_query <- extract_example("Largest cities with female mayor") cat(sparql_query) query_wikidata(sparql_query) ## End(Not run)
## Not run: sparql_query <- extract_example(c("Cats", "Horses")) query_wikidata(sparql_query) # returns a named list with two data frames # one called "Cats" and one called "Horses" sparql_query <- extract_example("Largest cities with female mayor") cat(sparql_query) query_wikidata(sparql_query) ## End(Not run)
Makes a POST request to Wikidata Query Service SPARQL endpoint.
query_wikidata(sparql_query, format = c("simple", "smart"))
query_wikidata(sparql_query, format = c("simple", "smart"))
sparql_query |
SPARQL query (can be a vector of queries) |
format |
"simple" uses CSV and returns pure character data frame, while
"smart" fetches JSON-formatted data and returns a data frame with datetime
columns converted to |
A tibble data frame
There is a hard query deadline configured which is set to 60 seconds. There are also following limits:
One client (user agent + IP) is allowed 60 seconds of processing time each 60 seconds
One client is allowed 30 error queries per minute See query limits section in the WDQS user manual for more information.
sparql_query <- "SELECT ?softwareVersion ?publicationDate WHERE { BIND(wd:Q206904 AS ?R) ?R p:P348 [ ps:P348 ?softwareVersion; pq:P577 ?publicationDate ] . }" query_wikidata(sparql_query) ## Not run: query_wikidata(sparql_query, format = "smart") ## End(Not run)
sparql_query <- "SELECT ?softwareVersion ?publicationDate WHERE { BIND(wd:Q206904 AS ?R) ?R p:P348 [ ps:P348 ?softwareVersion; pq:P577 ?publicationDate ] . }" query_wikidata(sparql_query) ## Not run: query_wikidata(sparql_query, format = "smart") ## End(Not run)
Why did I have to go and make things so deprecated?
scrape_example(example_name, ...)
scrape_example(example_name, ...)
example_name |
the names of the examples as they appear on this page |
... |
ignored (kept for backwards-compatibility) |
scrape_example
: use get_example instead which employs WikipediR::page_content