-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
88 lines (61 loc) · 2.81 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
output: github_document
---
# glitter <img src="man/figures/logo_small.png" align="right"/>
> DSL for SPARQL in R. :sparkles: `glitter` produces ~~sparkle~~ SPARQL! :sparkles:
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<!-- badges: start -->
[![R-CMD-check](https://github.com/lvaudor/glitter/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/lvaudor/glitter/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Codecov test coverage](https://codecov.io/gh/lvaudor/glitter/branch/master/graph/badge.svg)](https://app.codecov.io/gh/lvaudor/glitter?branch=master)
<!-- badges: end -->
This package aims at writing and sending SPARQL queries without advanced knowledge of the SPARQL language syntax.
It makes the exploration and use of Linked Open Data (Wikidata in particular) easier for those who do not know SPARQL well.
With glitter, compared to writing SPARQL queries by hand, your code should be easier to write, and easier to read by your peers who do not know SPARQL.
The glitter package supports a "domain-specific language" (DSL) with function names (and syntax) closer to the tidyverse and base R than to SPARQL.
For instance, to find a corpus of 5 articles with a title in English and "wikidata" in that title, instead of writing SPARQL by hand you can run:
```{r}
library("glitter")
query <- spq_init() %>%
spq_add("?item wdt:P31 wd:Q13442814") %>%
spq_label(item) %>%
spq_filter(str_detect(str_to_lower(item_label), 'wikidata')) %>%
spq_head(n = 5)
query
```
Note how we were able to use `str_detect()` and `str_to_lower()` (as in the stringr package) instead of SPARQL's functions `REGEX` and `LCASE`.
To perform the query,
```{r}
spq_perform(query)
```
To get a random subset of movies with the date they were released, you could use
```{r}
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_label(film) %>%
spq_add("?film wdt:P577 ?date") %>%
spq_mutate(date = year(date)) %>%
spq_head(10) %>%
spq_perform()
```
Note that we were able to "overwrite" the date variable, which is straightforward in dplyr, but not so much in SPARQL.
## Installation
Install this packages through R-universe:
```r
install.packages("glitter", repos = "https://lvaudor.r-universe.dev")
```
Or through GitHub:
```r
install.packages("remotes") #if remotes is not already installed
remotes::install_github("lvaudor/glitter")
```
## Documentation
You can access the documentation regarding package `glitter` [on its pkgdown website](http://perso.ens-lyon.fr/lise.vaudor/Rpackages/glitter/).