OWLIM client library for Ruby
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
README.rdoc
gemspec.rb

README.rdoc

OWLIM-RUBY

This is a Semantic Web program which provides a front-end library and a command line tool for using the OWLIM (www.ontotext.com/owlim) triple store with ease. You need a remote or local OWLIM installation.

Install

gem install owlim-ruby

Usage as a command

owlim command [repository [arguments]]

Environmental variable

Specify your OWLIM server by the environmental variable 'SESAME_URL'. Default is “localhost:8080/openrdf-sesame”.

for B shell:

export SESAME_URL="http://example.org/openrdf-sesame"

for C shell:

setenv SESAME_URL "http://example.org/openrdf-sesame"

Info commands

Show the Sesame OWLIM server URI in use.

owlim host

Show list of repositories.

owlim list

Show number of triples in a repository.

owlim size repository

CRUD commands

Create a new repository.

owlim create repository

Import a RDF file to a repository.

owlim import repository file [format]

Export contents of a repository in RDF (default is RDF/XML).

owlim export repository [format]

Clear the contents of a repository.

owlim clear repository

Drop a repository.

owlim drop repository

Valid formats for import and export

  • RDF/XML: “rdf” or “rdfxml”

  • Turtle: “ttl” or “turtle”

  • N3: “n3”

  • N-Triples: “nt”

  • TriX: “trix”

  • TriG: “trig”

  • Bionary RDF: “rdfbin”

If not specified, format will be guessed from the file name suffix for import.

Query commands

Show a list of pre-defined prefixes

owlim prefix

SPARQL query against a repository without pre-defined prefixes

owlim query repository "SPARQL" [format]

SPARQL query against a repository including pre-defined prefixes

owlim q repository "SPARQL" [format]

Search for literal objects by a keyword.

owlim find repository "keyword" [format]

Peek the triples in the store.

owlim head repository [limit [offset [format]]]

Results will be printed in a tabular text format by default.

Available alternative formats

  • “json” for “application/sparql-result+json”

  • “xml” for “application/sparql-result+xml”.

Help

owlim help

Examples

owlim host
owlim list

owlim create hoge
owlim import hoge ../hoge.ttl
owlim export hoge > hoge.rdf
owlim size   hoge
owlim clear  hoge
owlim drop   hoge

owlim prefix

owlim q      hoge 'select * where { ?s ?p ?o . } limit 1000'
owlim q      hoge 'select * where { ?s ?p ?o . } limit 1000' json
owlim q      hoge 'select * where { ?s ?p ?o . } limit 1000' xml

owlim query  hoge 'select * where { ?s ?p ?o . } limit 1000'
owlim query  hoge 'select * where { ?s ?p ?o . } limit 1000' json
owlim query  hoge 'select * where { ?s ?p ?o . } limit 1000' xml

owlim find   hoge "fuga"
owlim find   hoge "fuga" json
owlim find   hoge "fuga" xml

owlim head   hoge
owlim head   hoge 10
owlim head   hoge 10 50 
owlim head   hoge 10 50 json
owlim head   hoge 10 50 xml

Usage as a library

Enable this library.

require 'rubygems'
require 'owlim'

Create a server object. Argument is a URI of the OWLIM endpoint.

uri = "http://localhost:8080/openrdf-sesame"
owlim = OWLIM.new(uri)

Show the endpoint URI.

puts owlim.host

Show all repositories.

puts owlim.list

Show the size of a given repository.

puts owlim.size(repository)

Create new repository.

owlim.create(repository)

Import a RDF file into a repository.

owlim.import(repository, rdf_file)
owlim.import(repository, rdf_file, :format => "turtle")

The file format is automatically guessed by the suffix of a given file name. To specify the format, use :format => format option. Available formats are described in the “Valid formats for import and export” section above.

Export triples from a repository.

owlim.export(repository)
owlim.export(repository, :format => "turtle")

Clear a repository.

owlim.clear(repository)

Drop a repository.

owlim.drop(repository)

SPARQL query to a repository.

owlim.query(repository, sparql) {|x| print x}
  or
result = owlim.query(repository, sparql)

Use :format => “xml” option to retrieve results in the SPARQL Query Results XML Format (www.w3.org/TR/rdf-sparql-XMLres/; “application/sparql-results+xml”) and use :format => “json” to retrieve in the JSON (www.w3.org/2001/sw/DataAccess/json-sparql/; “application/sparql-results+json”) format.

owlim.query(repository, sparql, :format => "xml") {|x| print x}
owlim.query(repository, sparql, :format => "json") {|x| print x}
  or
result = owlim.query(repository, sparql, :format => "xml")
result = owlim.query(repository, sparql, :format => "json")

Search for a triple which has a keyword as a literal in its object and finds all relevant triples sharing the same subject.

owlim.find(repository, keyword) {|x| print x}
  or
result owlim.find(repository, keyword)

Peak the triples in the store. By default, OWLIM adds 62 triples to the empty repository when created, so offset + 61 is used internally.

opts = {:limit => 50, :offset => 100, :format => "json"}
owlim.head(repository, opts) {|x| print x}
  or
result = owlim.head(repository, opts)

With a :format option and a block, the search results will be immediately sent in a stream for “query”, “find” and “head” methods. In other cases, results are buffred and will not be returened until the search is completed.

Show formatted SPARQL prefixes.

puts owlim.prefix

Access current SPARQL prefixes.

owlim.prefix_hash.each {|pfx, uri| puts "PREFIX #{pfx}: <#{uri}>"}

Add a SPARQL prefix.

owlim.prefix_hash["vcard"] = "http://www.w3.org/2006/vcard/ns#"

Delete a SPARQL prefix.

owlim.prefix_hash.delete("skos")

Authors

  • Toshiaki Katayama (DBCLS; ktym@dbcls.jp)

  • Tatsuya Nishizawa (IMSBIO)

License

This program is free software. You can redistribute it and/or modify it under the same terms as Ruby itself.