SkillAgentSearch skills...

Rdf

RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.

Install / Use

/learn @ruby-rdf/Rdf
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

RDF.rb: Linked Data for Ruby

This is a pure-Ruby library for working with [Resource Description Framework (RDF)][RDF] data.

Gem Version Build Status Coverage Status Gitter chat

Table of contents

  1. Features
  2. Differences between RDF 1.0 and RDF 1.1
  3. Differences between RDF 1.1 and RDF 1.2
  4. Tutorials
  5. Command Line
  6. Examples
  7. Reader/Writer convenience methods
  8. RDF 1.2
  9. Documentation
  10. Dependencies
  11. Installation
  12. Download
  13. Resources
  14. Mailing List
  15. Authors
  16. Contributors
  17. Contributing
  18. License

Features

  • 100% pure Ruby with minimal dependencies and no bloat.
  • Fully compatible with [RDF 1.1][] specifications.
  • Provisional support for [RDF 1.2][] specifications.
  • 100% free and unencumbered public domain software.
  • Provides a clean, well-designed RDF object model and related APIs.
  • Supports parsing and serializing [N-Triples][] and [N-Quads][] out of the box, with more serialization format support available through add-on extensions.
  • Includes in-memory graph and repository implementations, with more storage adapter support available through add-on extensions.
  • Implements basic graph pattern (BGP) query evaluation.
  • Plays nice with others: entirely contained in the RDF module, and does not modify any of Ruby's core classes or standard library.
  • Based entirely on Ruby's autoloading, meaning that you can generally make use of any one part of the library without needing to load up the rest.
  • Compatible with Ruby Ruby >= 3.0, Rubinius and JRuby 9.0+.
    • Note, changes in mapping hashes to keyword arguments for Ruby 3+ may require that arguments be passed more explicitly, especially when the first argument is a Hash and there are optional keyword arguments. In this case, Hash argument may need to be explicitly included within {} and the optional keyword arguments may need to be specified using **{} if there are no keyword arguments.
  • Performs auto-detection of input to select appropriate Reader class if one cannot be determined from file characteristics.

HTTP requests

RDF.rb uses Net::HTTP for retrieving HTTP and HTTPS resources. If the [RestClient][] gem is included, that will be used instead to retrieve remote resources. Clients may also consider using [RestClient Components][] to enable client-side caching of HTTP results using [Rack::Cache][] or other Rack middleware.

See {RDF::Util::File} for configuring other mechanisms for retrieving resources.

Term caching and configuration

RDF.rb uses a weak-reference cache for storing internalized versions of URIs and Nodes. This is particularly useful for Nodes as two nodes are equivalent only if they're the same node.

By default, each cache can grow to an unlimited size, but this can be configured using {RDF.config}, for general limits, along with URI- or Node-specific limits.

For example, to limit the size of the URI intern cache only:

RDF.config.uri_cache_size = 10_000

The default for creating new caches without a specific initialization size can be set using:

RDF.config.cache_size = 100_000

Differences between RDF 1.0 and RDF 1.1

This version of RDF.rb is fully compatible with [RDF 1.1][], but it creates some marginal incompatibilities with [RDF 1.0][], as implemented in versions prior to the 1.1 release of RDF.rb:

  • Introduces {RDF::IRI}, as a synonym for {RDF::URI} either {RDF::IRI} or {RDF::URI} can be used interchangeably. Versions of RDF.rb prior to the 1.1 release were already compatible with IRIs. Internationalized Resource Identifiers (see [RFC3987][]) are a super-set of URIs (see [RFC3986][]) which allow for characters other than standard US-ASCII.
  • {RDF::URI} no longer uses the Addressable gem. As URIs typically don't need to be parsed, this provides a substantial performance improvement when enumerating or querying graphs and repositories.
  • {RDF::List} no longer emits a rdf:List type. However, it will now recognize any subjects that are {RDF::Node} instances as being list elements, as long as they have both rdf:first and rdf:rest predicates.
  • {RDF::Graph} adding a graph_name to a graph may only be done when the underlying storage model supports graph_names (the default {RDF::Repository} does). The notion of graph_name in RDF.rb is treated equivalently to Named Graphs within an RDF Dataset, and graphs on their own are not named.
  • {RDF::Graph}, {RDF::Statement} and {RDF::List} now include {RDF::Value}, and not {RDF::Resource}. Made it clear that using {RDF::Graph} does not mean that it may be used within an {RDF::Statement}, for this see {RDF::Term}.
  • {RDF::Statement} now is stricter about checking that all elements are valid when validating.
  • {RDF::NTriples::Writer} and {RDF::NQuads::Writer} now default to validate output, only allowing valid statements to be emitted. This may disabled by setting the :validate option to false.
  • {RDF::Dataset} is introduced as a class alias of {RDF::Repository}. This allows closer alignment to the RDF concept of Dataset.
  • The graph_name of a graph within a Dataset or Repository may be either an {RDF::IRI} or {RDF::Node}. Implementations of repositories may restrict this to being only {RDF::IRI}.
  • There are substantial and somewhat incompatible changes to {RDF::Literal}. In [RDF 1.1][], all literals are typed, including plain literals and language tagged literals. Internally, plain literals are given the xsd:string datatype and language tagged literals are given the rdf:langString datatype. Creating a plain literal, without a datatype or language, will automatically provide the xsd:string datatype; similar for language tagged literals. Note that most serialization formats will remove this datatype. Code which depends on a literal having the xsd:string datatype being different from a plain literal (formally, without a datatype) may break. However note that the #has\_datatype? will continue to return false for plain or language-tagged literals.
  • {RDF::Query#execute} now accepts a block and returns {RDF::Query::Solutions}. This allows enumerable.query(query) to behave like query.execute(enumerable) and either return an enumerable or yield each solution.
  • {RDF::Queryable#query} now returns {RDF::Query::Solutions} instead of an Enumerator if it's argument is an {RDF::Query}.
  • {RDF::Util::File.open_file} now performs redirects and manages base_uri based on W3C recommendations:
    • base_uri is set to the original URI if a status 303 is provided, otherwise any other redirect will set base_uri to the redirected location.
    • base_uri is set to the content of the Location header if status is success.
  • Additionally, {RDF::Util::File.open_file} sets the result encoding from charset if provided, defaulting to UTF-8. Other access methods include last_modified and content_type,
  • {RDF::StrictVocabulary} added with an easy way to keep vocabulary definitions up to date based on their OWL or RDFS definitions. Most vocabularies are now StrictVocabularies meaning that an attempt to resolve a particular term in that vocabulary will error if the term is not defined in the vocabulary.
  • New vocabulary definitions have been added for ICal, Media Annotations (MA), Facebook OpenGraph (OG), PROV, SKOS-XL (SKOSXL), Data Vocabulary (V), VCard, VOID, Powder-S (WDRS), and XHV.

Notably, {RDF::Queryable#query} and {RDF::Query#execute} are now completely symmetric; this allows an implementation of {RDF::Queryable} to optimize queries using implementation-specific logic, allowing for substantial performance improvements when executing BGP queries.

Differences between RDF 1.1 and RDF 1.2

  • {RDF::Literal} has an optional direction property for directional language-tagged strings.
  • Removes support for legacy text/plain (as an alias for application/n-triples) and text/x-nquads (as an alias for application/n-quads)

Tutorials

Command Line

When installed, RDF.rb includes a rdf shell script which acts as a wrapper to perform a number of different operations on RDF files using available readers and writers.

  • count: Parse and RDF input and count the number of statements.
  • predicates: Returns unique objects from parsed input.
  • objects: Returns unique objects from parsed input.
  • serialize: Parse an RDF input and re-serializing to [N
View on GitHub
GitHub Stars394
CategoryDevelopment
Updated3d ago
Forks97

Languages

Ruby

Security Score

100/100

Audited on Apr 2, 2026

No findings