rdf-virtuoso 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 222f972acee18d8fad63ec6b94becb2e2445223e50d0acf316e699b7e2b94907
4
+ data.tar.gz: 020ff0b1c11585f10499276d44b34807543a456714fa9933f87634e26cd9d57c
5
+ SHA512:
6
+ metadata.gz: 75ebb9442251821a9ca108471de85da3b7f24d3b447ebc7502052da32f31fe74e424cd054883ff76ed3fb5b09d3d882f3c18dbdf647fafc30b5ede72cea6ce37
7
+ data.tar.gz: 88fbf45edf0705530d76b935db348131e5c9beb3656bf7fe22837b6af47fd4d99ae0804e677c1eb8655b54e5aeec7fd9807bc96fafcbded938bbfc07334bbe0f
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org/>
data/README.md CHANGED
@@ -1,9 +1,14 @@
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
- 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
- RDF::Virtuoso::Query subclasses RDF::Query and adds SPARQL 1.1. update methods (insert, delete, aggregates, etc.).
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.
11
+ `RDF::Virtuoso::Query` subclasses `RDF::Query` and adds SPARQL 1.1. update methods (insert, delete, aggregates, etc.).
7
12
 
8
13
  For examples on use, please read:
9
14
  ./spec/repository_spec.rb
@@ -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
 
@@ -64,3 +69,30 @@ or you can dynamically add RDF::Vocabulary objects
64
69
  Results will be an array of RDF::Query::Solution that can be accessed by bindings or iterated
65
70
 
66
71
  count = result.first[:count].to_i
72
+
73
+ ## Contributing
74
+
75
+ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
76
+
77
+ * Do your best to adhere to the existing coding conventions and idioms.
78
+ * Don't use hard tabs, and don't leave trailing whitespace on any line.
79
+ Before committing, run `git diff --check` to make sure of this.
80
+ * Do document every method you add using [YARD][] annotations. Read the
81
+ [tutorial][YARD-GS] or just look at the existing code for examples.
82
+ * Don't touch the `.gemspec` or `VERSION` files. If you need to change them,
83
+ do so on your private branch only.
84
+ * Do note that in order for us to merge any non-trivial changes (as a rule
85
+ of thumb, additions larger than about 15 lines of code), we need an
86
+ explicit [public domain dedication][PDD] on record from you,
87
+ which you will be asked to agree to on the first commit to a repo within the organization.
88
+ Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
89
+
90
+ ## License
91
+
92
+ This is free and unencumbered public domain software. For more information,
93
+ see <https://unlicense.org/> or the accompanying {file:LICENSE} file.
94
+
95
+ [PDD]: https://unlicense.org/#unlicensing-contributions
96
+ [YARD]: https://yardoc.org/
97
+ [YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
98
+ [RDF.rb]: https://rubydoc.info/github/ruby-rdf/rdf
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/lib/rdf/virtuoso.rb CHANGED
@@ -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
@@ -29,8 +29,8 @@ module RDF::Virtuoso
29
29
  # @param [Hash{Symbol => Object}] options
30
30
  # @return [Query]
31
31
  # @see http://www.w3.org/TR/rdf-sparql-query/#ask
32
- def self.ask(options = {})
33
- self.new(:ask, options)
32
+ def self.ask(**options)
33
+ self.new(:ask, **options)
34
34
  end
35
35
 
36
36
  ##
@@ -40,9 +40,8 @@ module RDF::Virtuoso
40
40
  # @param [Hash{Symbol => Object}] options
41
41
  # @return [Query]
42
42
  # @see http://www.w3.org/TR/rdf-sparql-query/#select
43
- def self.select(*variables)
44
- options = variables.last.is_a?(Hash) ? variables.pop : {}
45
- self.new(:select, options).select(*variables)
43
+ def self.select(*variables, **options)
44
+ self.new(:select, **options).select(*variables)
46
45
  end
47
46
 
48
47
  ##
@@ -52,9 +51,8 @@ module RDF::Virtuoso
52
51
  # @param [Hash{Symbol => Object}] options
53
52
  # @return [Query]
54
53
  # @see http://www.w3.org/TR/rdf-sparql-query/#describe
55
- def self.describe(*variables)
56
- options = variables.last.is_a?(Hash) ? variables.pop : {}
57
- self.new(:describe, options).describe(*variables)
54
+ def self.describe(*variables, **options)
55
+ self.new(:describe, **options).describe(*variables)
58
56
  end
59
57
 
60
58
  ##
@@ -64,9 +62,8 @@ module RDF::Virtuoso
64
62
  # @param [Hash{Symbol => Object}] options
65
63
  # @return [Query]
66
64
  # @see http://www.w3.org/TR/rdf-sparql-query/#construct
67
- def self.construct(*patterns)
68
- options = patterns.last.is_a?(Hash) ? patterns.pop : {}
69
- self.new(:construct, options).construct(*patterns) # FIXME
65
+ def self.construct(*patterns, **options)
66
+ self.new(:construct, **options).construct(*patterns) # FIXME
70
67
  end
71
68
 
72
69
  ##
@@ -76,40 +73,32 @@ module RDF::Virtuoso
76
73
  # @param [Hash{Symbol => Object}] options
77
74
  # @return [Query]
78
75
  # @see http://www.w3.org/Submission/SPARQL-Update/
79
- def self.insert_data(*patterns)
80
- # options = variables.last.is_a?(Hash) ? variables.pop : {}
81
- options = patterns.last.is_a?(Hash) ? patterns.pop : {}
82
- self.new(:insert_data, options).insert_data(*patterns)
76
+ def self.insert_data(*patterns, **options)
77
+ self.new(:insert_data, **options).insert_data(*patterns)
83
78
  end
84
79
 
85
- def self.insert(*patterns)
86
- options = patterns.last.is_a?(Hash) ? patterns.pop : {}
87
- self.new(:insert, options).insert(*patterns)
80
+ def self.insert(*patterns, **options)
81
+ self.new(:insert, **options).insert(*patterns)
88
82
  end
89
83
 
90
- def self.delete_data(*patterns)
91
- options = patterns.last.is_a?(Hash) ? patterns.pop : {}
92
- self.new(:delete_data, options).delete_data(*patterns)
84
+ def self.delete_data(*patterns, **options)
85
+ self.new(:delete_data, **options).delete_data(*patterns)
93
86
  end
94
87
 
95
- def self.delete(*patterns)
96
- options = patterns.last.is_a?(Hash) ? patterns.pop : {}
97
- self.new(:delete, options).delete(*patterns)
88
+ def self.delete(*patterns, **options)
89
+ self.new(:delete, **options).delete(*patterns)
98
90
  end
99
91
 
100
- def self.create(*variables)
101
- options = variables.last.is_a?(Hash) ? variables.pop : {}
102
- self.new(:create, options).create(variables.first)
92
+ def self.create(*variables, **options)
93
+ self.new(:create, **options).create(variables.first)
103
94
  end
104
95
 
105
- def self.drop(*variables)
106
- options = variables.last.is_a?(Hash) ? variables.pop : {}
107
- self.new(:drop, options).drop(variables.first)
96
+ def self.drop(*variables, **options)
97
+ self.new(:drop, **options).drop(variables.first)
108
98
  end
109
99
 
110
- def self.clear(*variables)
111
- options = variables.last.is_a?(Hash) ? variables.pop : {}
112
- self.new(:clear, options).clear(variables.first)
100
+ def self.clear(*variables, **options)
101
+ self.new(:clear, **options).clear(variables.first)
113
102
  end
114
103
 
115
104
  ##
@@ -117,9 +106,9 @@ module RDF::Virtuoso
117
106
  # @param [Hash{Symbol => Object}] options
118
107
  # @yield [query]
119
108
  # @yieldparam [Query]
120
- def initialize(form = :ask, options = {}, &block)
109
+ def initialize(form = :ask, **options, &block)
121
110
  @form = form.respond_to?(:to_sym) ? form.to_sym : form.to_s.to_sym
122
- super([], options, &block)
111
+ super([], **options, &block)
123
112
  end
124
113
 
125
114
  ##
@@ -228,13 +217,6 @@ module RDF::Virtuoso
228
217
  self
229
218
  end
230
219
 
231
- # def delete(*variables)
232
- # @values = variables.map { |var|
233
- # [var, var.is_a?(RDF::URI) ? var : RDF::Query::Variable.new(var)]
234
- # }
235
- # self
236
- # end
237
-
238
220
  def create(uri)
239
221
  options[:graph] = uri
240
222
  self
@@ -271,8 +253,6 @@ module RDF::Virtuoso
271
253
  def from_named(uri)
272
254
  (options[:from_named] ||= []) << uri
273
255
  self
274
- #options[:from_named] = uri
275
- #self
276
256
  end
277
257
 
278
258
  # @param RDF::URI uri
@@ -350,7 +330,6 @@ module RDF::Virtuoso
350
330
 
351
331
  AGG_METHODS.each do |m|
352
332
  define_method m do |*variables|
353
- #options[m.to_sym] = variables
354
333
  options[m.to_sym] ||= []
355
334
  options[m.to_sym] += variables
356
335
  self
@@ -424,7 +403,7 @@ module RDF::Virtuoso
424
403
  ##
425
404
  # @private
426
405
  # make RDF::Query::Pattern from triple array if not already done
427
- # include :context in Statement
406
+ # include :graph_name in Statement
428
407
  # @return [RDF::Query::Pattern]
429
408
  def build_patterns(patterns)
430
409
  patterns.map do |pattern|
@@ -486,10 +465,10 @@ module RDF::Virtuoso
486
465
 
487
466
  ##
488
467
  # @return [Object]
489
- def execute
468
+ # def execute
490
469
  #query
491
470
  #raise NotImplementedError
492
- end
471
+ # end
493
472
 
494
473
  ##
495
474
  # Returns the string representation of this query.
@@ -507,7 +486,6 @@ module RDF::Virtuoso
507
486
  aggregates = [:count, :min, :max, :avg, :sum, :sample, :group_concat, :group_digest]
508
487
  if (options.keys & aggregates).any?
509
488
  (options.keys & aggregates).each do |agg|
510
- #p options[agg]
511
489
  case agg
512
490
  when :sample
513
491
  # multiple samples splits to individual sample expressions
@@ -614,10 +592,10 @@ module RDF::Virtuoso
614
592
  buffer << '{' if options[:unions]
615
593
 
616
594
  # iterate patterns
617
- # does patterns have :context hash? build with GRAPH statement
595
+ # does patterns have :graph_name hash? build with GRAPH statement
618
596
  patterns.each do | pattern|
619
- if pattern.context
620
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
597
+ if pattern.graph_name
598
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
621
599
  buffer << '{'
622
600
  buffer << serialize_patterns(pattern)
623
601
  buffer << '}'
@@ -631,8 +609,8 @@ module RDF::Virtuoso
631
609
  buffer << 'OPTIONAL {'
632
610
 
633
611
  patterns.each do | pattern|
634
- if pattern.context
635
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
612
+ if pattern.graph_name
613
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
636
614
  buffer << '{'
637
615
  buffer << serialize_patterns(pattern)
638
616
  buffer << '}'
@@ -650,8 +628,8 @@ module RDF::Virtuoso
650
628
  buffer << 'MINUS {'
651
629
 
652
630
  patterns.each do | pattern|
653
- if pattern.context
654
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
631
+ if pattern.graph_name
632
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
655
633
  buffer << '{'
656
634
  buffer << serialize_patterns(pattern)
657
635
  buffer << '}'
@@ -1,10 +1,11 @@
1
1
  require 'api_smith'
2
2
  require 'rdf'
3
3
  require 'uri'
4
+ require 'timeout'
4
5
 
5
6
  module RDF
6
7
  module Virtuoso
7
- class Repository < RDF::Repository
8
+ class Repository < ::RDF::Repository
8
9
  include APISmith::Client
9
10
 
10
11
  RESULT_JSON = 'application/sparql-results+json'.freeze
@@ -19,28 +20,28 @@ module RDF
19
20
  class NotAuthorized < ClientError; end
20
21
  class ServerError < StandardError; end
21
22
 
22
- # TODO: Look at issues with HTTParty Connection reset
23
23
  #persistent
24
24
  maintain_method_across_redirects true
25
25
 
26
26
  attr_reader :uri, :update_uri, :username, :password, :auth_method
27
27
 
28
- def initialize(uri, opts={})
28
+ def initialize(uri, opts={}, &block)
29
29
  @uri = URI.parse(uri)
30
30
  @update_uri = URI.parse(opts[:update_uri]) if opts[:update_uri]
31
31
  @base_uri = "#{@uri.scheme}://#{@uri.host}"
32
32
  @base_uri += ":" + @uri.port.to_s if @uri.port
33
- @username = opts[:username] || nil
33
+ @username = opts[:username] || nil
34
34
  @password = opts[:password] || nil
35
35
  @auth_method = opts[:auth_method] || 'digest'
36
+ @timeout = opts[:timeout] || 5 # default timeout 5 seconds
36
37
 
37
38
  @sparql_endpoint = @uri.request_uri
38
39
  @sparul_endpoint = @update_uri.nil? ? @sparql_endpoint : @update_uri.request_uri
39
40
  self.class.base_uri @base_uri
40
41
  end
41
42
 
42
- READ_METHODS = %w(select ask construct describe)
43
- WRITE_METHODS = %w(query insert insert_data update delete delete_data create drop clear)
43
+ READ_METHODS = %w(query select ask construct describe)
44
+ WRITE_METHODS = %w(insert insert_data update delete delete_data create drop clear)
44
45
 
45
46
  READ_METHODS.each do |m|
46
47
  define_method m do |*args|
@@ -53,7 +54,7 @@ module RDF
53
54
  response = api_post *args
54
55
  end
55
56
  end
56
-
57
+
57
58
  private
58
59
 
59
60
  def check_response_errors(response)
@@ -72,46 +73,53 @@ module RDF
72
73
  end
73
74
 
74
75
  def base_query_options
75
- { :format => 'json' }
76
+ { format: RESULT_JSON }
76
77
  end
77
78
 
78
79
  def base_request_options
79
- { :headers => headers }
80
+ { headers: headers }
80
81
  end
81
82
 
82
83
  def extra_request_options
83
84
  case @auth_method
84
85
  when 'basic'
85
- { :basic_auth => auth }
86
+ { basic_auth: auth }
86
87
  when 'digest'
87
- { :digest_auth => auth }
88
+ { digest_auth: auth }
88
89
  end
89
90
  end
90
-
91
+
91
92
  def auth
92
- { :username => @username, :password => @password }
93
+ { username: @username, password: @password }
93
94
  end
94
-
95
+
95
96
  def api_get(query, options = {})
96
97
  # prefer sparul endpoint with auth if present to allow SELECT/CONSTRUCT access to protected graphs
97
98
  if @sparul_endpoint
98
99
  self.class.endpoint @sparul_endpoint
99
- get '/', :extra_query => { :query => query }.merge(options),
100
- :extra_request => extra_request_options,
101
- :transform => RDF::Virtuoso::Parser::JSON
100
+ Timeout::timeout(@timeout) {
101
+ get '/', extra_query: { query: query }.merge(options),
102
+ extra_request: extra_request_options,
103
+ transform: RDF::Virtuoso::Parser::JSON
104
+ }
102
105
  else
103
106
  self.class.endpoint @sparql_endpoint
104
- get '/', :extra_query => { :query => query }.merge(options),
105
- :transform => RDF::Virtuoso::Parser::JSON
107
+ Timeout::timeout(@timeout) {
108
+ puts self.inspect
109
+ get '/', extra_query: { query: query }.merge(options),
110
+ transform: RDF::Virtuoso::Parser::JSON
111
+ }
106
112
  end
107
113
  end
108
114
 
109
115
  def api_post(query, options = {})
110
116
  self.class.endpoint @sparul_endpoint
111
- post '/', :extra_body => { :query => query }.merge(options),
112
- :extra_request => extra_request_options,
113
- :response_container => [
114
- "results", "bindings", 0, "callret-0", "value"]
117
+ Timeout::timeout(@timeout) {
118
+ post '/', extra_body: { query: query }.merge(options),
119
+ extra_request: extra_request_options,
120
+ response_container: [
121
+ "results", "bindings", 0, "callret-0", "value"]
122
+ }
115
123
  end
116
124
 
117
125
  end
@@ -1,5 +1,18 @@
1
- module RDF
2
- module Virtuoso
3
- VERSION = "0.1.3"
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,137 +1,138 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-virtuoso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.2.0
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-03-06 00:00:00.000000000 Z
12
+ date: 2021-04-08 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.13.0
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.13.0
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.0.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.0.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.0.3
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.0.3
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.10.2
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.10.2
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.2.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
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdf-vocab
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
93
89
  - !ruby/object:Gem::Version
94
- version: 1.2.0
95
- description: An RDF.rb extension library for interacting with a Virtuoso rdf store
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'
98
+ description: An RDF.rb extension library for interacting with a Virtuoso rdf store.\nSupports
99
+ SPARQL 1.1 UPDATE extensions and some Virtuoso specific commands.
96
100
  email:
97
101
  - benjamin.rokseth@kul.oslo.kommune.no
98
102
  executables: []
99
103
  extensions: []
100
104
  extra_rdoc_files: []
101
105
  files:
106
+ - LICENSE
102
107
  - README.md
108
+ - VERSION
103
109
  - lib/rdf/virtuoso.rb
104
- - lib/rdf/virtuoso/version.rb
105
110
  - lib/rdf/virtuoso/parser.rb
106
111
  - lib/rdf/virtuoso/prefixes.rb
107
- - lib/rdf/virtuoso/repository.rb
108
112
  - lib/rdf/virtuoso/query.rb
109
- - spec/repository_spec.rb
110
- - spec/query_spec.rb
111
- - spec/spec_helper.rb
112
- - spec/prefixes_spec.rb
113
- homepage: https://github.com/digibib/rdf-virtuoso
114
- licenses: []
115
- post_install_message:
113
+ - lib/rdf/virtuoso/repository.rb
114
+ - lib/rdf/virtuoso/version.rb
115
+ homepage: https://github.com/ruby-rdf/rdf-virtuoso
116
+ licenses:
117
+ - Unlicense
118
+ metadata: {}
119
+ post_install_message:
116
120
  rdoc_options: []
117
121
  require_paths:
118
122
  - lib
119
123
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
124
  requirements:
122
- - - ! '>='
125
+ - - ">="
123
126
  - !ruby/object:Gem::Version
124
127
  version: '0'
125
128
  required_rubygems_version: !ruby/object:Gem::Requirement
126
- none: false
127
129
  requirements:
128
- - - ! '>='
130
+ - - ">="
129
131
  - !ruby/object:Gem::Version
130
132
  version: '0'
131
133
  requirements: []
132
- rubyforge_project: rdf-virtuoso
133
- rubygems_version: 1.8.24
134
- signing_key:
135
- specification_version: 3
134
+ rubygems_version: 3.2.3
135
+ signing_key:
136
+ specification_version: 4
136
137
  summary: An RDF.rb extension library for interacting with a Virtuoso rdf store
137
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
data/spec/query_spec.rb DELETED
@@ -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.Document]
153
- ).to_s.should ==
154
- "SELECT * WHERE { ?s ?p ?o . ?s <#{RDF.type}> <#{RDF::DC.Document}> . }"
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.Document, :context => @graph2]).to_s.should ==
161
- "SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.Document}> . } }"
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.Document, :context => @graph2]).to_s.should ==
295
- "SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } OPTIONAL { GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.Document}> . } } }"
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
@@ -1,36 +0,0 @@
1
- $:.unshift "."
2
- require 'spec_helper'
3
- require 'rdf/spec/repository'
4
- #require_relative '../lib/rdf/virtuoso/repository'
5
- describe RDF::Virtuoso::Repository do
6
-
7
- before(:each) do
8
- @uri = "http://localhost:8890/sparql"
9
- @update_uri = "http://localhost:8890/sparql-auth"
10
- end
11
-
12
- it "should mixin RDF::Repository" do
13
- @repository = RDF::Virtuoso::Repository.new(@uri)
14
- #it_should_behave_like RDF_Repository # not working!
15
- end
16
-
17
- it "should support connecting to a Virtuoso SPARQL endpoint" do
18
- repo = RDF::Virtuoso::Repository.new(@uri)
19
- repo.instance_variable_get("@sparul_endpoint").should == "/sparql"
20
- end
21
-
22
- it "should support accept port in repository endpoint" do
23
- repo = RDF::Virtuoso::Repository.new(@uri)
24
- repo.instance_variable_get("@base_uri").should == "http://localhost:8890"
25
- end
26
-
27
- it "should support connecting to a Virtuoso SPARUL endpoint with BASIC AUTH" do
28
- repo = RDF::Virtuoso::Repository.new(@uri, :update_uri => @update_uri, :username => 'admin', :password => 'secret', :auth_method => 'basic')
29
- repo.instance_variable_get("@auth_method").should == "basic"
30
- end
31
-
32
- it "should support connecting to a Virtuoso SPARUL endpoint with DIGEST AUTH" do
33
- repo = RDF::Virtuoso::Repository.new(@uri, :update_uri => @update_uri, :username => 'admin', :password => 'secret', :auth_method => 'digest')
34
- repo.instance_variable_get("@sparul_endpoint").should == "/sparql-auth"
35
- end
36
- end
data/spec/spec_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/setup'
2
- require 'rspec'
3
- require 'rdf'
4
- require 'rdf/spec'
5
- require 'rdf/virtuoso'
6
- require 'rdf/spec/repository'