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

Commit 3530cef

Browse files
committed
Fixes #3 and prepares for v0.1.1 submission to CRAN
* Updated documentation to use Markdown thanks to roxygen2 6.0.0 * Added more links for learning SPARQL in context of Wikidata (see `help("WDQS", package = "WikidataQueryServiceR")`) * Fixed a bug with JSON-formatted results (#3)
1 parent 39a98ed commit 3530cef

File tree

10 files changed

+99
-155
lines changed

10 files changed

+99
-155
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: WikidataQueryServiceR
22
Title: API Client Library for 'Wikidata Query Service'
3-
Version: 0.1.0
4-
Date: 2017-01-17
3+
Version: 0.1.1
4+
Date: 2017-04-28
55
Authors@R: c(
66
person("Mikhail", "Popov", email = "mikhail@wikimedia.org",
77
role = c("aut", "cre"), comment = "@bearloga on Twitter"),
@@ -23,4 +23,5 @@ BugReports: https://github.com/bearloga/WikidataQueryServiceR/issues
2323
License: MIT + file LICENSE
2424
Encoding: UTF-8
2525
LazyData: true
26-
RoxygenNote: 5.0.1
26+
Roxygen: list(markdown = TRUE)
27+
RoxygenNote: 6.0.1

NEWS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
WikidataQueryServiceR 0.1.1
2+
---------------------------
3+
4+
## Changes
5+
6+
* Updated documentation to use Markdown thanks to [roxygen2 6.0.0](https://blog.rstudio.org/2017/02/01/roxygen2-6-0-0/)
7+
* Added more links for learning SPARQL in context of Wikidata
8+
(see `help("WDQS", package = "WikidataQueryServiceR")`)
9+
10+
## Bug fixes
11+
12+
* Fixed a bug with JSON-formatted results ([#3](https://github.com/bearloga/WikidataQueryServiceR/issues/3))
13+
114
WikidataQueryServiceR 0.1.0
215
---------------------------
316

R/query.R

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,23 @@
33
#' @param sparql_query SPARQL query (can be a vector of queries)
44
#' @param format "simple" uses CSV and returns pure character data frame, while
55
#' "smart" fetches JSON-formatted data and returns a data frame with datetime
6-
#' columns converted to POSIXlt
7-
#' @param ... Additional parameters to supply to \code{\link[httr]{GET}}
8-
#' @return A data.frame
6+
#' columns converted to `POSIXlt`
7+
#' @param ... Additional parameters to supply to [httr::GET()]
8+
#' @return A `data.frame`
99
#' @examples
10-
#' # Cats on Wikidata:
11-
#' sparql_query <- 'SELECT ?item ?itemLabel
12-
#' WHERE
13-
#' {
14-
#' ?item wdt:P31 wd:Q146 .
15-
#' SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
16-
#' }
17-
#' LIMIT 10'
10+
#' # R's versions and release dates:
11+
#' sparql_query <- 'SELECT DISTINCT
12+
#' ?softwareVersion ?publicationDate
13+
#' WHERE {
14+
#' BIND(wd:Q206904 AS ?R)
15+
#' ?R p:P348 [
16+
#' ps:P348 ?softwareVersion;
17+
#' pq:P577 ?publicationDate
18+
#' ] .
19+
#' }'
1820
#' query_wikidata(sparql_query)
1921
#'
2022
#' \dontrun{
21-
#' sparql_query <- "#Recent Events
22-
#' SELECT ?event ?eventLabel ?date
23-
#' WHERE
24-
#' {
25-
#' # find events
26-
#' ?event wdt:P31/wdt:P279* wd:Q1190554.
27-
#' # with a point in time or start date
28-
#' OPTIONAL { ?event wdt:P585 ?date. }
29-
#' OPTIONAL { ?event wdt:P580 ?date. }
30-
#' # but at least one of those
31-
#' FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
32-
#' # not in the future, and not more than 31 days ago
33-
#' BIND(NOW() - ?date AS ?distance).
34-
#' FILTER(0 <= ?distance && ?distance < 31).
35-
#' # and get a label as well
36-
#' OPTIONAL {
37-
#' ?event rdfs:label ?eventLabel.
38-
#' FILTER(LANG(?eventLabel) = \"en\").
39-
#' }
40-
#' }
41-
#' # limit to 10 results so we don't timeout
42-
#' LIMIT 10"
43-
#'
4423
#' # "smart" format converts all datetime columns to POSIXlt
4524
#' query_wikidata(sparql_query, format = "smart")
4625
#' }
@@ -77,9 +56,8 @@ query_wikidata <- function(sparql_query, format = c("simple", "smart"), ...) {
7756
)
7857
httr::stop_for_status(response)
7958
if (httr::http_type(response) == "application/sparql-results+json") {
80-
temp <- jsonlite::read_json(httr::content(response, as = "text", encoding = "UTF-8"))
59+
temp <- jsonlite::fromJSON(httr::content(response, as = "text", encoding = "UTF-8"), simplifyVector = FALSE)
8160
}
82-
httr::stop_for_status(response)
8361
if (length(temp$results$bindings) > 0) {
8462
df <- as.data.frame(dplyr::bind_rows(lapply(temp$results$bindings, function(x) {
8563
return(lapply(x, function(y) { return(y$value) }))

R/utils.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#' @title Scrape an example SPARQL query from Wikidata
2-
#' @description Scrapes \href{https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples}{SPARQL query service examples page}
2+
#' @description Scrapes [SPARQL query service examples page](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples)
33
#' 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
7-
#' \href{https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples}{this page}
8-
#' @param ... Additional \code{httr} configurations passed to \code{rvest}
7+
#' [this page](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples)
8+
#' @param ... Additional `httr` configurations passed to `rvest`
99
#' @return The SPARQL query as a character vector.
1010
#' @examples
1111
#' \dontrun{

R/wdqs.R

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
#' @title WikidataQueryServiceR: An R Wrapper For Wikidata Query Service API
22
#' @description This is an R wrapper for the
3-
#' \href{https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service}{Wikidata Query Service}
3+
#' [Wikidata Query Service](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service)
44
#' (WDQS) which provides a way for tools to query Wikidata via
5-
#' \href{https://en.wikipedia.org/wiki/SPARQL}{SPARQL}.
6-
#' @details \href{https://www.mediawiki.org/wiki/Wikidata_query_service}{Wikidata Query Service}
7-
#' is maintained by Wikimedia Foundation's \href{https://www.mediawiki.org/wiki/Wikimedia_Discovery}{Discovery}
8-
#' Department.
9-
#' @references \itemize{
10-
#' \item \href{https://www.mediawiki.org/wiki/Wikidata_query_service/User_Manual}{WDQS User Manual}
11-
#' \item \href{https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples}{SPARQL Query Examples} for WDQS
12-
#' \item \href{http://programminghistorian.org/lessons/graph-databases-and-SPARQL}{Using SPARQL to access Linked Open Data}
13-
#' by Matthew Lincoln
14-
#' \item Interesting or illustrative \href{https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries}{SPARQL queries}
15-
#' for Wikidata
16-
#' \item Wikidata \href{https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/2016_SPARQL_Workshop}{2016 SPARQL Workshop}
17-
#' }
5+
#' [SPARQL](https://en.wikipedia.org/wiki/SPARQL).
6+
#' @details [Wikidata Query Service](https://www.mediawiki.org/wiki/Wikidata_query_service)
7+
#' is maintained by [Wikimedia Foundation](https://wikimediafoundation.org/).
8+
#' @references
9+
#' - [A beginner-friendly course for SPARQL](https://www.wikidata.org/wiki/Wikidata:A_beginner-friendly_course_for_SPARQL)
10+
#' - Building a SPARQL query: [Museums on Instagram](https://www.wikidata.org/wiki/Help:SPARQL/Building_a_query/Museums_on_Instagram)
11+
#' - [SPARQL Query Examples](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples) for WDQS
12+
#' - [Using SPARQL to access Linked Open Data](http://programminghistorian.org/lessons/graph-databases-and-SPARQL)
13+
#' by Matthew Lincoln
14+
#' - Interesting or illustrative [SPARQL queries](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries)
15+
#' for Wikidata
16+
#' - Wikidata [2016 SPARQL Workshop](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/2016_SPARQL_Workshop)
17+
#' - [Wikidata SPARQL Query video tutorial](https://www.youtube.com/watch?v=1jHoUkj_mKw)
18+
#' by Navino Evans
19+
#' - _[Learning SPARQL](http://www.learningsparql.com/)_ by Bob DuCharme
20+
#' - [WDQS User Manual](https://www.mediawiki.org/wiki/Wikidata_query_service/User_Manual)
1821
#' @aliases WDQS
1922
#' @docType package
2023
#' @name WDQS-package

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ __Author:__ Mikhail Popov (Wikimedia Foundation)<br/>
1111
__License:__ [MIT](http://opensource.org/licenses/MIT)<br/>
1212
__Status:__ Active
1313

14+
## Installation
15+
16+
```R
17+
install.packages("WikidataQueryServiceR")
18+
```
19+
20+
To install the development version:
21+
22+
```R
23+
# install.packages(c("devtools", "httr", "dplyr", "jsonlite"))
24+
devtools::install_github("bearloga/WikidataQueryServiceR")
25+
```
26+
1427
## Example
1528

1629
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.
@@ -102,21 +115,6 @@ results$`Largest cities with female mayor`
102115
|http://www.wikidata.org/entity/Q1563 |Havana |http://www.wikidata.org/entity/Q6774124 |Marta Hernández Romero |
103116
|http://www.wikidata.org/entity/Q19660 |Bucharest |http://www.wikidata.org/entity/Q16593781 |Gabriela Fireaa |
104117

105-
## Installation
106-
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).
108-
109-
```R
110-
install.packages("WikidataQueryServiceR")
111-
```
112-
113-
To install the development version:
114-
115-
```R
116-
# install.packages(c("devtools", "httr", "dplyr", "jsonlite"))
117-
devtools::install_github("bearloga/WikidataQueryServiceR")
118-
```
119-
120118
## Additional Information
121119

122120
Please 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.

cran-comments.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
WikidataQueryServiceR 0.1.0
1+
WikidataQueryServiceR 0.1.1
22
---------------------------
33

44
## Test environments
5-
* local OS X install, R 3.3.2
5+
* local macOS install, R 3.4.0
66
* win-builder (devel and release)
77

88
## R CMD check results
@@ -12,35 +12,6 @@ There were no ERRORs or WARNINGs and 1 NOTE:
1212
* checking CRAN incoming feasibility ... NOTE
1313
Maintainer: 'Mikhail Popov <mikhail@wikimedia.org>'
1414
15-
New submission
16-
1715
Possibly mis-spelled words in DESCRIPTION:
18-
API (2:8, 9:17)
19-
20-
Found the following (possibly) invalid URLs:
21-
URL: https://cran.r-project.org/package=WikidataQueryServiceR
22-
From: README.md
23-
Status: 404
24-
Message: Not Found
25-
```
26-
27-
## R-hub Builder results
28-
Platforms:
29-
* Windows Server 2008 R2 SP1, R-devel, 32/64 bit
30-
* Fedora Linux, R-devel, clang, gfortran
31-
* Ubuntu Linux 16.04 LTS, R-release, GCC
32-
33-
There were no ERRORs or WARNINGs and 1 NOTE:
34-
35-
```
36-
N checking CRAN incoming feasibility
37-
Maintainer: 'Mikhail Popov <mikhail@wikimedia.org>'
38-
39-
New submission
40-
41-
License components with restrictions and base license permitting such:
42-
MIT + file LICENSE
43-
File 'LICENSE':
44-
YEAR: 2016
45-
COPYRIGHT HOLDER: Wikimedia Foundation
16+
API (2:8, 10:17)
4617
```

man/WDQS-package.Rd

Lines changed: 17 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/query_wikidata.Rd

Lines changed: 13 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scrape_example.Rd

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)