Skip to content

markborkum/acts_as_statement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

acts_as_statement: an RDF.rb quad-store for Active Record

This is a pure-Ruby library for working with Resource Description Framework (RDF) data in Active Record-based applications.

Features

Examples

require 'active_record'
require 'acts_as_statement'

Define an ActiveRecord class to represent an RDF quad

class RdfStatement < ActiveRecord::Base
  acts_as_statement
end

Define the relational database schema for a quad-store

acts_as_statement uses an indexed, four-column, relational database schema.

The MD5 check-sum of the empty string "d41d8cd98f00b204e9800998ecf8427e" is used as a substitute for NULL.

class CreateRdfStatements < ActiveRecord::Migration
  def change
    create_table :rdf_statements do |t|
      t.timestamps
      
      # hexdigests
      t.string :s, :null => false, :limit => 32
      t.string :p, :null => false, :limit => 32
      t.string :o, :null => false, :limit => 32
      t.string :c, :null => false, :limit => 32
      
      # quad
      t.text :subject
      t.text :predicate
      t.text :object
      t.text :context
    end
    
    # triplestore indices
    add_index :rdf_statements, :s
    add_index :rdf_statements, :p
    add_index :rdf_statements, :o
    add_index :rdf_statements, [:s, :p]
    add_index :rdf_statements, [:s, :o]
    add_index :rdf_statements, [:p, :o]
    add_index :rdf_statements, [:s, :p, :o]
    
    # quadstore indices
    add_index :rdf_statements, :c
    add_index :rdf_statements, [:s, :c]
    add_index :rdf_statements, [:p, :c]
    add_index :rdf_statements, [:o, :c]
    add_index :rdf_statements, [:s, :p, :c]
    add_index :rdf_statements, [:s, :o, :c]
    add_index :rdf_statements, [:p, :o, :c]
    add_index :rdf_statements, [:s, :p, :o, :c], :unique => true
  end
end

Query the quad-store using Active Record query interface

acts_as_statement provides 7x scoped relations:

  • with_subject: all quads with the specified subject.
  • with_predicate: all quads with the specified predicate.
  • with_object: all quads with the specified object.
  • with_context: all quads with the specified context.
  • for_statement: all quads with the specified RDF::Statement.
  • for_triple: all quads with the specified [subject, predicate, object] tuple.
  • for_quad: all quads with the specified [subject, predicate, object, context] tuple.

Arguments to "with_*" relations have the following semantics:

  • RDF::URI: all quads with the specified URI.
  • RDF::Literal: all quads with the specified literal.
  • true: all quads with a non-NULL value for the column denoted by (*).
  • false: all quads with a NULL value for the column denoted by (*).
  • nil: all quads.
# find all quads with the specified subject and any context...
RdfStatement.with_context(nil).with_subject(RDF::URI.new('https://github.com/markborkum/acts_as_statement'))

Query the quad-store using RDF.rb query interface

acts_as_statement implements the RDF::Repository interface, so you can use any RDF.rb mechanism to query the quad-store.

query = RDF::Query.new({
  RDF::URI.new('https://github.com/markborkum/acts_as_statement') => {
    :predicate => :object,
  },
})

solutions = query.execute(RdfStatement.repository)

solutions.each do |solution|
  puts "predicate=#{solution[:predicate]} object=#{solution[:object]} (context=#{solution[:context]})"
end

Documentation

TODO

Dependencies

  • Ruby (>= 1.8.7) or (>= 1.8.1 with [Backports][])
  • RDF.rb (>= 0.3.4)

Installation

TODO

Download

To get a local working copy of the development repository, do:

% git clone git://github.com/markborkum/acts_as_statement.git

Alternatively, download the latest development version as a tarball as follows:

% wget https://github.com/markborkum/acts_as_statement/tarball/master

Resources

TODO

Mailing List

TODO

Authors

License

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

About

acts_as_statement: an RDF.rb quad-store for Active Record

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages