项目作者: ropensci

项目描述 :
:package: High level wrapper around the redland package for common rdf applications
高级语言: HTML
项目地址: git://github.com/ropensci/rdflib.git
创建时间: 2017-08-16T18:46:58Z
项目社区:https://github.com/ropensci/rdflib

开源协议:Other

下载


" class="reference-link">rdflib

R-CMD-check
Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.
CRAN_Status_Badge

CRAN RStudio mirror
downloads
DOI

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:

  1. # install.packages("devtools")
  2. 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:

  1. library(magrittr)
  2. library(rdflib)

Parse a file and serialize into a different format:

  1. system.file("extdata/dc.rdf", package="redland") %>%
  2. rdf_parse() %>%
  3. rdf_serialize("test.nquads", "nquads")

Perform SPARQL queries:

  1. sparql <-
  2. 'PREFIX dc: <http://purl.org/dc/elements/1.1></http:>
  3. SELECT ?a ?c
  4. WHERE { ?a dc:creator ?c . }'
  5. system.file("extdata/dc.rdf", package="redland") %>%
  6. rdf_parse() %>%
  7. rdf_query(sparql)
  8. #> # A tibble: 1 × 2
  9. #> a c
  10. #> <chr> <chr>
  11. #> 1 http://www.dajobe.org/ Dave Beckett

Initialize graph a new object or add triples statements to an existing
graph:

  1. x <- rdf()
  2. x <- rdf_add(x,
  3. subject="http://www.dajobe.org/",
  4. predicate="http://purl.org/dc/elements/1.1/language",
  5. object="en")
  6. x
  7. #> Total of 1 triples, stored in hashes
  8. #> -------------------------------
  9. #> <http://www.dajobe.org></http:> <http://purl.org/dc/elements/1.1/language> "en" .

Change the default display format (nquads) for graph objects:

  1. options(rdf_print_format = "jsonld")
  2. x
  3. #> Total of 1 triples, stored in hashes
  4. #> -------------------------------
  5. #> {
  6. #> "@id": "http://www.dajobe.org/",
  7. #> "http://purl.org/dc/elements/1.1/language": "en"
  8. #> }

JSON-LD

We can also work with the JSON-LD format through additional functions
provided in the R package, jsonld.

  1. out <- tempfile()
  2. rdf_serialize(x, out, "jsonld")
  3. rdf_parse(out, format = "jsonld")
  4. #> Total of 1 triples, stored in hashes
  5. #> -------------------------------
  6. #> {
  7. #> "@id": "http://www.dajobe.org/",
  8. #> "http://purl.org/dc/elements/1.1/language": "en"
  9. #> }

For more information on the JSON-LD RDF API, see
https://json-ld.org/spec/latest/json-ld-rdf.

Advanced Use

See 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

Carl Boettiger. (2018). rdflib: A high level wrapper around the redland
package for common rdf applications (Version 0.1.0). Zenodo.
https://doi.org/10.5281/zenodo.1098478

Jones M, Slaughter P, Ooms J, Boettiger C, Chamberlain S (2022).
redland: RDF Library Bindings in R.
https://doi.org/10.5063/F1VM496B, R package version 1.0.17-16,
https://github.com/ropensci/redland-bindings/tree/master/R/redland.

rofooter