Jena Ruby Setup: Mac OS X

JRuby

The JRuby Downloads page offers various forms and versions of JRuby. Unless you're interested in modifying JRuby, all you need is the "JRuby x.y.z Binary .jar". See http://jruby.org/getting-started for a quick rundown on how to use it.

The following notes and code are based on my local configuration, so you will have to make appropriate accommodations. After installing JRuby, I set up a nearby jena_hax directory:

.../
  jena_hax/
    jena.rb
    jenabean-1.0.5.jar
    js.rb
    rj
    song.owl
  jruby-1.4.0/

Downloads, etc.

You'll need to download a few files and store them in jena_hax.

  • jena.rb

    jena.rb is a small (~200 line) library that provides Ruby bindings to Jena.

  • jenabean

    jenabean uses Jena's flexible RDF/OWL API to persist Java beans.

Here are some helper scripts I wrote. Save them as files in jena_hax, then adjust the path and file names appropriately.

Here's rj, used to start up jirb (JRuby's version of Interactive Ruby):

:
# rj - run jirb
#
# Set up PATH, then run jirb with a simple prompt.

PATH="$PATH:$HOME/.../jruby-1.4.0/bin"
jirb --simple-prompt

Here's js.rb. We'll use this in jirb to bring in jarfiles, etc:

# js.rb - jena startup code

home  = ENV['HOME']
jlib  = "#{home}/...ARQ or Jena directory.../lib"
patt  = "#{jlib}/*.jar"
files = Dir.glob(patt) + %w[ jenabean-1.0.5.jar jena.rb ]
files.each {|file| require file } 

Finally, make rj executable and grab a copy of song.owl:

% chmod +x rj
% curl http://jena.s3.amazonaws.com/ruby/song.owl > song.owl

Trial Run

OK; let's make sure that things are working:

% rj
>> require 'js'
=> true
>> m = Jena.create_model
=> #<Java::ComHpHplJenaOntologyImpl::OntModelImpl:0x6e8e76>
>> m.write(System.out)
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:owl="http://www.w3.org/2002/07/owl#" > 
</rdf:RDF>
=> #<Java::ComHpHplJenaRdfModelImpl::ModelCom:0xc93cf5>

If that worked, you can wander off to some Jena_Ruby_Hacks. If not, get in touch and we'll try to figure out what went wrong.


This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r3 - 02 Jul 2011, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email