Learn R Programming

⚠️There's a newer version (1.0.17-18) of this package.Take me there.

redland

The R package redland provides methods to create, query and write information stored in the Resource Description Framework (RDF). An introduction to RDF can be found at http://www.w3.org/TR/rdf-primer. In brief, RDF provides a structured graph consisting of Statements composed of Subject, Predicate, and Object Nodes.

This package is implemented as R scripts that provide an R interface (aka "wrapper") to the Redland RDF C libraries that are described at http://librdf.org/docs/api/index.html. In this redland R wrapper, S4 classes are used to model RDF data structures. A redland::Statement is composed of redland::Nodes representing the subject, predicate, and object of each triple statement. Statements can be composed into a graph by adding them to a redland::Model, which in turn can be serialized and deserialized to RDF's text formats using redland::Serializer and redland::Parser, respectively.

See the redland_overview vignette for a brief example of usage.

Installation Notes

The redland R package is now available from CRAN. Before the redland R package can be installed, the Redland C libraries may need to be installed, depending on the platform type you are installing to and whether or not you wish to install from source.

Installing on Mac OS X

On Mac OS X, the binary build from CRAN can be installed without installing the Redland C libraries by typing the following commands in the R console:

install.packages("redland")
library(redland)

The redland R package should be available for use at this point.

Alternatively, to install redland from source, please continue reading this section.

The required Redland C libraries can be installed with either Mac Ports package manager or the HomeBrew package manager. The HomeBrew package manager can be significantly faster to install but either one will work provided the directions shown below are followed.

You can check if you have MacPorts installed by entering the following command in a terminal window:

port version

Installing on Mac OS X with Macports

If you are already using the MacPorts package manager, you can install redland with the following commands, otherwise, it is recommended that you skip to the next section Installing with HomeBrew. To install the redland R package with MacPorts, enter these commands at a terminal window:

sudo port install redland

Then enter these commands in the R console:

install.packages("redland", type="source")
library(redland)

Please note that the install.packages command specifies a "source" installation. Installing from source is only necessary if Macports is being used, and is not a requirement if Homebrew is used.

The redland R package should be available for use at this point

Installing on Mac OS X with HomeBrew

On Mac OS X you can use the package management system HomeBrew to install the necessary libraries. The HomeBrew software can be installed with the following command entered at a terminal window:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once HomeBrew has been installed, you can then enter the following command to install the Redland C libraries:

brew install redland

Next, install the redland R package with these commands typed at the R console window:

install.packages("redland", type="source")
library(redland)

The redland R package should be available for use at this point.

Installing on Ubuntu

For ubuntu, install the required Redland C libraies:

sudo apt-get update
sudo apt-get install librdf0 librdf0-dev

Then install the R packages from the R console:

install.packages("redland")
library(redland)

Installing on Windows

For windows, the redland R package is distributed as a binary release, and it is not necessary to install any additional system libraries.

To install the R packages from the R console:

install.packages("redland")
library(redland)

Example Usage

The redland library can be used for a wide variety of RDF parsing and creation tasks. Some examples are provided in the redland_overview vignette. As a quick start, here is an example that creates an RDF graph using an in-memory storage model, adds some triples, and then serializes the graph to disk.

library(redland)

# World is the redland mechanism for scoping models
world <- new("World")

# Storage provides a mechanism to store models; in-memory hashes are convenient for small models
storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'")

# A model is a set of Statements, and is associated with a particular Storage instance
model <- new("Model", world=world, storage, options="")

# Add some Dublin Core properties to the model
dc <- "http://purl.org/dc/elements/1.1/"
stmt <- new("Statement", world=world, 
        subject="http://ropensci.org/", predicate=paste0(dc, "title"), object="ROpenSci")
addStatement(model, stmt)
stmt <- new("Statement", world=world, 
        subject="http://ropensci.org/", predicate=paste0(dc, "language"), object="en")
addStatement(model, stmt)
stmt <- new("Statement", world=world, 
        subject="http://ropensci.org/", predicate=paste0(dc, "license"), 
        object="https://creativecommons.org/licenses/by/2.0/")
addStatement(model, stmt)

# Serialize the model to a TTL file
serializer <- new("Serializer", world, name="turtle", mimeType="text/turtle")
status <- setNameSpace(serializer, world, namespace="http://purl.org/dc/elements/1.1/", prefix="dc")  
filePath <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".ttl")
status <- serializeToFile(serializer, world, model, filePath)
readLines(file(filePath))

Acknowledgements

Work on this package was supported by NSF-ABI grant #1262458 to C. Gries, M. Jones, and S. Collins.

Copy Link

Version

Install

install.packages('redland')

Monthly Downloads

1,474

Version

1.0.17-9

License

Apache License 2.0

Maintainer

Matthew B Jones

Last Published

December 15th, 2016

Functions in redland (1.0.17-9)

freeQuery

Free memory used by a librdf query
freeStatement

Free memory used by a librdf statement
freeModel

Free memory used by a librdf model.
freeStorage

Free memory used by a librdf storage object
addStatement

Add a Statement object to the Model
freeSerializer

Free memory used by a librdf serializer.
freeWorld

Free memory used by a librdf world object
executeQuery

Execute a query
getNodeType

Determine the node type and return as a string
getQueryResultLimit

Get the query result limit
librdf_digest_final

Finish the digesting of data.
librdf_copyright_string

Copyright string (multiple lines).
librdf_free_storage

Destructor - destroy a librdf_storage object.
librdf_digest_update

Add more data to the librdf_digest object.
librdf_digest_update_string

Add a string to the librdf_digest object.
getNextResult

Get the next query result.
librdf_free_stream

Destructor - destroy an libdf_stream object.
getBlankNodeId

Get the blank identifier that has been assigned for a specified Node object
librdf_digest_init

(Re)initialise the librdf_digest object.
librdf_digest_to_string

Get a string representation of the digest object.
librdf_free_serializer

Destructor - destroys a librdf_serializer object.
librdf_free_statement

Destructor - destroy a librdf_statement.
librdf_iterator_end

Test if the iterator has finished.
librdf_log_message_facility

Retrieve facility that generated the message.
librdf_log_message_level

Retrieve severity of log message.
librdf_internal_test_warning

For internal testing, not part of public API
librdf_model_add_typed_literal_statement

Create and add a new statement about a typed literal to the model.
librdf_model_add_string_literal_statement

Create and add a new statement about a literal to the model.
librdf_model_context_as_stream

List all statements in a model context.
librdf_model_context_remove_statement

Remove a statement from a model in a context.
length,SWIGArray-method

Return length of a SWIGArray
librdf_copyright_string_get

Return Redland RDF copyright string
librdf_free_model

Destructor - Destroy a librdf_model object.
librdf_free_iterator

Destructor - destroy a librdf_iterator object.
librdf_free_world

Terminate the library and frees all allocated resources.
librdf_free_uri

Destructor - destroy a librdf_uri object.
librdf_log_message_code

Retrieve error code from log message.
librdf_iterator_next

Move to the next iterator element.
librdf_model_contains_context

Check for a context in the model.
librdf_model_contains_statement

Check for a statement in the model.
librdf_free_parser

Destructor - destroys a librdf_parser object.
librdf_free_node

Destructor - destroy an librdf_node object.
librdf_model_context_add_statements

Add statements to a model with a context.
librdf_model_context_add_statement

Add a statement to a model with a context.
librdf_model_get_feature

Get the value of a graph feature .
librdf_model_get_source

Return one source (subject) of arc in an RDF graph given arc (predicate) and target (object).
librdf_model_to_string

Write serialized model to a string.
librdf_model_sync

Synchronise the model to the model implementation.
librdf_new_serializer

Constructor - create a new librdf_serializer object.
librdf_new_statement_from_nodes

Constructor - create a new librdf_statement from existing librdf_node objects.
librdf_new_storage_from_storage

Copy constructor - create a new librdf_storage object from an existing one
librdf_new_storage

Constructor - create a new librdf_storage object.
librdf_node_is_literal

Check node is a literal.
librdf_node_is_blank

Check node is a blank nodeID.
librdf_iterator_get_context

Get the context of the current object on the iterator.
librdf_hash_to_string

Format the hash as a string, suitable for parsing by librdf_hash_from_string.
librdf_internal_test_error

For internal testing, not part of public API
librdf_iterator_get_object

Get the current object from the iterator.
librdf_model_add

Create and add a new statement about a resource to the model.
librdf_model_as_stream

List the model contents as a stream of statements.
librdf_model_get_arcs_in

Return the properties pointing to the given resource.
librdf_model_get_arcs_out

Return the properties pointing from the given resource.
librdf_model_query_execute

Execute a query against the model.
librdf_model_find_statements_in_context

Search the model for matching statements in a given context.
librdf_model_context_remove_statements

Remove statements from a model with the given context.
librdf_model_remove_statement

Remove a known statement from the model.
librdf_model_has_arc_out

Check if a node has a given property pointing from it.
librdf_model_load

Load content from a URI into the model.
librdf_model_transaction_commit

Commit a transaction.
librdf_model_transaction_rollback

Rollback a transaction.
librdf_new_node_from_typed_literal

Constructor - create a new typed literal librdf_node object.
librdf_new_node_from_uri_local_name

Constructor - create a new resource librdf_node object with a given URI and local name.
librdf_node_get_blank_identifier

Get the blank node identifier as a UTF-8 encoded string.
librdf_parser_get_feature

Get the value of a parser feature.
librdf_node_equals

Compare two librdf_node objects for equality.
librdf_parser_get_namespaces_seen_count

Get the number of namespaces seen during parsing
librdf_parser_parse_string_into_model

Parse a string of content into an librdf_model.
librdf_parser_parse_string_as_stream

Parse a string of content to a librdf_stream of statements.
librdf_query_results_get_binding_value

Get one binding value for the current result.
librdf_query_results_get_bindings_count

Get the number of bound variables in the result.
librdf_query_set_offset

Set the query-specified offset on results.
librdf_serializer_check_name

Check if a serializer name is known
librdf_statement_set_predicate

Set the statement predicate.
librdf_model_transaction_start

Start a transaction
librdf_new_digest

Constructor - create a new librdf_digest object.
librdf_statement_set_subject

Set the statement subject.
librdf_new_node_from_normalised_uri_string

Constructor - create a new librdf_node object from a UTF-8 encoded URI string normalised to a new base URI.
librdf_new_node_from_node

Copy constructor - create a new librdf_node object from an existing librdf_node object.
librdf_new_query

Constructor - create a new librdf_query object.
librdf_new_query_from_query

Copy constructor - create a new librdf_query object from an existing one
librdf_new_uri_from_filename

Constructor - create a new librdf_uri object from a filename.
librdf_new_uri_from_uri

Copy constructor - create a new librdf_uri object from an existing librdf_uri object.
librdf_node_is_resource

Check node is a resource.
librdf_node_to_string

Format the node as a string in a debugging format.
getTermType

Return the redland node type for the specified RDF term in a statement
librdf_free_hash

Destructor - destroy a librdf_hash object.
librdf_free_digest

Destructor - destroy a librdf_digest object.
is.null.externalptr

Determine whether an externalptr object is NULL.
librdf_free_query_results

Destructor - destroy a librdf_query_results object.
librdf_free_query

Destructor - destroy a librdf_query object.
librdf_log_message_locator

Retrieve locator of log entry.
librdf_model_add_statement

Add a statement to the model.
librdf_log_message_message

Retrieve text message from log entry.
librdf_model_add_statements

Add a stream of statements to the model.
librdf_model_get_arcs

Return the arcs (predicates) of an arc in an RDF graph given source (subject) and target (object).
librdf_model_get_contexts

Return the list of contexts in the graph.
librdf_model_get_targets

Return the targets (objects) of an arc in an RDF graph given source (subject) and arc (predicate).
librdf_model_has_arc_in

Check if a node has a given property pointing to it.
librdf_model_set_feature

Set the value of a graph feature.
librdf_model_size

Get the number of statements in the model.
librdf_new_node_from_blank_identifier

Constructor - create a new blank node librdf_node object from a blank node identifier.
librdf_new_node_from_literal

Constructor - create a new literal librdf_node object.
librdf_new_node

Constructor - create a new librdf_node object with a private identifier.
librdf_new_parser

Constructor - create a new librdf_parser object.
librdf_new_hash_from_array_of_strings

Constructor - create a new librdf_hash object from an array of strings.
freeParser

Free memory used by a librdf parser
librdf_new_hash_from_string

Constructor - create a new librdf_hash object from a string.
librdf_new_model

Constructor - create a new storage librdf_model object.
librdf_new_model_with_options

Constructor - Create a new librdf_model with storage.
librdf_new_node_from_uri_string

Constructor - create a new librdf_node object from a URI string.
librdf_new_node_from_uri

Constructor - create a new resource librdf_node object with a given URI.
librdf_new_uri

Constructor - create a new librdf_uri object from a URI string.
librdf_new_world

Create a new Redland execution environment.
freeQueryResults

Free memory used by a librdf query results
librdf_node_get_literal_value_language

Get the XML language of the node.
librdf_node_get_type

Get the type of the node.
librdf_node_get_literal_value

Get the literal value of the node as a UTF-8 encoded string.
librdf_parser_get_namespaces_seen_uri

Get the uri of namespaces seen during parsing
librdf_parser_get_namespaces_seen_prefix

Get the prefix of namespaces seen during parsing
librdf_query_results_as_stream

Get a query result as an RDF graph in librdf_stream form
librdf_query_results_finished

Find out if binding results are exhausted.
librdf_query_results_get_boolean

Get boolean query result.
librdf_query_results_get_count

Get number of bindings so far.
librdf_node_get_uri

Get the URI for a node object.
librdf_parser_guess_name

Get a parser name for content with type or identifier
librdf_parser_guess_name2

Get a parser name for content with type or identifier
librdf_query_results_get_binding_name

Get binding name for the current result.
librdf_query_results_get_binding_value_by_name

Get one binding value for a given name in the current result.
librdf_serializer_serialize_stream_to_string

Write a librdf_stream to a string.
librdf_serializer_set_feature

Set the value of a serializer feature.
librdf_statement_to_string

Format the librdf_statement as a string.
librdf_stream_end

Test if the stream has ended.
librdf_stream_next

Move to the next librdf_statement in the stream.
librdf_uri_compare

Compare two librdf_uri objects lexicographically.
librdf_version_release_get

Return the Redland librdf release version number
librdf_version_release

Library release version number as a decimal integer.
initialize,Node-method

Initialize a Node object.
parseFileIntoModel

Parse the contents of a file into a model
raptor_version_string

Raptor library version string.
raptor_version_string_get

Get Raptor library version string.
rasqal_version_decimal_get

Get the Rasqal version as a decimal number.
rasqal_version_decimal

Rasqal version as a decimal number.
librdf_version_major

Library major version number as a decimal integer.
librdf_version_major_get

Return the Redland librdf major version number
librdf_world_get_feature

Get the value of a world feature.
librdf_world_open

Open a created redland world environment.
raptor_locator_line

Get line number from locator.
rasqal_version_string_get

Get the Rasqal version as a string
raptor_locator_uri

Get URI from locator.
rasqal_version_string

Rasqal version as a string
redland

Create, query and write RDF graphs.
librdf_query_get_limit

Get the query-specified limit on results.
librdf_query_get_offset

Get the query-specified offset on results.
librdf_query_results_next

Move to the next result.
librdf_query_results_to_file

Write a query results to a file.
librdf_statement_get_object

Get the statement object.
librdf_statement_get_predicate

Get the statement predicate.
librdf_world_set_feature

Set the value of a world feature.
librdf_uri_to_string

Format the URI as a string.
librdf_uri_equals

Compare two librdf_uri objects for equality.
librdf_world_set_logger

Set the world log handling function.
librdf_node_get_li_ordinal

Get the node li object ordinal value.
librdf_node_get_literal_value_as_latin1

Get the string literal value of the node as ISO Latin-1.
librdf_node_get_literal_value_datatype_uri

Get the typed literal datatype URI of the literal node.
librdf_parser_parse_as_stream

Parse a URI to a librdf_stream of statements.
librdf_node_get_literal_value_is_wf_xml

Get the XML well-formness property of the node.
librdf_parser_parse_counted_string_as_stream

Parse a counted string of content to a librdf_stream of statements.
librdf_parser_set_feature

Set the value of a parser feature.
librdf_serializer_get_feature

Get the value of a serializer feature.
librdf_query_results_is_syntax

Test if librdf_query_results is a syntax.
librdf_query_execute

Run the query on a model.
librdf_query_results_is_graph

Test if librdf_query_results is RDF graph format.
librdf_serializer_serialize_model_to_file

Write a serialized librdf_model to a file.
librdf_short_copyright_string

Short copyright string (one line).
librdf_statement_equals

Check if two statements are equal.
librdf_stream_get_context

Get the context of the current object on the stream.
librdf_stream_get_object

Get the current librdf_statement in the stream.
librdf_version_minor_get

Return the Redland librdf minor version number
librdf_version_minor

Library minor version number as a decimal integer.
initialize,Model-method

Constructor for a Model object.
mergeNamespace_roclet

A custom Roxygen roclet that adds Redland RDF functions to NAMESPACE file generated by Roxygen.
librdf_query_results_to_file2

Write a query results to a file.
librdf_serializer_set_namespace

Set a namespace URI/prefix mapping.
librdf_query_results_to_string

Turn a query results into a string.
librdf_short_copyright_string_get

Return Redland librdf copyright string
librdf_statement_get_subject

Get the statement subject.
librdf_statement_is_complete

Check if statement is a complete and legal RDF triple.
librdf_version_decimal_get

Return Redland librdf copyright
raptor_version_minor_get

Get Raptor library minor version.
librdf_version_decimal

Library full version as a decimal integer.
roc_output.mergeNamespace

Roxygen output function that merges a base NAMESPACE file with the Roxygen dynamically created NAMSPACE file
raptor_version_minor

Raptor library minor version.
raptor_locator_file

Get file name from locator.
raptor_locator_column

Get column number from locator
raptor_version_decimal_get

Raptor version as a decimal number.
setNameSpace

Set a namespace for the serializer.
raptor_version_decimal

Raptor version as a decimal number
setQueryResultLimit

Set limit on returned query results
librdf_model_get_sources

Return the sources (subjects) of arc in an RDF graph given arc (predicate) and target (object).
librdf_model_get_arc

Return one arc (predicate) of an arc in an RDF graph given source (subject) and target (object).
librdf_model_find_statements

Find matching statements in the model.
[,ExternalReference-method

Subset a list of ExternalReferences
[<-,ExternalReference-method

Assign values in a list of ExternalReferences
librdf_new_hash

Constructor - create a new librdf_hash object.
librdf_model_get_target

Return one target (object) of an arc in an RDF graph given source (subject) and arc (predicate).
librdf_new_statement_from_statement

Copy constructor - create a new librdf_statement from an existing librdf_statement. Creates a deep copy - changes to original statement nodes are not reflected in the copy.
librdf_new_model_from_model

Copy constructor - create a new librdf_model from an existing one.
librdf_new_statement

Constructor - create a new empty librdf_statement.
librdf_parser_check_name

Check if a parser name is known
librdf_query_results_is_bindings

Test if librdf_query_results is variable bindings format.
librdf_parser_parse_counted_string_into_model

Parse a counted string of content into an librdf_model.
librdf_parser_parse_into_model

Parse a URI of content into an librdf_model.
librdf_parser_get_accept_header

Get an HTTP Accept value for the parser.
librdf_query_results_is_boolean

Test if librdf_query_results is boolean format.
librdf_query_results_to_string2

Turn a query results into a string.
librdf_query_set_limit

Set the query-specified limit on results.
librdf_serializer_serialize_model_to_string

Write a serialized librdf_model to a string. The returned string must be freed by the caller using librdf_free_memory().
librdf_serializer_serialize_stream_to_file

Write a librdf_stream to a file.
librdf_statement_match

Match a statement against a 'partial' statement.
librdf_statement_set_object

Set the statement object.
raptor_locator_byte

Get the locator byte offset from locator.
raptor_version_major_get

Get Raptor library major version
initialize,QueryResults-method

Initialize the QueryResults object.
raptor_version_major

Raptor library major version
rasqal_version_major

Rasqal major version number.
rasqal_version_major_get

Get Rasqal major version number.
initialize,Statement-method

Construct a Statement object.
initialize,Storage-method

Initialize a Storage object
rasqal_version_release

Rasqal release version number.
rasqal_version_release_get

Get the Rasqal release version number.
librdf_version_string_get

Return the Redland librdf version as a string.
serializeToFile

Serialize a model to a file.
serializeToCharacter

Serialize a model to a character vector.
librdf_version_string

Library full version as a string.
initialize,Parser-method

Initialize a Parser object.
raptor_version_release_get

Raptor library release.
initialize,Query-method

Initialize the Query object.
raptor_version_release

Raptor library release.
rasqal_version_minor_get

Get the Rasqal minor version number.
rasqal_version_minor

Rasqal minor version number.
roc_process.mergeNamespace

Roxygen process function for the 'mergeNamespace' roclet
initialize,Serializer-method

Construct a Serializer object.
initialize,World-method

Initialize the World object.
QueryResults-class

A Redland QueryResults object is used to inspect query results from a Query object.
Query-class

Query an RDF model
Node-class

A Redland Node, used to store one node in an RDF triple statement.
Parser-class

An RDF Parser object
Statement-class

An RDF Statement object
Model-class

A Redland Model object
Serializer-class

An RDF Serializer object.
Storage-class

A Redland Storage object
World-class

A Redland World object, used to initialize the Redland RDF library.
[<-,ExternalReference-method

Assign values in a list of ExternalReferences