rdf-virtuoso 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,7 +5,10 @@ The intent of this class is to act as an abstraction for clients wishing to conn
5
5
  RDF::Virtuoso::Repository builds on RDF.rb and is the main connection class built on top of APISmith to establish the read and write methods to a Virtuoso store SPARQL endpoint.
6
6
  RDF::Virtuoso::Query extends RDF::Query and adds SPARQL 1.1. update methods (insert, delete, aggregates, etc.).
7
7
 
8
- For examples on use, see ./spec/client_spec.rb and ./spec/query_spec.rb
8
+ For examples on use, please read:
9
+ ./spec/client_spec.rb
10
+ and
11
+ ./spec/query_spec.rb
9
12
 
10
13
  ### A simple example
11
14
 
@@ -29,12 +32,31 @@ This example assumes you have a local installation of Virtoso running at standar
29
32
 
30
33
  #### A count query example
31
34
 
32
- QUERY = RDF::Virtuoso::Query
33
- graph = RDF::URI.new("http://test.com")
34
- type = RDF::BIBO.Document
35
+ New prefixes can either extend the RDF::Vocabulary class (best if you want to model yourself:
36
+
37
+ module RDF
38
+ class FOO < RDF::Vocabulary("http://purl.org/ontology/foo/");end
39
+ end
40
+
41
+ it can then be easily accessed by RDF::FOO, eg.
42
+
43
+ RDF::FOO.Document
35
44
 
36
- count = REPO.select.where(:s, type, :o).count(:s).graph(graph)
45
+ or you can use the RDF::Virtuoso::Prefixes class in a query:
46
+
47
+ prefixes = RDF::Virtuoso::Prefixes.new foo: "http://purl.org/ontology/foo/", bar: "http://bar.net"
48
+
49
+ QUERY = RDF::Virtuoso::Query
50
+ graph = RDF::URI.new("http://test.com")
51
+ type = RDF::FOO.Document
52
+
53
+ query = QUERY.select.where([:s, type, :o]).count(:s).prefixes(prefixes).graph(graph)
54
+ result = REPO.select(query)
37
55
 
56
+ Results will be an array of RDF::Query::Solution that can be accessed by bindings or iterated
57
+
58
+ count = result.first[:count].to_i
59
+
38
60
  ## Rails specifics
39
61
  Working on a prototype Rails application for negotiating and manipulating linked data in an RDF store, I discovered the lack of a reasonably current library to bridge the gap between the fairly well-established, modular RDF.rb library and a Rails 3 application. I wanted to be able to manipulate RDF data in a convenient, ActiveRecord/ActiveModel way. It turned out to be fairly non-trivial to mimic true AR/AM behavior and this is more or less the groundwork and result of my experimentation. I now have a much better idea of how to proceed, I just need the time to really go deep into this.
40
62
  An example prototype that exercises this library can be found here: https://github.com/digibib/booky
@@ -1,5 +1,6 @@
1
1
  require 'api_smith'
2
2
  require 'rdf'
3
+ require 'uri'
3
4
 
4
5
  module RDF
5
6
  module Virtuoso
@@ -22,14 +23,20 @@ module RDF
22
23
  #persistent
23
24
  maintain_method_across_redirects true
24
25
 
25
- attr_reader :username, :password, :uri, :auth_method
26
+ attr_reader :uri, :update_uri, :username, :password, :auth_method
26
27
 
27
28
  def initialize(uri, opts={})
28
- self.class.base_uri uri
29
- @uri = uri
30
- @username = opts[:username] ||= nil
31
- @password = opts[:password] ||= nil
32
- @auth_method = opts[:auth_method] ||= 'digest'
29
+ @uri = URI.parse(uri)
30
+ @update_uri = URI.parse(opts[:update_uri]) if opts[:update_uri]
31
+ @base_uri = "#{@uri.scheme}://#{@uri.host}"
32
+ @base_uri += ":" + @uri.port.to_s if @uri.port
33
+ @username = opts[:username] || nil
34
+ @password = opts[:password] || nil
35
+ @auth_method = opts[:auth_method] || 'digest'
36
+
37
+ @sparql_endpoint = @uri.request_uri
38
+ @sparul_endpoint = @update_uri.nil? ? @sparql_endpoint : @update_uri.request_uri
39
+ self.class.base_uri @base_uri
33
40
  end
34
41
 
35
42
  READ_METHODS = %w(select ask construct describe)
@@ -86,13 +93,13 @@ module RDF
86
93
  end
87
94
 
88
95
  def api_get(query, options = {})
89
- self.class.endpoint 'sparql'
96
+ self.class.endpoint @sparql_endpoint
90
97
  get '/', :extra_query => { :query => query }.merge(options),
91
98
  :transform => RDF::Virtuoso::Parser::JSON
92
99
  end
93
100
 
94
101
  def api_post(query, options = {})
95
- self.class.endpoint 'sparql-auth'
102
+ self.class.endpoint @sparul_endpoint
96
103
  post '/', :extra_body => { :query => query }.merge(options),
97
104
  :extra_request => extra_request_options,
98
105
  :response_container => [
@@ -1,5 +1,5 @@
1
1
  module RDF
2
2
  module Virtuoso
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
@@ -2,20 +2,31 @@ require_relative '../lib/rdf/virtuoso/repository'
2
2
  describe RDF::Virtuoso do
3
3
 
4
4
  before(:each) do
5
- @uri = "http://localhost:8890"
5
+ @uri = "http://localhost:8890/sparql"
6
+ @update_uri = "http://localhost:8890/sparql-auth"
6
7
  end
7
8
 
8
9
  context "when connecting to a Virtuoso server" do
9
10
  it "should support connecting to a Virtuoso SPARQL endpoint" do
10
- RDF::Virtuoso::Repository.new(@uri)
11
+ repo = RDF::Virtuoso::Repository.new(@uri)
12
+ p repo
13
+
14
+ repo.instance_variable_get("@sparul_endpoint").should == "/sparql"
11
15
  end
12
-
16
+
17
+ it "should support accept port in repository endpoint" do
18
+ repo = RDF::Virtuoso::Repository.new(@uri)
19
+ repo.instance_variable_get("@base_uri").should == "http://localhost:8890"
20
+ end
21
+
13
22
  it "should support connecting to a Virtuoso SPARUL endpoint with BASIC AUTH" do
14
- RDF::Virtuoso::Repository.new(@uri, :username => 'admin', :password => 'secret', :auth_method => 'basic')
23
+ repo = RDF::Virtuoso::Repository.new(@uri, :update_uri => @update_uri, :username => 'admin', :password => 'secret', :auth_method => 'basic')
24
+ repo.instance_variable_get("@auth_method").should == "basic"
15
25
  end
16
26
 
17
27
  it "should support connecting to a Virtuoso SPARUL endpoint with DIGEST AUTH" do
18
- RDF::Virtuoso::Repository.new(@uri, :username => 'admin', :password => 'secret', :auth_method => 'digest')
28
+ repo = RDF::Virtuoso::Repository.new(@uri, :update_uri => @update_uri, :username => 'admin', :password => 'secret', :auth_method => 'digest')
29
+ repo.instance_variable_get("@sparul_endpoint").should == "/sparql-auth"
19
30
  end
20
31
  end
21
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-virtuoso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-12 00:00:00.000000000 Z
13
+ date: 2012-08-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec