rdf-virtuoso 0.1.2 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,12 +1,17 @@
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 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
- RDF::Virtuoso::Query extends 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
- ./spec/client_spec.rb
14
+ ./spec/repository_spec.rb
10
15
  and
11
16
  ./spec/query_spec.rb
12
17
 
@@ -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
@@ -228,13 +228,6 @@ module RDF::Virtuoso
228
228
  self
229
229
  end
230
230
 
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
231
  def create(uri)
239
232
  options[:graph] = uri
240
233
  self
@@ -269,7 +262,7 @@ module RDF::Virtuoso
269
262
  # @param RDF::URI uri
270
263
  # @return [Query]
271
264
  def from_named(uri)
272
- options[:from_named] = uri
265
+ (options[:from_named] ||= []) << uri
273
266
  self
274
267
  end
275
268
 
@@ -348,7 +341,6 @@ module RDF::Virtuoso
348
341
 
349
342
  AGG_METHODS.each do |m|
350
343
  define_method m do |*variables|
351
- #options[m.to_sym] = variables
352
344
  options[m.to_sym] ||= []
353
345
  options[m.to_sym] += variables
354
346
  self
@@ -422,7 +414,7 @@ module RDF::Virtuoso
422
414
  ##
423
415
  # @private
424
416
  # make RDF::Query::Pattern from triple array if not already done
425
- # include :context in Statement
417
+ # include :graph_name in Statement
426
418
  # @return [RDF::Query::Pattern]
427
419
  def build_patterns(patterns)
428
420
  patterns.map do |pattern|
@@ -484,10 +476,10 @@ module RDF::Virtuoso
484
476
 
485
477
  ##
486
478
  # @return [Object]
487
- def execute
479
+ # def execute
488
480
  #query
489
481
  #raise NotImplementedError
490
- end
482
+ # end
491
483
 
492
484
  ##
493
485
  # Returns the string representation of this query.
@@ -505,7 +497,6 @@ module RDF::Virtuoso
505
497
  aggregates = [:count, :min, :max, :avg, :sum, :sample, :group_concat, :group_digest]
506
498
  if (options.keys & aggregates).any?
507
499
  (options.keys & aggregates).each do |agg|
508
- #p options[agg]
509
500
  case agg
510
501
  when :sample
511
502
  # multiple samples splits to individual sample expressions
@@ -603,7 +594,7 @@ module RDF::Virtuoso
603
594
  end
604
595
 
605
596
  buffer << "FROM #{serialize_value(options[:from])}" if options[:from]
606
- buffer << "FROM NAMED #{serialize_value(options[:from_named])}" if options[:from_named]
597
+ options[:from_named].each {|from_named| buffer << "FROM NAMED #{serialize_value(from_named)}" } if options[:from_named]
607
598
 
608
599
 
609
600
  unless patterns.empty? && ([:describe, :insert_data, :delete_data, :create, :clear, :drop].include?(form))
@@ -612,10 +603,10 @@ module RDF::Virtuoso
612
603
  buffer << '{' if options[:unions]
613
604
 
614
605
  # iterate patterns
615
- # does patterns have :context hash? build with GRAPH statement
606
+ # does patterns have :graph_name hash? build with GRAPH statement
616
607
  patterns.each do | pattern|
617
- if pattern.context
618
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
608
+ if pattern.graph_name
609
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
619
610
  buffer << '{'
620
611
  buffer << serialize_patterns(pattern)
621
612
  buffer << '}'
@@ -629,8 +620,8 @@ module RDF::Virtuoso
629
620
  buffer << 'OPTIONAL {'
630
621
 
631
622
  patterns.each do | pattern|
632
- if pattern.context
633
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
623
+ if pattern.graph_name
624
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
634
625
  buffer << '{'
635
626
  buffer << serialize_patterns(pattern)
636
627
  buffer << '}'
@@ -648,8 +639,8 @@ module RDF::Virtuoso
648
639
  buffer << 'MINUS {'
649
640
 
650
641
  patterns.each do | pattern|
651
- if pattern.context
652
- buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
642
+ if pattern.graph_name
643
+ buffer << "GRAPH #{serialize_value(RDF::URI(pattern.graph_name))}"
653
644
  buffer << '{'
654
645
  buffer << serialize_patterns(pattern)
655
646
  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
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.2"
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.2
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-03-04 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.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
+ - - "~>"
93
82
  - !ruby/object:Gem::Version
94
- version: 1.2.0
95
- description: An RDF.rb extension library for interacting with a Virtuoso rdf store
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'
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
103
- - lib/rdf/virtuoso/version.rb
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
112
+ - lib/rdf/virtuoso/query.rb
106
113
  - lib/rdf/virtuoso/repository.rb
107
- - lib/rdf/virtuoso/parser.rb
108
- - lib/rdf/virtuoso.rb
109
- - spec/repository_spec.rb
110
- - spec/prefixes_spec.rb
111
- - spec/query_spec.rb
112
- - spec/spec_helper.rb
113
- homepage: https://github.com/digibib/rdf-virtuoso
114
- licenses: []
115
- post_install_message:
114
+ - lib/rdf/virtuoso/version.rb
115
+ homepage: https://github.com/ruby-rdf/rdf-virtuoso
116
+ licenses:
117
+ - GPL-3.0
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.1.4
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: []