Giter Club home page Giter Club logo

iq_rdf's Introduction

IqRdf - RDF Renderering for Ruby and Rails build status

IqRdf is a RDF renderer for Ruby and Rails. You can use it in any Ruby environment to render Trurtle-, N-Triple- (not implemented yet) or XML-RDF.

IqRdf underlays a Builder-like approach to specify the RDF-Data by using a internal Ruby DSL. The basic Idea for specifing a triple (subject, predicate, object) is that the predicate is a method call on the subject with the object as parameters:

IqRdf::some_subject.some_predicate(IqRdf::some_object)

The IqRdf namespaces are needed not to mess up the rest of your project due to the heavy use of method_missing in the IqRdf-Library. See the IqRdf::use method for Ruby 1.9 to omit the IqRdf:: prefix.

Ruby example

You can use IqRdf in pure Ruby to produce Strings in a certain RDF Syntax like Turtle or XML:

require 'IqRdf'
document = IqRdf::Document.new('http://www.test.de/')

document.namespaces :skos => 'http://www.w3.org/2008/05/skos#',
  :foaf => 'http://xmlns.com/foaf/0.1/', # A :rdf namespace is added automatically
  :sdmxdimension => {'sdmx-dimension' => 'http://purl.org/linked-data/sdmx/2009/measure#'} # alternative to define namespaces (e.g. if you want to use '-' inside prefix)

document << IqRdf::john_doe.myCustomNote("This is an example", :lang => :en)
# Turtle: :john_doe :myCustomNote "This is an example"@en.

document << IqRdf::john_doe(IqRdf::Foaf::build_uri("Person")).Foaf::name("John Doe")
# Turtle: :john_doe a foaf:Person; foaf:name "John Doe".

document << IqRdf::john_doe.Foaf::knows(IqRdf::jane_doe)
# Turtle: :john_doe foaf:knows :jane_doe.

document.to_turtle
# => "@prefix : <http://www.test.de/>. ..."

Rails example

Include IqRdf to your Ruby on Rails project by adding the following line to your Gemfile (or with Rails 2.x in your config/environment.rb):

gem "iq_rdf"

Add the mime types you want to support to your config/initializers/mime_types.rb file:

Mime::Type.register "application/rdf+xml", :rdf
Mime::Type.register "text/turtle", :ttl
Mime::Type.register "application/n-triples", :nt

Now you can define views in you application. Use the extension .iqrdf for the view files. You can use the extensions .ttl or .rdf in the URL of your request, to force the output to be in Turtle or XML/RDF.

Views

In your views IqRdf gives you a document object you can add your triples to. But first you will have to define your namespaces and the global language if you want to label all String literals in a certain language (as long as there is no other language or :none given).

document.namespaces :default => 'http://data.example.com/', :foaf => 'http://xmlns.com/foaf/0.1/'
document.lang = :en

document << IqRdf::test_subject.test_predicate("test")
# Turtle: :test_subject :test_predicate "test"@en.

document << IqRdf::test_subject.test_predicate("test", :lang => :de)
# Turtle: :test_subject :test_predicate "test"@de.

document << IqRdf::test_subject.test_predicate("test", :lang => :none)
# Turtle: :test_subject :test_predicate "test".

# ...

Use the namespace token :default to mark the default namespace. This has the same effect as specifing the default namespace in IqRdf::Document.new.

Complex RDF definitions

TODO

Copyright (c) 2011 innoQ Deutschland GmbH, released under the Apache License 2.0

iq_rdf's People

Contributors

fnd avatar mjansing avatar tillsc avatar youngbrioche 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.