rdf-virtuoso 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # rdf-virtuoso: Ruby Virtuoso adapter for RDF.rb
2
+
2
3
  The intent of this class is to act as an abstraction for clients wishing to connect and manipulate linked data stored in a Virtuoso Quad store.
3
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/rdf-virtuoso.png)](https://badge.fury.io/rb/rdf-virtuoso)
6
+ [![Build Status](https://github.com/ruby-rdf/rdf-virtuoso/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf-virtuoso/actions?query=workflow%3ACI)
7
+ [![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
8
+
4
9
  ## How?
5
10
  RDF::Virtuoso::Repository subclasses RDF::Repository built 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
11
  RDF::Virtuoso::Query subclasses RDF::Query and adds SPARQL 1.1. update methods (insert, delete, aggregates, etc.).
@@ -19,10 +24,10 @@ This example assumes you have a local installation of Virtoso running at standar
19
24
  uri = "http://localhost:8890/sparql"
20
25
  update_uri = "http://localhost:8890/sparql-auth"
21
26
  repo = RDF::Virtuoso::Repository.new(uri,
22
- :update_uri => update_uri,
23
- :username => 'admin',
24
- :password => 'secret',
25
- :auth_method => 'digest')
27
+ update_uri: update_uri,
28
+ username: 'admin',
29
+ password: 'secret',
30
+ auth_method: 'digest')
26
31
 
27
32
  :auth_method can be 'digest' or 'basic'. a repository connection without auth requires only uri
28
33
 
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.7
@@ -1,8 +1,11 @@
1
+ require 'rdf'
2
+
1
3
  module RDF
2
4
  module Virtuoso
3
5
  autoload :Repository, 'rdf/virtuoso/repository'
4
6
  autoload :Query, 'rdf/virtuoso/query'
5
7
  autoload :Prefixes, 'rdf/virtuoso/prefixes'
6
8
  autoload :Parser, 'rdf/virtuoso/parser'
9
+ autoload :VERSION, 'rdf/virtuoso/version'
7
10
  end
8
11
  end
@@ -29,9 +29,9 @@ module RDF
29
29
  when :uri
30
30
  RDF::URI.new(value['value'])
31
31
  when :literal
32
- RDF::Literal.new(value['value'], :language => value['xml:lang'])
32
+ RDF::Literal.new(value['value'], language: value['xml:lang'])
33
33
  when :'typed-literal'
34
- RDF::Literal.new(value['value'], :datatype => value['datatype'])
34
+ RDF::Literal.new(value['value'], datatype: value['datatype'])
35
35
  else nil
36
36
  end
37
37
  end
@@ -414,7 +414,7 @@ module RDF::Virtuoso
414
414
  ##
415
415
  # @private
416
416
  # make RDF::Query::Pattern from triple array if not already done
417
- # include :context in Statement
417
+ # include :graph_name in Statement
418
418
  # @return [RDF::Query::Pattern]
419
419
  def build_patterns(patterns)
420
420
  patterns.map do |pattern|
@@ -603,10 +603,10 @@ module RDF::Virtuoso
603
603
  buffer << '{' if options[:unions]
604
604
 
605
605
  # iterate patterns
606
- # does patterns have :context hash? build with GRAPH statement
606
+ # does patterns have :graph_name hash? build with GRAPH statement
607
607
  patterns.each do | pattern|
608
- if pattern.context
609
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
608
+ if pattern.graph_name
609
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
610
610
  buffer << '{'
611
611
  buffer << serialize_patterns(pattern)
612
612
  buffer << '}'
@@ -620,8 +620,8 @@ module RDF::Virtuoso
620
620
  buffer << 'OPTIONAL {'
621
621
 
622
622
  patterns.each do | pattern|
623
- if pattern.context
624
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
623
+ if pattern.graph_name
624
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
625
625
  buffer << '{'
626
626
  buffer << serialize_patterns(pattern)
627
627
  buffer << '}'
@@ -639,8 +639,8 @@ module RDF::Virtuoso
639
639
  buffer << 'MINUS {'
640
640
 
641
641
  patterns.each do | pattern|
642
- if pattern.context
643
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
642
+ if pattern.graph_name
643
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
644
644
  buffer << '{'
645
645
  buffer << serialize_patterns(pattern)
646
646
  buffer << '}'
@@ -73,24 +73,24 @@ module RDF
73
73
  end
74
74
 
75
75
  def base_query_options
76
- { :format => RESULT_JSON }
76
+ { format: RESULT_JSON }
77
77
  end
78
78
 
79
79
  def base_request_options
80
- { :headers => headers }
80
+ { headers: headers }
81
81
  end
82
82
 
83
83
  def extra_request_options
84
84
  case @auth_method
85
85
  when 'basic'
86
- { :basic_auth => auth }
86
+ { basic_auth: auth }
87
87
  when 'digest'
88
- { :digest_auth => auth }
88
+ { digest_auth: auth }
89
89
  end
90
90
  end
91
91
 
92
92
  def auth
93
- { :username => @username, :password => @password }
93
+ { username: @username, password: @password }
94
94
  end
95
95
 
96
96
  def api_get(query, options = {})
@@ -98,16 +98,16 @@ module RDF
98
98
  if @sparul_endpoint
99
99
  self.class.endpoint @sparul_endpoint
100
100
  Timeout::timeout(@timeout) {
101
- get '/', :extra_query => { :query => query }.merge(options),
102
- :extra_request => extra_request_options,
103
- :transform => RDF::Virtuoso::Parser::JSON
101
+ get '/', extra_query: { query: query }.merge(options),
102
+ extra_request: extra_request_options,
103
+ transform: RDF::Virtuoso::Parser::JSON
104
104
  }
105
105
  else
106
106
  self.class.endpoint @sparql_endpoint
107
107
  Timeout::timeout(@timeout) {
108
108
  puts self.inspect
109
- get '/', :extra_query => { :query => query }.merge(options),
110
- :transform => RDF::Virtuoso::Parser::JSON
109
+ get '/', extra_query: { query: query }.merge(options),
110
+ transform: RDF::Virtuoso::Parser::JSON
111
111
  }
112
112
  end
113
113
  end
@@ -115,9 +115,9 @@ module RDF
115
115
  def api_post(query, options = {})
116
116
  self.class.endpoint @sparul_endpoint
117
117
  Timeout::timeout(@timeout) {
118
- post '/', :extra_body => { :query => query }.merge(options),
119
- :extra_request => extra_request_options,
120
- :response_container => [
118
+ post '/', extra_body: { query: query }.merge(options),
119
+ extra_request: extra_request_options,
120
+ response_container: [
121
121
  "results", "bindings", 0, "callret-0", "value"]
122
122
  }
123
123
  end
@@ -1,5 +1,18 @@
1
- module RDF
2
- module Virtuoso
3
- VERSION = "0.1.6"
4
- end
1
+ module RDF::Virtuoso::VERSION
2
+ VERSION_FILE = File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "VERSION")
3
+ MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chop.split(".")
4
+
5
+ STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
6
+
7
+ ##
8
+ # @return [String]
9
+ def self.to_s() STRING end
10
+
11
+ ##
12
+ # @return [String]
13
+ def self.to_str() STRING end
14
+
15
+ ##
16
+ # @return [Array(Integer, Integer, Integer)]
17
+ def self.to_a() STRING.split(".") end
5
18
  end
metadata CHANGED
@@ -1,97 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-virtuoso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
5
- prerelease:
4
+ version: 0.1.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Benjamin Rokseth
9
8
  - Peter Kordel
10
- autorequire:
9
+ autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-12-09 00:00:00.000000000 Z
12
+ date: 2021-01-07 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: rspec
15
+ name: rdf
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ~>
18
+ - - "~>"
21
19
  - !ruby/object:Gem::Version
22
- version: 2.14.1
23
- type: :development
20
+ version: '3.1'
21
+ type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ~>
25
+ - - "~>"
29
26
  - !ruby/object:Gem::Version
30
- version: 2.14.1
27
+ version: '3.1'
31
28
  - !ruby/object:Gem::Dependency
32
- name: rdf-spec
29
+ name: httparty
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ~>
32
+ - - "~>"
37
33
  - !ruby/object:Gem::Version
38
- version: 1.1.0
39
- type: :development
34
+ version: 0.18.1
35
+ type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ~>
39
+ - - "~>"
45
40
  - !ruby/object:Gem::Version
46
- version: 1.1.0
41
+ version: 0.18.1
47
42
  - !ruby/object:Gem::Dependency
48
- name: rdf
43
+ name: api_smith
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ~>
46
+ - - "~>"
53
47
  - !ruby/object:Gem::Version
54
- version: 1.1.0
48
+ version: 1.3.0
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ~>
53
+ - - "~>"
61
54
  - !ruby/object:Gem::Version
62
- version: 1.1.0
55
+ version: 1.3.0
63
56
  - !ruby/object:Gem::Dependency
64
- name: httparty
57
+ name: rspec
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ~>
60
+ - - "~>"
69
61
  - !ruby/object:Gem::Version
70
- version: 0.12.0
71
- type: :runtime
62
+ version: '3.10'
63
+ type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ~>
67
+ - - "~>"
77
68
  - !ruby/object:Gem::Version
78
- version: 0.12.0
69
+ version: '3.10'
79
70
  - !ruby/object:Gem::Dependency
80
- name: api_smith
71
+ name: rdf-spec
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ~>
74
+ - - "~>"
85
75
  - !ruby/object:Gem::Version
86
- version: 1.3.0
87
- type: :runtime
76
+ version: '3.1'
77
+ type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ~>
81
+ - - "~>"
93
82
  - !ruby/object:Gem::Version
94
- version: 1.3.0
83
+ version: '3.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdf-vocab
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.1'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.1'
95
98
  description: An RDF.rb extension library for interacting with a Virtuoso rdf store.\nSupports
96
99
  SPARQL 1.1 UPDATE extensions and some Virtuoso specific commands.
97
100
  email:
@@ -100,40 +103,36 @@ executables: []
100
103
  extensions: []
101
104
  extra_rdoc_files: []
102
105
  files:
106
+ - LICENSE
103
107
  - README.md
104
- - lib/rdf/virtuoso/query.rb
108
+ - VERSION
109
+ - lib/rdf/virtuoso.rb
110
+ - lib/rdf/virtuoso/parser.rb
105
111
  - lib/rdf/virtuoso/prefixes.rb
106
- - lib/rdf/virtuoso/version.rb
112
+ - lib/rdf/virtuoso/query.rb
107
113
  - lib/rdf/virtuoso/repository.rb
108
- - lib/rdf/virtuoso/parser.rb
109
- - lib/rdf/virtuoso.rb
110
- - spec/repository_spec.rb
111
- - spec/spec_helper.rb
112
- - spec/prefixes_spec.rb
113
- - spec/query_spec.rb
114
- homepage: https://github.com/digibib/rdf-virtuoso
114
+ - lib/rdf/virtuoso/version.rb
115
+ homepage: https://github.com/ruby-rdf/rdf-virtuoso
115
116
  licenses:
116
- - GPL-3
117
- post_install_message:
117
+ - GPL-3.0
118
+ metadata: {}
119
+ post_install_message:
118
120
  rdoc_options: []
119
121
  require_paths:
120
122
  - lib
121
123
  required_ruby_version: !ruby/object:Gem::Requirement
122
- none: false
123
124
  requirements:
124
- - - ! '>='
125
+ - - ">="
125
126
  - !ruby/object:Gem::Version
126
127
  version: '0'
127
128
  required_rubygems_version: !ruby/object:Gem::Requirement
128
- none: false
129
129
  requirements:
130
- - - ! '>='
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubyforge_project: rdf-virtuoso
135
- rubygems_version: 1.8.23
136
- signing_key:
137
- specification_version: 3
134
+ rubygems_version: 3.1.4
135
+ signing_key:
136
+ specification_version: 4
138
137
  summary: An RDF.rb extension library for interacting with a Virtuoso rdf store
139
138
  test_files: []
@@ -1,48 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
- require_relative '../lib/rdf/virtuoso/prefixes'
3
-
4
- describe RDF::Virtuoso::Prefixes do
5
- subject { RDF::Virtuoso::Prefixes.new(foo: 'bar', baz: 'quux') }
6
-
7
- it "takes a hash when initialized" do
8
- subject.should be_a RDF::Virtuoso::Prefixes
9
- end
10
-
11
- it "responds to to_a" do
12
- subject.should respond_to :to_a
13
- end
14
-
15
- it "returns a nice array" do
16
- subject.to_a.should == ["foo: <bar>", "baz: <quux>"]
17
- end
18
-
19
- it "presents itself nicely" do
20
- subject.to_s.should == "{:foo=>\"bar\", :baz=>\"quux\"}"
21
- end
22
-
23
- context "when creating prefixes" do
24
- let(:uris) { [RDF::DC.title.to_s, "http://example.org/foo/bar", "http://hash.org/foo#bar"] }
25
-
26
- it "creates prefixes from uris" do
27
- RDF::Virtuoso::Prefixes.parse(uris).should == [
28
- "purl: <http://purl.org/dc/terms/>",
29
- "example: <http://example.org/foo/>",
30
- "hash: <http://hash.org/foo#>"
31
- ]
32
- end
33
-
34
- it "only creates unique prefixes from uris" do
35
- uris << 'http://example.org/foo/baz'
36
- RDF::Virtuoso::Prefixes.parse(uris).should == [
37
- "purl: <http://purl.org/dc/terms/>",
38
- "example: <http://example.org/foo/>",
39
- "hash: <http://hash.org/foo#>"
40
- ]
41
- end
42
-
43
- it "returns an error object if a disallowed param is sent" do
44
- RDF::Virtuoso::Prefixes.parse({}).should be_a RDF::Virtuoso::UnProcessable
45
- end
46
-
47
- end
48
- end
@@ -1,384 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe RDF::Virtuoso::Query do
4
- before :each do
5
- @query = RDF::Virtuoso::Query
6
- end
7
-
8
- context "when building queries" do
9
- it "should support ASK queries" do
10
- @query.should respond_to(:ask)
11
- end
12
-
13
- it "should support SELECT queries" do
14
- @query.should respond_to(:select)
15
- end
16
-
17
- it "should support DESCRIBE queries" do
18
- @query.should respond_to(:describe)
19
- end
20
-
21
- it "should support CONSTRUCT queries" do
22
- @query.should respond_to(:construct)
23
- end
24
-
25
- it "should support INSERT DATA queries" do
26
- @query.should respond_to(:insert_data)
27
- end
28
-
29
- it "should support INSERT WHERE queries" do
30
- @query.should respond_to(:insert)
31
- end
32
-
33
- it "should support DELETE DATA queries" do
34
- @query.should respond_to(:delete_data)
35
- end
36
-
37
- it "should support DELETE WHERE queries" do
38
- @query.should respond_to(:delete)
39
- end
40
-
41
- it "should support CREATE GRAPH queries" do
42
- @query.should respond_to(:create)
43
- end
44
-
45
- end
46
-
47
- context "when building update queries" do
48
- before :each do
49
- @graph = "http://example.org/"
50
- @uri = RDF::Vocabulary.new "http://example.org/"
51
- end
52
- # TODO add support for advanced inserts (moving copying between different graphs)
53
- it "should support INSERT DATA queries" do
54
- @query.insert_data([@uri.ola, @uri.type, @uri.something]).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . }"
55
- @query.insert_data([@uri.ola, @uri.name, "two words"]).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <#{@graph}ola> <#{@graph}name> \"two words\" . }"
56
- end
57
-
58
- it "should support INSERT DATA queries with arrays" do
59
- @query.insert_data([@uri.ola, @uri.type, @uri.something],[@uri.ola, @uri.type, @uri.something_else]).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . <#{@graph}ola> <#{@graph}type> <#{@graph}something_else> . }"
60
- end
61
-
62
- it "should support INSERT DATA queries with RDF::Statements" do
63
- statements = [RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type')), RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type2'))]
64
- @query.insert_data(statements).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <http://test> <#{RDF.type}> <http://type> .\n <http://test> <#{RDF.type}> <http://type2> .\n }"
65
- end
66
-
67
- it "should support INSERT WHERE queries with symbols and patterns" do
68
- @query.insert([:s, :p, :o]).graph(RDF::URI.new(@graph)).where([:s, :p, :o]).to_s.should == "INSERT INTO GRAPH <#{@graph}> { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
69
- @query.insert([:s, @uri.newtype, :o]).graph(RDF::URI.new(@graph)).where([:s, @uri.type, :o]).to_s.should == "INSERT INTO GRAPH <#{@graph}> { ?s <#{@graph}newtype> ?o . } WHERE { ?s <#{@graph}type> ?o . }"
70
- end
71
-
72
- it "should support DELETE DATA queries" do
73
- @query.delete_data([@uri.ola, @uri.type, @uri.something]).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . }"
74
- @query.delete_data([@uri.ola, @uri.name, RDF::Literal.new("myname")]).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <#{@graph}ola> <#{@graph}name> \"myname\" . }"
75
- end
76
-
77
- it "should support DELETE DATA queries with arrays" do
78
- @query.delete_data([@uri.ola, @uri.type, @uri.something],[@uri.ola, @uri.type, @uri.something_else]).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . <#{@graph}ola> <#{@graph}type> <#{@graph}something_else> . }"
79
- end
80
-
81
- it "should support DELETE DATA queries with RDF::Statements" do
82
- statements = [RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type')), RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type2'))]
83
- @query.delete_data(statements).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <http://test> <#{RDF.type}> <http://type> .\n <http://test> <#{RDF.type}> <http://type2> .\n }"
84
- end
85
-
86
- it "should support DELETE DATA queries with appendable objects" do
87
- statements = []
88
- statements << RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type'))
89
- statements << RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type2'))
90
- @query.delete_data(statements).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <http://test> <#{RDF.type}> <http://type> .\n <http://test> <#{RDF.type}> <http://type2> .\n }"
91
- end
92
-
93
- it "should support DELETE WHERE queries with symbols and patterns" do
94
- @query.delete([:s, :p, :o]).graph(RDF::URI.new(@graph)).where([:s, :p, :o]).to_s.should == "DELETE FROM <#{@graph}> { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
95
- @query.delete([:s, @uri.newtype, :o]).graph(RDF::URI.new(@graph)).where([:s, @uri.newtype, :o]).to_s.should == "DELETE FROM <#{@graph}> { ?s <#{@graph}newtype> ?o . } WHERE { ?s <#{@graph}newtype> ?o . }"
96
- end
97
-
98
- it "should support CREATE GRAPH queries" do
99
- @query.create(RDF::URI.new(@graph)).to_s.should == "CREATE GRAPH <#{@graph}>"
100
- @query.create(RDF::URI.new(@graph), :silent => true).to_s.should == "CREATE SILENT GRAPH <#{@graph}>"
101
- end
102
-
103
- it "should support DROP GRAPH queries" do
104
- @query.drop(RDF::URI.new(@graph)).to_s.should == "DROP GRAPH <#{@graph}>"
105
- @query.drop(RDF::URI.new(@graph), :silent => true).to_s.should == "DROP SILENT GRAPH <#{@graph}>"
106
-
107
- end
108
-
109
- end
110
-
111
- context "when building ASK queries" do
112
- it "should support basic graph patterns" do
113
- @query.ask.where([:s, :p, :o]).to_s.should == "ASK WHERE { ?s ?p ?o . }"
114
- @query.ask.whether([:s, :p, :o]).to_s.should == "ASK WHERE { ?s ?p ?o . }"
115
- end
116
- end
117
-
118
- context "when building SELECT queries" do
119
- it "should support basic graph patterns" do
120
- @query.select.where([:s, :p, :o]).to_s.should == "SELECT * WHERE { ?s ?p ?o . }"
121
- end
122
-
123
- it "should support projection" do
124
- @query.select(:s).where([:s, :p, :o]).to_s.should == "SELECT ?s WHERE { ?s ?p ?o . }"
125
- @query.select(:s, :p).where([:s, :p, :o]).to_s.should == "SELECT ?s ?p WHERE { ?s ?p ?o . }"
126
- @query.select(:s, :p, :o).where([:s, :p, :o]).to_s.should == "SELECT ?s ?p ?o WHERE { ?s ?p ?o . }"
127
- end
128
-
129
- it "should support SELECT FROM" do
130
- @graph = RDF::URI("http://example.org/")
131
- @query.select(:s).where([:s, :p, :o]).from(@graph).to_s.should == "SELECT ?s FROM <#{@graph}> WHERE { ?s ?p ?o . }"
132
- end
133
-
134
- it "should support SELECT FROM and FROM NAMED" do
135
- @graph1 = RDF::URI("a")
136
- @graph2 = RDF::URI("b")
137
- @query.select(:s).where([:s, :p, :o, :context => @graph2]).from(@graph1).from_named(@graph2).to_s.should ==
138
- "SELECT ?s FROM <#{@graph1}> FROM NAMED <#{@graph2}> WHERE { GRAPH <#{@graph2}> { ?s ?p ?o . } }"
139
- end
140
-
141
- it "should support one SELECT FROM and multiple FROM NAMED" do
142
- @graph1 = RDF::URI("a")
143
- @graph2 = RDF::URI("b")
144
- @graph3 = RDF::URI("c")
145
- @query.select(:s).where([:s, :p, :o, :context => @graph2], [:s, :p, :o, :context => @graph3]).from(@graph1).from_named(@graph2).from_named(@graph3).to_s.should ==
146
- "SELECT ?s FROM <#{@graph1}> FROM NAMED <#{@graph2}> FROM NAMED <#{@graph3}> WHERE { GRAPH <#{@graph2}> { ?s ?p ?o . } GRAPH <#{@graph3}> { ?s ?p ?o . } }"
147
- end
148
-
149
- it "should support SELECT with complex WHERE patterns" do
150
- @query.select.where(
151
- [:s, :p, :o],
152
- [:s, RDF.type, RDF::DC.BibliographicResource]
153
- ).to_s.should ==
154
- "SELECT * WHERE { ?s ?p ?o . ?s <#{RDF.type}> <#{RDF::DC.BibliographicResource}> . }"
155
- end
156
-
157
- it "should support SELECT WHERE patterns from different GRAPH contexts" do
158
- @graph1 = "http://example1.org/"
159
- @graph2 = "http://example2.org/"
160
- @query.select.where([:s, :p, :o, :context => @graph1],[:s, RDF.type, RDF::DC.BibliographicResource, :context => @graph2]).to_s.should ==
161
- "SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.BibliographicResource}> . } }"
162
- end
163
-
164
- it "should support string objects in SPARQL queries" do
165
- @query.select.where([:s, :p, "dummyobject"]).to_s.should == "SELECT * WHERE { ?s ?p \"dummyobject\" . }"
166
- end
167
-
168
- #it "should support raw string SPARQL queries" do
169
- # q = "SELECT * WHERE { ?s <#{RDF.type}> ?o . }"
170
- # @query.query(q).should == "SELECT * WHERE { ?s <#{RDF.type}> ?o . }"
171
- #end
172
-
173
- it "should support FROM" do
174
- uri = "http://example.org/dft.ttl"
175
- @query.select.from(RDF::URI.new(uri)).where([:s, :p, :o]).to_s.should ==
176
- "SELECT * FROM <#{uri}> WHERE { ?s ?p ?o . }"
177
- end
178
-
179
- it "should support DISTINCT" do
180
- @query.select(:s, :distinct => true).where([:s, :p, :o]).to_s.should == "SELECT DISTINCT ?s WHERE { ?s ?p ?o . }"
181
- @query.select(:s).distinct.where([:s, :p, :o]).to_s.should == "SELECT DISTINCT ?s WHERE { ?s ?p ?o . }"
182
- end
183
-
184
- it "should support REDUCED" do
185
- @query.select(:s, :reduced => true).where([:s, :p, :o]).to_s.should == "SELECT REDUCED ?s WHERE { ?s ?p ?o . }"
186
- @query.select(:s).reduced.where([:s, :p, :o]).to_s.should == "SELECT REDUCED ?s WHERE { ?s ?p ?o . }"
187
- end
188
-
189
- it "should support aggregate COUNT" do
190
- @query.select.where([:s, :p, :o]).count(:s).to_s.should == "SELECT (COUNT (?s) AS ?s) WHERE { ?s ?p ?o . }"
191
- @query.select.count(:s).where([:s, :p, :o]).to_s.should == "SELECT (COUNT (?s) AS ?s) WHERE { ?s ?p ?o . }"
192
- end
193
-
194
- it "should support aggregates SUM, MIN, MAX, AVG, SAMPLE, GROUP_CONCAT, GROUP_DIGEST" do
195
- @query.select.where([:s, :p, :o]).sum(:s).to_s.should == "SELECT (SUM (?s) AS ?s) WHERE { ?s ?p ?o . }"
196
- @query.select.where([:s, :p, :o]).min(:s).to_s.should == "SELECT (MIN (?s) AS ?s) WHERE { ?s ?p ?o . }"
197
- @query.select.where([:s, :p, :o]).max(:s).to_s.should == "SELECT (MAX (?s) AS ?s) WHERE { ?s ?p ?o . }"
198
- @query.select.where([:s, :p, :o]).avg(:s).to_s.should == "SELECT (AVG (?s) AS ?s) WHERE { ?s ?p ?o . }"
199
- @query.select.where([:s, :p, :o]).sample(:s).to_s.should == "SELECT (sql:SAMPLE (?s) AS ?s) WHERE { ?s ?p ?o . }"
200
- @query.select.where([:s, :p, :o]).group_concat(:s, '_').to_s.should == "SELECT (sql:GROUP_CONCAT (?s, '_' ) AS ?s) WHERE { ?s ?p ?o . }"
201
- @query.select.where([:s, :p, :o]).group_digest(:s, '_', 1000, 1).to_s.should == "SELECT (sql:GROUP_DIGEST (?s, '_', 1000, 1 ) AS ?s) WHERE { ?s ?p ?o . }"
202
- end
203
-
204
- it "should support multiple instances of SAMPLE" do
205
- @query.select.where([:s, :p, :o]).sample(:s).sample(:p).to_s.should == "SELECT (sql:SAMPLE (?s) AS ?s) (sql:SAMPLE (?p) AS ?p) WHERE { ?s ?p ?o . }"
206
- end
207
-
208
- it "should support multiple instances of MIN/MAX/AVG/SUM" do
209
- @query.select.where([:s, :p, :o]).min(:s).min(:p).to_s.should == "SELECT (MIN (?s) AS ?s) (MIN (?p) AS ?p) WHERE { ?s ?p ?o . }"
210
- @query.select.where([:s, :p, :o]).max(:s).max(:p).to_s.should == "SELECT (MAX (?s) AS ?s) (MAX (?p) AS ?p) WHERE { ?s ?p ?o . }"
211
- @query.select.where([:s, :p, :o]).avg(:s).avg(:p).to_s.should == "SELECT (AVG (?s) AS ?s) (AVG (?p) AS ?p) WHERE { ?s ?p ?o . }"
212
- @query.select.where([:s, :p, :o]).sum(:s).sum(:p).to_s.should == "SELECT (SUM (?s) AS ?s) (SUM (?p) AS ?p) WHERE { ?s ?p ?o . }"
213
- end
214
-
215
- it "should support multiple instances of GROUP_CONCAT" do
216
- @query.select.where([:s, :p, :o]).group_concat(:s, '_').group_concat(:p, '-').to_s.should == "SELECT (sql:GROUP_CONCAT (?s, '_' ) AS ?s) (sql:GROUP_CONCAT (?p, '-' ) AS ?p) WHERE { ?s ?p ?o . }"
217
- end
218
-
219
- it "should support multiple instances of GROUP_DIGEST" do
220
- @query.select.where([:s, :p, :o]).group_digest(:s, '_', 1000, 1).group_digest(:p, '-', 1000, 1).to_s.should == "SELECT (sql:GROUP_DIGEST (?s, '_', 1000, 1 ) AS ?s) (sql:GROUP_DIGEST (?p, '-', 1000, 1 ) AS ?p) WHERE { ?s ?p ?o . }"
221
- end
222
-
223
- it "should support aggregates in addition to SELECT variables" do
224
- @query.select(:s).where([:s, :p, :o]).group_digest(:o, '_', 1000, 1).to_s.should == "SELECT (sql:GROUP_DIGEST (?o, '_', 1000, 1 ) AS ?o) ?s WHERE { ?s ?p ?o . }"
225
- end
226
-
227
- it "should support multiple instances of aggregates AND select variables" do
228
- @query.select(:s).where([:s, :p, :o]).sample(:p).sample(:o).to_s.should == "SELECT (sql:SAMPLE (?p) AS ?p) (sql:SAMPLE (?o) AS ?o) ?s WHERE { ?s ?p ?o . }"
229
- end
230
-
231
- it "should support ORDER BY" do
232
- @query.select.where([:s, :p, :o]).order_by(:o).to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o"
233
- @query.select.where([:s, :p, :o]).order_by('?o').to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o"
234
- # @query.select.where([:s, :p, :o]).order_by(:o => :asc).to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o ASC"
235
- @query.select.where([:s, :p, :o]).order_by('ASC(?o)').to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ASC(?o)"
236
- # @query.select.where([:s, :p, :o]).order_by(:o => :desc).to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o DESC"
237
- @query.select.where([:s, :p, :o]).order_by('DESC(?o)').to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY DESC(?o)"
238
- end
239
-
240
- it "should support OFFSET" do
241
- @query.select.where([:s, :p, :o]).offset(100).to_s.should == "SELECT * WHERE { ?s ?p ?o . } OFFSET 100"
242
- end
243
-
244
- it "should support LIMIT" do
245
- @query.select.where([:s, :p, :o]).limit(10).to_s.should == "SELECT * WHERE { ?s ?p ?o . } LIMIT 10"
246
- end
247
-
248
- it "should support OFFSET with LIMIT" do
249
- @query.select.where([:s, :p, :o]).offset(100).limit(10).to_s.should == "SELECT * WHERE { ?s ?p ?o . } OFFSET 100 LIMIT 10"
250
- @query.select.where([:s, :p, :o]).slice(100, 10).to_s.should == "SELECT * WHERE { ?s ?p ?o . } OFFSET 100 LIMIT 10"
251
- end
252
-
253
- # DEPRECATED - USE RDF::Vocabulary instead
254
- =begin
255
- it "should support PREFIX" do
256
- prefixes = ["dc: <http://purl.org/dc/elements/1.1/>", "foaf: <http://xmlns.com/foaf/0.1/>"]
257
- @query.select.prefix(prefixes[0]).prefix(prefixes[1]).where([:s, :p, :o]).to_s.should ==
258
- "PREFIX #{prefixes[0]} PREFIX #{prefixes[1]} SELECT * WHERE { ?s ?p ?o . }"
259
- end
260
-
261
- it "constructs PREFIXes" do
262
- prefixes = RDF::Virtuoso::Prefixes.new dc: RDF::DC, foaf: RDF::FOAF
263
- @query.select.prefixes(prefixes).where([:s, :p, :o]).to_s.should ==
264
- "PREFIX dc: <#{RDF::DC}> PREFIX foaf: <#{RDF::FOAF}> SELECT * WHERE { ?s ?p ?o . }"
265
- end
266
-
267
- it "should support custom PREFIXes in hash array" do
268
- prefixes = RDF::Virtuoso::Prefixes.new foo: "http://foo.com/", bar: "http://bar.net"
269
- @query.select.prefixes(prefixes).where([:s, :p, :o]).to_s.should ==
270
- "PREFIX foo: <http://foo.com/> PREFIX bar: <http://bar.net> SELECT * WHERE { ?s ?p ?o . }"
271
- end
272
-
273
- it "should support accessing custom PREFIXes in SELECT" do
274
- prefixes = RDF::Virtuoso::Prefixes.new foo: "http://foo.com/"
275
- @query.select.where(['foo:bar', :p, :o]).prefixes(prefixes).to_s.should ==
276
- "PREFIX foo: <http://foo.com/bar> SELECT * WHERE { ?s ?p ?o . }"
277
- end
278
- =end
279
-
280
- it "should support using custom RDF::Vocabulary prefixes" do
281
- BIBO = RDF::Vocabulary.new("http://purl.org/ontology/bibo/")
282
- @query.select.where([:s, :p, BIBO.Document]).to_s.should ==
283
- "SELECT * WHERE { ?s ?p <http://purl.org/ontology/bibo/Document> . }"
284
- end
285
-
286
- it "should support OPTIONAL" do
287
- @query.select.where([:s, :p, :o]).optional([:s, RDF.type, :o], [:s, RDF::DC.abstract, :o]).to_s.should ==
288
- "SELECT * WHERE { ?s ?p ?o . OPTIONAL { ?s <#{RDF.type}> ?o . ?s <#{RDF::DC.abstract}> ?o . } }"
289
- end
290
-
291
- it "should support OPTIONAL with GRAPH contexts" do
292
- @graph1 = "http://example1.org/"
293
- @graph2 = "http://example2.org/"
294
- @query.select.where([:s, :p, :o, :context => @graph1]).optional([:s, RDF.type, RDF::DC.BibliographicResource, :context => @graph2]).to_s.should ==
295
- "SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } OPTIONAL { GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.BibliographicResource}> . } } }"
296
- end
297
-
298
- it "should support multiple OPTIONALs" do
299
- @query.select.where([:s, :p, :o]).optional([:s, RDF.type, :o]).optional([:s, RDF::DC.abstract, :o]).to_s.should ==
300
- "SELECT * WHERE { ?s ?p ?o . OPTIONAL { ?s <#{RDF.type}> ?o . } OPTIONAL { ?s <#{RDF::DC.abstract}> ?o . } }"
301
- end
302
-
303
- it "should support MINUS, also with an array pattern" do
304
- @query.select.where([:s, :p, :o]).minus([:s, RDF.type, :o], [:s, RDF::DC.abstract, :o]).to_s.should ==
305
- "SELECT * WHERE { ?s ?p ?o . MINUS { ?s <#{RDF.type}> ?o . ?s <#{RDF::DC.abstract}> ?o . } }"
306
- end
307
-
308
- it "should support multiple MINUSes" do
309
- @query.select.where([:s, :p, :o]).minus([:s, RDF.type, :o]).minus([:s, RDF::DC.abstract, :o]).to_s.should ==
310
- "SELECT * WHERE { ?s ?p ?o . MINUS { ?s <#{RDF.type}> ?o . } MINUS { ?s <#{RDF::DC.abstract}> ?o . } }"
311
- end
312
-
313
- it "should support MINUS with a GRAPH context" do
314
- @graph1 = "http://example1.org/"
315
- @query.select.where([:s, :p, :o]).minus([:s, RDF.type, :o, :context => @graph1]).to_s.should ==
316
- "SELECT * WHERE { ?s ?p ?o . MINUS { GRAPH <#{@graph1}> { ?s <#{RDF.type}> ?o . } } }"
317
- end
318
-
319
- it "should support UNION" do
320
- @query.select.where([:s, RDF::DC.abstract, :o]).union([:s, RDF.type, :o]).to_s.should ==
321
- "SELECT * WHERE { { ?s <#{RDF::DC.abstract}> ?o . } UNION { ?s <#{RDF.type}> ?o . } }"
322
- end
323
-
324
- it "should support FILTER" do
325
- @query.select.where([:s, RDF::DC.abstract, :o]).filter('lang(?text) != "nb"').to_s.should ==
326
- "SELECT * WHERE { ?s <#{RDF::DC.abstract}> ?o . FILTER(lang(?text) != \"nb\") }"
327
- end
328
-
329
- it "should support multiple FILTERs" do
330
- filters = ['lang(?text) != "nb"', 'regex(?uri, "^https")']
331
- @query.select.where([:s, RDF::DC.abstract, :o]).filters(filters).to_s.should ==
332
- "SELECT * WHERE { ?s <#{RDF::DC.abstract}> ?o . FILTER(lang(?text) != \"nb\") FILTER(regex(?uri, \"^https\")) }"
333
- end
334
-
335
- it "should support DEFINE headers in queries" do
336
- define = 'sql:select-option "ORDER"'
337
- @query.select.where([:s, RDF::DC.abstract, :o]).define(define).to_s.should ==
338
- "DEFINE #{define} SELECT * WHERE { ?s <#{RDF::DC.abstract}> ?o . }"
339
- end
340
-
341
- it "should support grouping graph patterns within brackets" do
342
- @query.select.where.group([:s, :p, :o],[:s2, :p2, :o2]).
343
- where([:s3, :p3, :o3]).to_s.should ==
344
- "SELECT * WHERE { { ?s ?p ?o . ?s2 ?p2 ?o2 . } ?s3 ?p3 ?o3 . }"
345
- end
346
-
347
- it "should support grouping with several graph statements" do
348
- @query.select.where.graph2(RDF::URI.new("a")).group([:s, :p, :o],[:s2, :p2, :o2]).
349
- where.graph2(RDF::URI.new("b")).group([:s3, :p3, :o3]).to_s.should ==
350
- "SELECT * WHERE { GRAPH <a> { ?s ?p ?o . ?s2 ?p2 ?o2 . } GRAPH <b> { ?s3 ?p3 ?o3 . } }"
351
- end
352
-
353
- end
354
-
355
- context "when building DESCRIBE queries" do
356
- it "should support basic graph patterns" do
357
- @query.describe.where([:s, :p, :o]).to_s.should == "DESCRIBE * WHERE { ?s ?p ?o . }"
358
- end
359
-
360
- it "should support projection" do
361
- @query.describe(:s).where([:s, :p, :o]).to_s.should == "DESCRIBE ?s WHERE { ?s ?p ?o . }"
362
- @query.describe(:s, :p).where([:s, :p, :o]).to_s.should == "DESCRIBE ?s ?p WHERE { ?s ?p ?o . }"
363
- @query.describe(:s, :p, :o).where([:s, :p, :o]).to_s.should == "DESCRIBE ?s ?p ?o WHERE { ?s ?p ?o . }"
364
- end
365
-
366
- it "should support RDF::URI arguments" do
367
- uris = ['http://www.bbc.co.uk/programmes/b007stmh#programme', 'http://www.bbc.co.uk/programmes/b00lg2xb#programme']
368
- @query.describe(RDF::URI.new(uris[0]),RDF::URI.new(uris[1])).to_s.should ==
369
- "DESCRIBE <#{uris[0]}> <#{uris[1]}>"
370
- end
371
- end
372
-
373
- context "when building CONSTRUCT queries" do
374
- it "should support basic graph patterns" do
375
- @query.construct([:s, :p, :o]).where([:s, :p, :o]).to_s.should == "CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
376
- end
377
-
378
- it "should support complex constructs" do
379
- @query.construct([:s, :p, :o], [:s, :q, RDF::Literal.new("new")]).where([:s, :p, :o], [:s, :q, "old"]).to_s.should == "CONSTRUCT { ?s ?p ?o . ?s ?q \"new\" . } WHERE { ?s ?p ?o . ?s ?q \"old\" . }"
380
- end
381
-
382
-
383
- end
384
- end