Giter Club home page Giter Club logo

rdf-turtle's Introduction

RDF::Turtle reader/writer Build Status

Turtle reader/writer for RDF.rb .

Description

This is a Ruby implementation of a Turtle parser for RDF.rb.

Features

RDF::Turtle parses Turtle and N-Triples into statements or triples. It also serializes to Turtle.

Install with gem install rdf-turtle

  • 100% free and unencumbered public domain software.
  • Implements a complete parser for Turtle.
  • Compatible with Ruby 1.8.7+, Ruby >= 1.9, and JRuby 1.7+.

Usage

Instantiate a reader from a local file:

graph = RDF::Graph.load("etc/doap.ttl", :format => :ttl)

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 graph to a file:

RDF::Turtle::Writer.open("etc/test.ttl") do |writer|
   writer << graph
end

Documentation

Full documentation available on Rubydoc.info

Principle Classes

  • {RDF::Turtle::Format}
    • {RDF::Turtle::TTL} Asserts :ttl format, text/turtle mime-type and .ttl file extension.
  • {RDF::Turtle::Reader}
  • {RDF::Turtle::Writer}

Variations from the spec

In some cases, the specification is unclear on certain issues:

  • For the time being, plain literals are generated without an xsd:string datatype, but literals with an xsd:string datatype are saved as non-datatyped triples in the graph. This will be updated in the future when the rest of the library suite is brought up to date with RDF 1.1.

Freebase-specific Reader

There is a special reader useful for processing Freebase Dumps. To invoke this, add the :freebase => true option to the {RDF::Turtle::Reader.new}, or use {RDF::Turtle::FreebaseReader} directly. As with {RDF::Turtle::Reader}, prefix definitions may be passed in using the :prefixes option to {RDF::Turtle::FreebaseReader#initialize} using the standard mechanism defined for RDF::Reader.

The Freebase Dumps have a very normalized form, similar to N-Triples but with prefixes. They also have a large amount of garbage. This Reader is optimized for this format and will perform faster error recovery.

An example of reading Freebase dumps:

require "rdf/turtle"
fb = "../freebase/freebase-rdf-2013-03-03-00-00.ttl"
fb_prefixes = {
  :ns => "http://rdf.freebase.com/ns/",
  :key => "http://rdf.freebase.com/key/",
  :owl => "http://www.w3.org/2002/07/owl#>",
  :rdfs => "http://www.w3.org/2000/01/rdf-schema#",
  :rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
  :xsd => "http://www.w3.org/2001/XMLSchema#"
}
RDF::Turtle::Reader.open(fb,
  :freebase => true,
  :prefixes => fb_prefixes) do |r|

  r.each_statement {|stmt| puts stmt.to_ntriples}
end

Implementation Notes

The reader uses the EBNF gem to generate first, follow and branch tables, and uses the Parser and Lexer modules to implement the Turtle parser.

The parser takes branch and follow tables generated from the original Turtle EBNF Grammar described in the specification. Branch and Follow tables are specified in {RDF::Turtle::Meta}, which is in turn generated using the EBNF gem.

Dependencies

Installation

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

% [sudo] gem install rdf-turtle

Mailing List

Author

Contributing

  • 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.

License

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

rdf-turtle's People

Contributors

gkellogg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.