rdf-redstore 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Nicholas J Humfrey - njh@aelius.com - <http://www.aelius.com/njh/>
data/README ADDED
@@ -0,0 +1,58 @@
1
+ # RedStore storage adapter for RDF.rb
2
+
3
+ This gem allows you to use a [RedStore](http://code.google.com/p/redstore/)
4
+ instance as a backend for RDF.rb.
5
+
6
+ Synopsis:
7
+
8
+ require 'rdf'
9
+ require 'rdf/redstore'
10
+
11
+ repo = RDF::RedStore::Repository.new('http://localhost:8080/')
12
+ puts RDF::Writer.for(:ntriples).dump repo
13
+
14
+ repo.load 'http://datagraph.org/jhacker/foaf.nt'
15
+ repo.count
16
+ # => 10
17
+ # Note: not all of the RedStore storage backends support the count method
18
+
19
+ subject = repo.first.subject
20
+ subject_statements = repo.query(:subject => subject)
21
+ subject_statements.size
22
+ # => 7
23
+
24
+ repo.delete(*subject_statements)
25
+ repo.count
26
+ # => 3
27
+
28
+ ## Installation
29
+
30
+ The recommended method of installation is via RubyGems.
31
+
32
+ $ sudo gem install rdf-redstore
33
+
34
+ ## Resources
35
+
36
+ * {RDF::RedStore::Repository}
37
+ * <http://rdf.rubyforge.org> - RDF.rb's home page
38
+ * <http://rdf.rubyforge.org/RDF/Repository.html> - RDF.rb's Repository documentation
39
+ * <http://code.google.com/p/redstore/>
40
+ * <http://github.com/njh/rdf-redstore/>
41
+
42
+ ### Support
43
+
44
+ Please post questions or feedback to the [W3C-ruby-rdf mailing list][].
45
+
46
+ ### Author
47
+ * Nicholas J Humfrey | <njh@aelius.com>
48
+
49
+ ### 'License'
50
+
51
+ This is free and unemcumbered software released into the public domain. For
52
+ more information, see the accompanying UNLICENSE file.
53
+
54
+ If you're unfamiliar with public domain, that means it's perfectly fine to
55
+ start with this skeleton and code away, later relicensing as you see fit.
56
+
57
+
58
+ [W3C-ruby-rdf mailing list]: http://lists.w3.org/Archives/Public/public-rdf-ruby/
@@ -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 <http://unlicense.org/>
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,37 @@
1
+ require 'rdf'
2
+
3
+ module RDF
4
+ ##
5
+ # **`RDF::RedStore`** is a RedStore adapter for RDF.rb.
6
+ #
7
+ # Dependencies
8
+ # ------------
9
+ #
10
+ # * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.1.0)
11
+ # * [SPARQL::Client](http://rubygems.org/gems/sparql-client) (>= 0.0.3)
12
+ #
13
+ # Installation
14
+ # ------------
15
+ #
16
+ # The recommended installation method is via RubyGems. To install the latest
17
+ # official release, do:
18
+ #
19
+ # % [sudo] gem install rdf-redstore
20
+ #
21
+ # Documentation
22
+ # -------------
23
+ #
24
+ # * {RDF::RedStore::Repository}
25
+ #
26
+ # @example Requiring the `RDF::RedStore` module
27
+ # require 'rdf/redstore'
28
+ #
29
+ # @see http://rdf.rubyforge.org/
30
+ # @see http://code.google.com/p/redstore/
31
+ #
32
+ # @author [Nicholas J Humfrey](http://www.aelius.com/njh/)
33
+ module RedStore
34
+ autoload :Repository, 'rdf/redstore/repository'
35
+ autoload :VERSION, 'rdf/redstore/version'
36
+ end
37
+ end
@@ -0,0 +1,113 @@
1
+ require 'rdf'
2
+ require 'sparql/client'
3
+ require 'net/http'
4
+ require 'enumerator'
5
+
6
+ module RDF::RedStore
7
+
8
+ SD = RDF::Vocabulary.new("http://www.w3.org/ns/sparql-service-description#")
9
+
10
+ ##
11
+ # An RDF::Repository backend for RedStore.
12
+ #
13
+ # @see http://rdf.rubyforge.org/RDF/Repository.html
14
+ class Repository < ::SPARQL::Client::Repository
15
+
16
+ ##
17
+ # Create a new RDF::RedStore::Repository.
18
+ #
19
+ # @param [String] uri
20
+ # @param [Hash] opts
21
+ # @return [RDF::RedStore::Repository]
22
+ # @example
23
+ # RDF::RedStore::Repository.new('http://localhost:8080/')
24
+ #
25
+ def initialize(options_or_uri = {})
26
+ case options_or_uri
27
+ when Hash
28
+ @settings = options_or_uri.dup
29
+ @uri = @settings[:uri].to_s
30
+ else
31
+ @settings = {}
32
+ @uri = options_or_uri.to_s
33
+ end
34
+ super(uri_for(:query), @settings)
35
+ end
36
+
37
+ # @private
38
+ def count
39
+ uri = uri_for(:description)
40
+ description = RDF::Graph.load(uri, :format => :ntriples)
41
+ total = description.first_value(:predicate => SD.totalTriples)
42
+ if total.nil? or total.to_i < 0
43
+ nil
44
+ else
45
+ total.to_i
46
+ end
47
+ end
48
+ alias_method :size, :count
49
+ alias_method :length, :count
50
+
51
+ # @private
52
+ def insert_statement(statement, opts = {})
53
+ insert_statements([statement], opts)
54
+ end
55
+
56
+ # @private
57
+ def insert_statements(statements, opts = {})
58
+ post_statements(:insert, statements, opts)
59
+ end
60
+
61
+ # @private
62
+ def delete_statement(statement, opts = {})
63
+ if statement.invalid?
64
+ delete_statements(query(statement), opts)
65
+ else
66
+ delete_statements([statement], opts)
67
+ end
68
+ end
69
+
70
+ # @private
71
+ def delete_statements(statements, opts = {})
72
+ post_statements(:delete, statements, opts)
73
+ end
74
+
75
+ # @private
76
+ def clear_statements
77
+ uri = uri_for(:data)
78
+ Net::HTTP.start(uri.host, uri.port) do |http|
79
+ http.delete(uri.path).code == '200'
80
+ end
81
+ end
82
+
83
+ def writable?
84
+ true
85
+ end
86
+
87
+ # @private
88
+ def uri_for(action)
89
+ RDF::URI.parse(@uri+action.to_s)
90
+ end
91
+
92
+ # @private
93
+ def post_statements(action, statements, opts = {})
94
+ graph = RDF::Graph.new
95
+ graph.insert_statements(statements)
96
+ content = RDF::Writer.for(:ntriples).dump(graph)
97
+
98
+ uri = uri_for(action)
99
+ req = Net::HTTP::Post.new(uri.path)
100
+ req.form_data = {
101
+ 'content' => content,
102
+ 'content-type' => 'ntriples',
103
+ 'graph' => opts[:context].to_s
104
+ }
105
+
106
+ Net::HTTP.start(uri.host, uri.port) do |http|
107
+ response = http.request(req)
108
+ response.code == '200'
109
+ end
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,19 @@
1
+ module RDF::RedStore
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+ EXTRA = nil
7
+
8
+ STRING = [MAJOR, MINOR, TINY].join('.')
9
+ STRING << "-#{EXTRA}" if EXTRA
10
+
11
+ ##
12
+ # @return [String]
13
+ def self.to_s() STRING end
14
+
15
+ ##
16
+ # @return [String]
17
+ def self.to_str() STRING end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdf-redstore
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Nicholas J Humfrey
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-18 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdf
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 9
31
+ version: 0.1.9
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: sparql-client
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 0
44
+ - 3
45
+ version: 0.0.3
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rdf-spec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 1
58
+ - 6
59
+ version: 0.1.6
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 3
72
+ - 0
73
+ version: 1.3.0
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: yard
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 5
86
+ - 3
87
+ version: 0.5.3
88
+ type: :development
89
+ version_requirements: *id005
90
+ description: RDF.rb plugin providing a RedStore storage adapter.
91
+ email: njh@aelius.com
92
+ executables: []
93
+
94
+ extensions: []
95
+
96
+ extra_rdoc_files: []
97
+
98
+ files:
99
+ - AUTHORS
100
+ - README
101
+ - UNLICENSE
102
+ - VERSION
103
+ - lib/rdf/redstore/repository.rb
104
+ - lib/rdf/redstore/version.rb
105
+ - lib/rdf/redstore.rb
106
+ has_rdoc: false
107
+ homepage: http://rdf.rubyforge.org/
108
+ licenses:
109
+ - Public Domain
110
+ post_install_message:
111
+ rdoc_options: []
112
+
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 1
121
+ - 8
122
+ - 2
123
+ version: 1.8.2
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project: rdf
134
+ rubygems_version: 1.3.6
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: RDF.rb plugin providing a RedStore storage adapter.
138
+ test_files: []
139
+