Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

TriG reader/writer for RDF.rb

branch: develop

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 etc
Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 script
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 .yardopts
Octocat-spinner-32 AUTHORS
Octocat-spinner-32 Gemfile
Octocat-spinner-32 History
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 UNLICENSE
Octocat-spinner-32 VERSION
Octocat-spinner-32 rdf-trig.gemspec

RDF::TriG reader/writer

TriG reader/writer for RDF.rb .

Gem Version Build Status


This is a Ruby implementation of a TriG reader and writer for RDF.rb.


RDF::TriG parses TriG into statements or quads. It also serializes to TriG.

Install with gem install rdf-trig

  • 100% free and unencumbered public domain software.
  • Implements a complete parser and serializer for TriG.
  • Compatible with Ruby 1.8.7+, Ruby 1.9.x, and JRuby 1.7+.
  • Optional streaming writer, to serialize large graphs


Instantiate a reader from a local file:

repo = RDF::Repository.load("etc/doap.trig", :format => :trig)

Define @base and @prefix definitions, and use for serialization using :base_uri an :prefixes options.

Canonicalize and validate using :canonicalize and :validate options.

Write a repository to a file:"etc/test.trig") do |writer|
   writer << repo

Note that reading and writing of graphs is also possible, but as graphs have only a single context, it is not particularly interesting for TriG.


Full documentation available on

Principle Classes

  • {RDF::TriG::Format}
  • {RDF::TriG::Reader}
  • {RDF::TriG::Writer}

Implementation Notes

The reader uses the Turtle parser, which is based on the LL1::Parser with minor updates for the TriG grammar. The writer also is based on the Turtle writer.

The syntax is compatible with placing default triples within {}, but the writer does not use this for writing triples in the default graph.

There is a new :stream option to {RDF::TriG::Writer} which is more efficient for streaming large datasets.



The recommended installation method is via RubyGems. To install the latest official release of the RDF::TriG gem, do:

% [sudo] gem install rdf-trig

Mailing List



  • Do your best to adhere to the existing coding conventions and idioms.
  • Don't use hard tabs, and don't leave trailing whitespace on any line.
  • Do document every method you add using YARD annotations. Read the tutorial or just look at the existing code for examples.
  • Don't touch the .gemspec, VERSION or AUTHORS files. If you need to change them, do so on your private branch only.
  • Do feel free to add yourself to the CREDITS file and the corresponding list in the the README. Alphabetical order applies.
  • Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit public domain dedication on record from you.


This is free and unencumbered public domain software. For more information, see or the accompanying {file:UNLICENSE} file.

A copy of the TriG EBNF and derived parser files are included in the repository, which are not covered under the UNLICENSE. These files are covered via the W3C Document License.

Something went wrong with that request. Please try again.