-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathREADME.Rmd
144 lines (101 loc) · 3.77 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
output: github_document
---
# rdflib <img src="man/figures/logo.svg" align="right" alt="" width="120" />
<!-- badges: start -->
[![R-CMD-check](https://github.com/ropensci/rdflib/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/rdflib/actions)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/rdflib)](https://cran.r-project.org/package=rdflib)
[![](http://badges.ropensci.org/169_status.svg)](https://github.com/ropensci/software-review/issues/169)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/rdflib)](https://CRAN.R-project.org/package=rdflib)
[![DOI](https://zenodo.org/badge/100521776.svg)](https://zenodo.org/badge/latestdoi/100521776)
<!-- badges: end -->
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
A friendly and consise user interface for performing common
tasks on rdf data, such as parsing and converting between
formats including rdfxml, turtle, nquads, ntriples,
and trig, creating rdf graphs, and performing SPARQL
queries. This package wraps the redland R package which
provides direct bindings to the redland C library. Additionally,
the package supports parsing and serialization of rdf
into json-ld through the json-ld package, which binds
the official json-ld javascript API. The package
interface takes inspiration from the Python rdflib library.
## Installation
You can install rdflib from GitHub with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("ropensci/rdflib")
```
## Basic use
While not required, `rdflib` is designed to play nicely with `%>%` pipes, so we will load the `magrittr` package as well:
```{r, message=FALSE}
library(magrittr)
library(rdflib)
```
Parse a file and serialize into a different format:
```{r parse}
system.file("extdata/dc.rdf", package="redland") %>%
rdf_parse() %>%
rdf_serialize("test.nquads", "nquads")
```
Perform SPARQL queries:
```{r sparql}
sparql <-
'PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?a ?c
WHERE { ?a dc:creator ?c . }'
system.file("extdata/dc.rdf", package="redland") %>%
rdf_parse() %>%
rdf_query(sparql)
```
Initialize graph a new object or add triples statements to an existing graph:
```{r}
x <- rdf()
x <- rdf_add(x,
subject="http://www.dajobe.org/",
predicate="http://purl.org/dc/elements/1.1/language",
object="en")
x
```
Change the default display format (`nquads`) for graph objects:
```{r}
options(rdf_print_format = "jsonld")
x
```
## JSON-LD
We can also work with the JSON-LD format through additional functions provided in the
R package, `jsonld`.
```{r}
out <- tempfile()
rdf_serialize(x, out, "jsonld")
rdf_parse(out, format = "jsonld")
```
For more information on the JSON-LD RDF API, see <https://json-ld.org/spec/latest/json-ld-rdf/>.
```{r include=FALSE}
unlink("test.nquads")
unlink(out)
rdf_free(x)
```
## Advanced Use
See [articles](https://docs.ropensci.org/rdflib/articles/) from the documentation for advanced use including applications to large triplestores, example SPARQL queries, and information about additional database backends.
----
## Citing rdflib
Please also cite the underlying `redland` library when citing `rdflib`
```{r results="asis", warning=FALSE, echo=FALSE}
print(citation("rdflib"), "textVersion")
```
```{r results="asis", warning=FALSE, echo=FALSE}
print(citation("redland"), "text")
```
```{r include=FALSE}
codemeta::write_codemeta()
```
[![rofooter](https://ropensci.org//public_images/github_footer.png)](https://ropensci.org/)