Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit cd55741

Browse files
committed
Prepare for initial CRAN release (v0.1.0)
1 parent 379af84 commit cd55741

7 files changed

Lines changed: 88 additions & 46 deletions

File tree

DESCRIPTION

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
Package: WikidataQueryServiceR
22
Title: API Client Library for 'Wikidata Query Service'
3-
Version: 0.0.3
4-
Date: 2017-01-04
3+
Version: 0.1.0
4+
Date: 2017-01-17
55
Authors@R: c(
6-
person("Mikhail", "Popov", , "mikhail@wikimedia.org", c("aut", "cre")),
6+
person("Mikhail", "Popov", email = "mikhail@wikimedia.org",
7+
role = c("aut", "cre"), comment = "@bearloga on Twitter"),
78
person("Wikimedia Foundation", role = "cph")
89
)
9-
Description: An API client for the Wikidata Query Service
10+
Description: An API client for the 'Wikidata Query Service'
1011
<https://query.wikidata.org/>.
1112
Depends:
12-
R (>= 3.3.2)
13+
R (>= 3.1.2)
1314
Imports:
1415
httr (>= 1.2.1),
1516
dplyr (>= 0.5.0),

R/query.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' "smart" fetches JSON-formatted data and returns a data frame with datetime
66
#' columns converted to POSIXlt
77
#' @param ... Additional parameters to supply to \code{\link[httr]{GET}}
8-
#' @return A data frame of results from WDQS
8+
#' @return A data.frame
99
#' @examples
1010
#' # Cats on Wikidata:
1111
#' sparql_query <- 'SELECT ?item ?itemLabel

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' @title Scrape an example SPARQL query from Wikidata
22
#' @description Scrapes \href{https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples}{SPARQL query service examples page}
3-
#' for specified example(s).
3+
#' for specified example(s). Requires rvest and urltools packages.
44
#' @details If you are planning on scraping multiple examples, please provide
55
#' all the names as a single vector.
66
#' @param example_name The names of the examples as they appear on

README.md

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
# WikidataQueryServiceR
22

3+
[![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)
4+
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/WikidataQueryServiceR)](https://cran.r-project.org/package=WikidataQueryServiceR)
5+
[![CRAN Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/WikidataQueryServiceR)](https://cran.r-project.org/package=WikidataQueryServiceR)
6+
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7+
38
This 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 Oliver Keyes' [WikipediR](https://github.com/Ironholds/WikipediR) and [WikidataR](https://github.com/Ironholds/WikidataR) packages.
49

510
__Author:__ Mikhail Popov (Wikimedia Foundation)<br/>
611
__License:__ [MIT](http://opensource.org/licenses/MIT)<br/>
7-
__Status:__ Active, early in development
12+
__Status:__ Active
813

914
## Example
1015

16+
In 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.
17+
1118
```R
12-
# https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples#Cats
13-
sparql_query <- 'SELECT ?item ?itemLabel
14-
WHERE
15-
{
16-
?item wdt:P31 wd:Q146 .
17-
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
18-
}
19-
LIMIT 10'
20-
query_wikidata(sparql_query) # 10 rows were returned by WDQS
19+
sparql_query <- 'PREFIX wd: <http://www.wikidata.org/entity/>
20+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
21+
PREFIX wikibase: <http://wikiba.se/ontology#>
22+
SELECT DISTINCT ?genre ?genreLabel WHERE {
23+
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
24+
?film wdt:P31 wd:Q11424.
25+
?film rdfs:label "The Cabin in the Woods"@en.
26+
?film wdt:P136 ?genre.
27+
}'
28+
WikidataQueryServiceR::query_wikidata(sparql_query)
29+
# 5 rows were returned by WDQS
2130
```
2231

23-
|item |itemLabel |
24-
|:----------------------------------------|:------------|
25-
|http://www.wikidata.org/entity/Q25471040 |Pixel |
26-
|http://www.wikidata.org/entity/Q27190410 |Gladstone |
27-
|http://www.wikidata.org/entity/Q27739753 |Sister Cream |
28-
|http://www.wikidata.org/entity/Q27744042 |Bob |
29-
|http://www.wikidata.org/entity/Q27745002 |Musashi |
30-
|http://www.wikidata.org/entity/Q27745006 |Leo |
31-
|http://www.wikidata.org/entity/Q27745008 |Luca |
32-
|http://www.wikidata.org/entity/Q27745009 |Seri |
33-
|http://www.wikidata.org/entity/Q27745011 |Marble |
34-
|http://www.wikidata.org/entity/Q28114532 |Q28114532 |
32+
|genre |genreLabel |
33+
|:---------------------------------------|:--------------------|
34+
|http://www.wikidata.org/entity/Q200092 |horror film |
35+
|http://www.wikidata.org/entity/Q471839 |science fiction film |
36+
|http://www.wikidata.org/entity/Q224700 |comedy horror |
37+
|http://www.wikidata.org/entity/Q859369 |comedy-drama |
38+
|http://www.wikidata.org/entity/Q1342372 |monster film |
3539

3640
For 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).
3741

@@ -43,8 +47,8 @@ This package does not rely on the [rvest](https://cran.r-project.org/package=rve
4347

4448
```R
4549
# install.packages(c("rvest", "urltools"))
46-
sparql_query <- scrape_example("Largest cities with female mayor")
47-
cat(sparql_query)
50+
sparql_query <- scrape_example(c("Cats", "Horses", "Largest cities with female mayor"))
51+
cat(sparql_query[["Largest cities with female mayor"]])
4852
```
4953

5054
```SPARQL
@@ -75,8 +79,14 @@ ORDER BY DESC(?population)
7579
LIMIT 10
7680
```
7781

82+
Now we can run all three scraped SPARQL queries and get back three data.frames:
83+
7884
```R
79-
query_wikidata(sparql_query) # 10 rows were returned by WDQS
85+
results <- query_wikidata(sparql_query)
86+
# 113 rows were returned by WDQS
87+
# 6677 rows were returned by WDQS
88+
# 10 rows were returned by WDQS
89+
results$`Largest cities with female mayor`
8090
```
8191

8292
|city |cityLabel |mayor |mayorLabel |
@@ -92,22 +102,13 @@ query_wikidata(sparql_query) # 10 rows were returned by WDQS
92102
|http://www.wikidata.org/entity/Q1563 |Havana |http://www.wikidata.org/entity/Q6774124 |Marta Hernández Romero |
93103
|http://www.wikidata.org/entity/Q19660 |Bucharest |http://www.wikidata.org/entity/Q16593781 |Gabriela Fireaa |
94104

95-
If you are planning on scraping multiple queries, please provide them all as a single vector instead of `s`/`v`/`l`-`apply`ing `scrape_example` because behind the scenes the function scrapes the examples page once and then it can really quickly extract all the queries from a single cache.
105+
## Installation
96106

97-
**Note** that since `query_wikidata` can also operate on a vector of queries, you can easily create chains:
107+
This R package depends on [httr](https://cran.r-project.org/package=httr), [dplyr](https://cran.r-project.org/package=dplyr), and [jsonlite](https://cran.r-project.org/package=jsonlite) R packages (and their dependencies).
98108

99109
```R
100-
# Results will be a named list of data frames
101-
# the names being the original example names.
102-
library(magrittr)
103-
results <- c("Cats", "Horses", "Largest cities with female mayor") %>%
104-
scrape_example %>%
105-
query_wikidata
110+
install.packages("WikidataQueryServiceR")
106111
```
107-
108-
## Installation
109-
110-
This R package depends on [httr](https://cran.r-project.org/package=httr), [dplyr](https://cran.r-project.org/package=dplyr), and [jsonlite](https://cran.r-project.org/package=jsonlite) R packages (and their dependencies).
111112

112113
To install the development version:
113114

cran-comments.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
WikidataQueryServiceR 0.1.0
2+
---------------------------
3+
4+
## Test environments
5+
* local OS X install, R 3.3.2
6+
* win-builder (devel and release)
7+
8+
## R CMD check results
9+
There were no ERRORs or WARNINGs and 1 NOTE:
10+
11+
```
12+
* checking CRAN incoming feasibility ... NOTE
13+
Maintainer: 'Mikhail Popov <mikhail@wikimedia.org>'
14+
15+
New submission
16+
17+
Possibly mis-spelled words in DESCRIPTION:
18+
API (2:8, 9:17)
19+
```
20+
21+
## R-hub Builder results
22+
Platforms:
23+
* Windows Server 2008 R2 SP1, R-devel, 32/64 bit
24+
* Fedora Linux, R-devel, clang, gfortran
25+
* Ubuntu Linux 16.04 LTS, R-release, GCC
26+
27+
There were no ERRORs or WARNINGs and 1 NOTE:
28+
29+
```
30+
N checking CRAN incoming feasibility
31+
Maintainer: 'Mikhail Popov <mikhail@wikimedia.org>'
32+
33+
New submission
34+
35+
License components with restrictions and base license permitting such:
36+
MIT + file LICENSE
37+
File 'LICENSE':
38+
YEAR: 2016
39+
COPYRIGHT HOLDER: Wikimedia Foundation
40+
```

man/query_wikidata.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scrape_example.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)