{"id":15282777,"url":"https://github.com/wikimedia/wikidataqueryservicer","last_synced_at":"2025-12-12T01:01:06.461Z","repository":{"id":56936259,"uuid":"77945465","full_name":"wikimedia/WikidataQueryServiceR","owner":"wikimedia","description":"An R package for the Wikidata Query Service API","archived":false,"fork":false,"pushed_at":"2020-07-27T13:57:53.000Z","size":53,"stargazers_count":28,"open_issues_count":6,"forks_count":2,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-30T12:11:11.320Z","etag":null,"topics":["api-wrapper","r","r-package","rstats","sparql","wdqs","wikidata"],"latest_commit_sha":null,"homepage":"https://cran.r-project.org/package=WikidataQueryServiceR","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wikimedia.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-03T19:15:12.000Z","updated_at":"2025-01-10T15:54:21.000Z","dependencies_parsed_at":"2022-08-21T01:10:27.509Z","dependency_job_id":null,"html_url":"https://github.com/wikimedia/WikidataQueryServiceR","commit_stats":null,"previous_names":["bearloga/wikidataqueryservicer"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikimedia%2FWikidataQueryServiceR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikimedia%2FWikidataQueryServiceR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikimedia%2FWikidataQueryServiceR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikimedia%2FWikidataQueryServiceR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wikimedia","download_url":"https://codeload.github.com/wikimedia/WikidataQueryServiceR/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237243005,"owners_count":19278060,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-wrapper","r","r-package","rstats","sparql","wdqs","wikidata"],"created_at":"2024-09-30T14:39:52.470Z","updated_at":"2025-10-20T01:31:16.209Z","avatar_url":"https://github.com/wikimedia.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"WikidataQueryServiceR\"\noutput:\n  github_document:\n    toc: true\n    toc_depth: 3\n---\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE)\n# install.packages(\"printr\", type = \"source\", repos = c(\"https://yihui.name/xran\", CRAN = \"https://cran.rstudio.com\"))\nlibrary(printr)\n```\n\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/WikidataQueryServiceR)](https://cran.r-project.org/package=WikidataQueryServiceR)\n[![CRAN Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/WikidataQueryServiceR)](https://cran.r-project.org/package=WikidataQueryServiceR)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nThis is an R wrapper for the [Wikidata Query Service (WDQS)](https://www.mediawiki.org/wiki/Wikidata_query_service) which provides a way for tools to query [Wikidata](https://www.wikidata.org/wiki/Wikidata:Main_Page) via [SPARQL](https://en.wikipedia.org/wiki/SPARQL) (see the beta at https://query.wikidata.org/). It is written in and for R, and was inspired by Os Keyes' [WikipediR](https://github.com/Ironholds/WikipediR) and [WikidataR](https://github.com/Ironholds/WikidataR) packages.\n\n__Author:__ Mikhail Popov (Wikimedia Foundation)\u003cbr/\u003e \n__License:__ [MIT](http://opensource.org/licenses/MIT)\u003cbr/\u003e\n__Status:__ Active\n\n## Installation\n\n```R\ninstall.packages(\"WikidataQueryServiceR\")\n```\n    \nTo install the development version:\n\n```R\n# install.packages(\"remotes\")\nremotes::install_github(\"wikimedia/WikidataQueryServiceR@main\")\n```\n\n## Usage\n\n```{r load}\nlibrary(WikidataQueryServiceR)\n```\n\nYou submit SPARQL queries using the `query_wikidata()` function.\n\n### Example: fetching genres of a particular movie\n\nIn this example, we find an \"instance of\" ([P31](https://www.wikidata.org/wiki/Property:P31)) \"film\" ([Q11424](https://www.wikidata.org/wiki/Q11424)) that has the label \"The Cabin in the Woods\" ([Q45394](https://www.wikidata.org/wiki/Q45394)), get its genres ([P136](https://www.wikidata.org/wiki/Property:P136)), and then use [WDQS label service](https://www.mediawiki.org/wiki/Wikidata_query_service/User_Manual#Label_service) to return the genre labels.\n\n```{r wdqs_example, cache=TRUE}\nquery_wikidata('SELECT DISTINCT\n  ?genre ?genreLabel\nWHERE {\n  ?film wdt:P31 wd:Q11424.\n  ?film rdfs:label \"The Cabin in the Woods\"@en.\n  ?film wdt:P136 ?genre.\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}')\n```\n\nFor more example SPARQL queries, see [this page](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples) on [Wikidata](https://www.wikidata.org/wiki/Wikidata:Main_Page).\n\n`query_wikidata()` can accept multiple queries, returning a (potentially named) list of data frames. If the vector of SPARQL queries is named, the results will inherit those names.\n\n### Fetching queries from Wikidata's examples page\n\nThe package provides a [WikipediR](https://github.com/Ironholds/WikipediR/)-based function for getting SPARQL queries from the [WDQS examples page](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples).\n\n```{r get_examples, cache=TRUE}\nsparql_query \u003c- get_example(c(\"Cats\", \"How many states this US state borders\"))\n```\n```{r, eval=FALSE}\nsparql_query[[\"How many states this US state borders\"]]\n```\n```{r, echo=FALSE, results='asis'}\ncat(\"```SPARQL\\n\", sparql_query[[\"How many states this US state borders\"]], \"\\n```\")\n```\n\nNow we can run all extracted SPARQL queries:\n\n```{r run_examples, cache=TRUE, dependson='get_examples'}\nresults \u003c- query_wikidata(sparql_query)\nlapply(results, dim)\nhead(results$`How many states this US state borders`)\n```\n\n## Links for learning SPARQL\n\n- [A beginner-friendly course for SPARQL](https://www.wikidata.org/wiki/Wikidata:A_beginner-friendly_course_for_SPARQL)\n- Building a SPARQL query: [Museums on Instagram](https://www.wikidata.org/wiki/Help:SPARQL/Building_a_query/Museums_on_Instagram)\n- [SPARQL Query Examples](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples) for WDQS\n- [Using SPARQL to access Linked Open Data](http://programminghistorian.org/lessons/graph-databases-and-SPARQL) by Matthew Lincoln\n- Interesting or illustrative [SPARQL queries](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries) for Wikidata\n- Wikidata [2016 SPARQL Workshop](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/2016_SPARQL_Workshop)\n- [Wikidata SPARQL Query video tutorial](https://www.youtube.com/watch?v=1jHoUkj_mKw) by Navino Evans\n- _[Learning SPARQL](http://www.learningsparql.com/)_ by Bob DuCharme\n- [WDQS User Manual](https://www.mediawiki.org/wiki/Wikidata_query_service/User_Manual)\n\n## Additional Information\n\nPlease note that this project is released with a [Contributor Code of Conduct](https://github.com/bearloga/WikidataQueryServiceR/blob/master/CONDUCT.md). By participating in this project you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwikimedia%2Fwikidataqueryservicer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwikimedia%2Fwikidataqueryservicer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwikimedia%2Fwikidataqueryservicer/lists"}