rdf-mongo 1.1.0 → 2.0.0.beta1
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rdf/mongo.rb +80 -56
- data/lib/rdf/mongo/version.rb +1 -1
- metadata +64 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf15f8c6d12d55bd85991a3e6bf8ab4ee318568b
|
4
|
+
data.tar.gz: 78e563de1eccb9af04635ebf61cd3b8feb181858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf281484d6946e53cd6edaf7c83715fe98021f4114cfaf2efad1c1525eb6b39f2ae90de862cdbaa38e6df54513855bd6dfe547356e433ae38657c16e67d34ccf
|
7
|
+
data.tar.gz: 87489d3773aaed971a6060d37139a22440d493ca1ad321fa2e141e1f0e35672212dde03a8a37ea350edd60d8af1b1398b71f85bdab7b640e33c154b181ecf075
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0.beta1
|
data/lib/rdf/mongo.rb
CHANGED
@@ -14,17 +14,17 @@ module RDF
|
|
14
14
|
end
|
15
15
|
|
16
16
|
##
|
17
|
-
# Create BSON for a statement representation. Note that if the statement has no
|
17
|
+
# Create BSON for a statement representation. Note that if the statement has no graph name,
|
18
18
|
# a value of `false` will be used to indicate the default context
|
19
19
|
#
|
20
20
|
# @param [RDF::Statement] statement
|
21
21
|
# @return [Hash] Generated BSON representation of statement.
|
22
22
|
def self.from_mongo(statement)
|
23
23
|
RDF::Statement.new(
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
24
|
+
subject: RDF::Mongo::Conversion.from_mongo(statement['s'], statement['st'], statement['sl']),
|
25
|
+
predicate: RDF::Mongo::Conversion.from_mongo(statement['p'], statement['pt'], statement['pl']),
|
26
|
+
object: RDF::Mongo::Conversion.from_mongo(statement['o'], statement['ot'], statement['ol']),
|
27
|
+
graph_name: RDF::Mongo::Conversion.from_mongo(statement['c'], statement['ct'], statement['cl']))
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -37,9 +37,9 @@ module RDF
|
|
37
37
|
#
|
38
38
|
# @param [RDF::Value, Symbol, false, nil] value
|
39
39
|
# URI, BNode or Literal. May also be a Variable or Symbol to indicate
|
40
|
-
# a pattern for a named
|
40
|
+
# a pattern for a named graph, or `false` to indicate the default graph.
|
41
41
|
# A value of `nil` indicates a pattern that matches any value.
|
42
|
-
# @param [:subject, :predicate, :object, :
|
42
|
+
# @param [:subject, :predicate, :object, :graph_name] place_in_statement
|
43
43
|
# Position within statement.
|
44
44
|
# @return [Hash] BSON representation of the statement
|
45
45
|
def self.to_mongo(value, place_in_statement)
|
@@ -76,11 +76,11 @@ module RDF
|
|
76
76
|
t, k1, lt = :pt, :p, :pl
|
77
77
|
when :object
|
78
78
|
t, k1, lt = :ot, :o, :ol
|
79
|
-
when :
|
79
|
+
when :graph_name
|
80
80
|
t, k1, lt = :ct, :c, :cl
|
81
81
|
end
|
82
82
|
h = {k1 => v, t => k, lt => ll}
|
83
|
-
h.delete_if {|
|
83
|
+
h.delete_if {|kk,_| h[kk].nil?}
|
84
84
|
end
|
85
85
|
|
86
86
|
##
|
@@ -92,9 +92,9 @@ module RDF
|
|
92
92
|
when :u
|
93
93
|
RDF::URI.intern(value)
|
94
94
|
when :ll
|
95
|
-
RDF::Literal.new(value, :
|
95
|
+
RDF::Literal.new(value, language: literal_extra.to_sym)
|
96
96
|
when :lt
|
97
|
-
RDF::Literal.new(value, :
|
97
|
+
RDF::Literal.new(value, datatype: RDF::URI.intern(literal_extra))
|
98
98
|
when :l
|
99
99
|
RDF::Literal.new(value)
|
100
100
|
when :n
|
@@ -108,63 +108,90 @@ module RDF
|
|
108
108
|
|
109
109
|
class Repository < ::RDF::Repository
|
110
110
|
# The Mongo database instance
|
111
|
-
# @!attribute [r] db
|
112
111
|
# @return [Mongo::DB]
|
113
|
-
attr_reader :
|
112
|
+
attr_reader :client
|
114
113
|
|
115
114
|
# The collection used for storing quads
|
116
|
-
# @!attribute [r] coll
|
117
115
|
# @return [Mongo::Collection]
|
118
|
-
attr_reader :
|
116
|
+
attr_reader :collection
|
119
117
|
|
120
118
|
##
|
121
119
|
# Initializes this repository instance.
|
122
120
|
#
|
123
|
-
# @
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
# @
|
121
|
+
# @overload initialize(options = {}, &block)
|
122
|
+
# @param [Hash{Symbol => Object}] options
|
123
|
+
# @option options [String, #to_s] :title (nil)
|
124
|
+
# @option options [URI, #to_s] :uri (nil)
|
125
|
+
# URI in the form `mongodb://host:port/db`. The URI should also identify the collection use, but appending a `collection` path component such as `mongodb://host:port/db/collection`, this ensures that the collection will be maintained if cloned. See [Mongo::Client options](https://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial-2-0/#uri-options-conversions) for more information on Mongo URIs.
|
126
|
+
#
|
127
|
+
# @overload initialize(options = {}, &block)
|
128
|
+
# @param [Hash{Symbol => Object}] options
|
129
|
+
# See [Mongo::Client options](https://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial-2-0/#uri-options-conversions) for more information on Mongo Client options.
|
130
|
+
# @option options [String, #to_s] :title (nil)
|
131
|
+
# @option options [String] :host
|
132
|
+
# a single address or an array of addresses, which may contain a port designation
|
133
|
+
# @option options [Integer] :port (27017) applied to host address(es)
|
134
|
+
# @option options [String] :database ('quadb')
|
135
|
+
# @option options [String] :collection ('quads')
|
136
|
+
#
|
130
137
|
# @yield [repository]
|
131
138
|
# @yieldparam [Repository] repository
|
132
139
|
def initialize(options = {}, &block)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
140
|
+
collection = nil
|
141
|
+
if options[:uri]
|
142
|
+
options = options.dup
|
143
|
+
uri = RDF::URI(options.delete(:uri))
|
144
|
+
_, db, coll = uri.path.split('/')
|
145
|
+
collection = coll || options.delete(:collection)
|
146
|
+
db ||= "quadb"
|
147
|
+
uri.path = "/#{db}" if coll
|
148
|
+
@client = ::Mongo::Client.new(uri.to_s, options)
|
149
|
+
else
|
150
|
+
warn "[DEPRECATION] RDF::Mongo::Repository#initialize expects a uri argument. Called from #{Gem.location_of_caller.join(':')}" unless options.empty?
|
151
|
+
options[:database] ||= options.delete(:db) # 1.x compat
|
152
|
+
options[:database] ||= 'quadb'
|
153
|
+
hosts = Array(options[:host] || 'localhost')
|
154
|
+
hosts.map! {|h| "#{h}:#{options[:port]}"} if options[:port]
|
155
|
+
@client = ::Mongo::Client.new(hosts, options)
|
156
|
+
end
|
157
|
+
|
158
|
+
@collection = @client[options.delete(:collection) || 'quads']
|
159
|
+
@collection.indexes.create_many([
|
160
|
+
{key: {s: 1}},
|
161
|
+
{key: {p: 1}},
|
162
|
+
{key: {o: "hashed"}},
|
163
|
+
{key: {c: 1}},
|
164
|
+
{key: {s: 1, p: 1}},
|
165
|
+
#{key: {s: 1, o: "hashed"}}, # Muti-key hashed indexes not allowed
|
166
|
+
#{key: {p: 1, o: "hashed"}}, # Muti-key hashed indexes not allowed
|
167
|
+
])
|
143
168
|
super(options, &block)
|
144
169
|
end
|
145
170
|
|
146
171
|
# @see RDF::Mutable#insert_statement
|
147
172
|
def supports?(feature)
|
148
173
|
case feature.to_sym
|
149
|
-
when :
|
174
|
+
when :graph_name then true
|
175
|
+
when :validity then @options.fetch(:with_validity, true)
|
150
176
|
else false
|
151
177
|
end
|
152
178
|
end
|
153
179
|
|
154
180
|
def insert_statement(statement)
|
181
|
+
raise ArgumentError, "Statement #{statement.inspect} is incomplete" if statement.incomplete?
|
155
182
|
st_mongo = statement.to_mongo
|
156
|
-
st_mongo[:ct] ||= :default # Indicate statement is in the default
|
183
|
+
st_mongo[:ct] ||= :default # Indicate statement is in the default graph
|
157
184
|
#puts "insert statement: #{st_mongo.inspect}"
|
158
|
-
@
|
185
|
+
@collection.update_one(st_mongo, st_mongo, upsert: true)
|
159
186
|
end
|
160
187
|
|
161
188
|
# @see RDF::Mutable#delete_statement
|
162
189
|
def delete_statement(statement)
|
163
|
-
case statement.
|
190
|
+
case statement.graph_name
|
164
191
|
when nil
|
165
|
-
@
|
192
|
+
@collection.delete_one(statement.to_mongo.merge('ct'=>:default))
|
166
193
|
else
|
167
|
-
@
|
194
|
+
@collection.delete_one(statement.to_mongo)
|
168
195
|
end
|
169
196
|
end
|
170
197
|
|
@@ -176,24 +203,24 @@ module RDF
|
|
176
203
|
##
|
177
204
|
# @private
|
178
205
|
# @see RDF::Countable#empty?
|
179
|
-
def empty?; @
|
206
|
+
def empty?; @collection.count == 0; end
|
180
207
|
|
181
208
|
##
|
182
209
|
# @private
|
183
210
|
# @see RDF::Countable#count
|
184
211
|
def count
|
185
|
-
@
|
212
|
+
@collection.count
|
186
213
|
end
|
187
214
|
|
188
215
|
def clear_statements
|
189
|
-
@
|
216
|
+
@collection.delete_many
|
190
217
|
end
|
191
218
|
|
192
219
|
##
|
193
220
|
# @private
|
194
221
|
# @see RDF::Enumerable#has_statement?
|
195
222
|
def has_statement?(statement)
|
196
|
-
|
223
|
+
@collection.find(statement.to_mongo).count > 0
|
197
224
|
end
|
198
225
|
##
|
199
226
|
# @private
|
@@ -201,10 +228,8 @@ module RDF
|
|
201
228
|
def each_statement(&block)
|
202
229
|
@nodes = {} # reset cache. FIXME this should probably be in Node.intern
|
203
230
|
if block_given?
|
204
|
-
@
|
205
|
-
|
206
|
-
block.call(RDF::Statement.from_mongo(data))
|
207
|
-
end
|
231
|
+
@collection.find().each do |document|
|
232
|
+
block.call(RDF::Statement.from_mongo(document))
|
208
233
|
end
|
209
234
|
end
|
210
235
|
enum_statement
|
@@ -213,9 +238,9 @@ module RDF
|
|
213
238
|
|
214
239
|
##
|
215
240
|
# @private
|
216
|
-
# @see RDF::Enumerable#
|
217
|
-
def
|
218
|
-
|
241
|
+
# @see RDF::Enumerable#has_graph?
|
242
|
+
def has_graph?(value)
|
243
|
+
@collection.find(RDF::Mongo::Conversion.to_mongo(value, :graph_name)).count > 0
|
219
244
|
end
|
220
245
|
|
221
246
|
protected
|
@@ -224,17 +249,16 @@ module RDF
|
|
224
249
|
# @private
|
225
250
|
# @see RDF::Queryable#query_pattern
|
226
251
|
# @see RDF::Query::Pattern
|
227
|
-
def query_pattern(pattern, &block)
|
252
|
+
def query_pattern(pattern, options = {}, &block)
|
253
|
+
return enum_for(:query_pattern, pattern, options) unless block_given?
|
228
254
|
@nodes = {} # reset cache. FIXME this should probably be in Node.intern
|
229
255
|
|
230
|
-
# A pattern
|
256
|
+
# A pattern graph_name of `false` is used to indicate the default graph
|
231
257
|
pm = pattern.to_mongo
|
232
|
-
pm.merge!(:
|
258
|
+
pm.merge!(c: nil, ct: :default) if pattern.graph_name == false
|
233
259
|
#puts "query using #{pm.inspect}"
|
234
|
-
@
|
235
|
-
|
236
|
-
block.call(RDF::Statement.from_mongo(data))
|
237
|
-
end
|
260
|
+
@collection.find(pm).each do |document|
|
261
|
+
block.call(RDF::Statement.from_mongo(document))
|
238
262
|
end
|
239
263
|
end
|
240
264
|
|
data/lib/rdf/mongo/version.rb
CHANGED
metadata
CHANGED
@@ -1,114 +1,143 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pius Uzamere
|
8
|
+
- Gregg Kellogg
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rdf
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
+
version: 2.0.0.beta
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3'
|
20
24
|
type: :runtime
|
21
25
|
prerelease: false
|
22
26
|
version_requirements: !ruby/object:Gem::Requirement
|
23
27
|
requirements:
|
24
|
-
- -
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.0.0.beta
|
31
|
+
- - "<"
|
25
32
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
33
|
+
version: '3'
|
27
34
|
- !ruby/object:Gem::Dependency
|
28
35
|
name: mongo
|
29
36
|
requirement: !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
|
-
- -
|
38
|
+
- - "~>"
|
32
39
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
40
|
+
version: '2.2'
|
34
41
|
type: :runtime
|
35
42
|
prerelease: false
|
36
43
|
version_requirements: !ruby/object:Gem::Requirement
|
37
44
|
requirements:
|
38
|
-
- -
|
45
|
+
- - "~>"
|
39
46
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
47
|
+
version: '2.2'
|
41
48
|
- !ruby/object:Gem::Dependency
|
42
49
|
name: rdf-spec
|
43
50
|
requirement: !ruby/object:Gem::Requirement
|
44
51
|
requirements:
|
45
|
-
- -
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0.beta
|
55
|
+
- - "<"
|
46
56
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
57
|
+
version: '3'
|
48
58
|
type: :development
|
49
59
|
prerelease: false
|
50
60
|
version_requirements: !ruby/object:Gem::Requirement
|
51
61
|
requirements:
|
52
|
-
- -
|
62
|
+
- - ">="
|
53
63
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
64
|
+
version: 2.0.0.beta
|
65
|
+
- - "<"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3'
|
55
68
|
- !ruby/object:Gem::Dependency
|
56
69
|
name: rspec
|
57
70
|
requirement: !ruby/object:Gem::Requirement
|
58
71
|
requirements:
|
59
|
-
- -
|
72
|
+
- - "~>"
|
60
73
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
74
|
+
version: '3.4'
|
62
75
|
type: :development
|
63
76
|
prerelease: false
|
64
77
|
version_requirements: !ruby/object:Gem::Requirement
|
65
78
|
requirements:
|
66
|
-
- -
|
79
|
+
- - "~>"
|
67
80
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
81
|
+
version: '3.4'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rspec-its
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.2'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.2'
|
69
96
|
- !ruby/object:Gem::Dependency
|
70
97
|
name: yard
|
71
98
|
requirement: !ruby/object:Gem::Requirement
|
72
99
|
requirements:
|
73
|
-
- -
|
100
|
+
- - "~>"
|
74
101
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.8
|
102
|
+
version: '0.8'
|
76
103
|
type: :development
|
77
104
|
prerelease: false
|
78
105
|
version_requirements: !ruby/object:Gem::Requirement
|
79
106
|
requirements:
|
80
|
-
- -
|
107
|
+
- - "~>"
|
81
108
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.8
|
109
|
+
version: '0.8'
|
83
110
|
- !ruby/object:Gem::Dependency
|
84
111
|
name: bson_ext
|
85
112
|
requirement: !ruby/object:Gem::Requirement
|
86
113
|
requirements:
|
87
|
-
- -
|
114
|
+
- - "~>"
|
88
115
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
116
|
+
version: '1.12'
|
90
117
|
type: :development
|
91
118
|
prerelease: false
|
92
119
|
version_requirements: !ruby/object:Gem::Requirement
|
93
120
|
requirements:
|
94
|
-
- -
|
121
|
+
- - "~>"
|
95
122
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
123
|
+
version: '1.12'
|
97
124
|
description: rdf-mongo is a storage adapter for integrating MongoDB and rdf.rb, a
|
98
125
|
Ruby library for working with Resource Description Framework (RDF) data.
|
99
|
-
email:
|
126
|
+
email:
|
127
|
+
- pius@alum.mit.edu
|
128
|
+
- gregg@greggkellogg.net
|
100
129
|
executables: []
|
101
130
|
extensions: []
|
102
131
|
extra_rdoc_files: []
|
103
132
|
files:
|
104
133
|
- LICENSE
|
105
|
-
- VERSION
|
106
134
|
- README.md
|
107
|
-
-
|
135
|
+
- VERSION
|
108
136
|
- lib/rdf/mongo.rb
|
137
|
+
- lib/rdf/mongo/version.rb
|
109
138
|
homepage: http://ruby-rdf.github.com/rdf-mongo
|
110
139
|
licenses:
|
111
|
-
- MIT
|
140
|
+
- MIT
|
112
141
|
metadata: {}
|
113
142
|
post_install_message: Have fun! :)
|
114
143
|
rdoc_options: []
|
@@ -116,17 +145,17 @@ require_paths:
|
|
116
145
|
- lib
|
117
146
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
147
|
requirements:
|
119
|
-
- -
|
148
|
+
- - ">="
|
120
149
|
- !ruby/object:Gem::Version
|
121
|
-
version:
|
150
|
+
version: '2.0'
|
122
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
152
|
requirements:
|
124
|
-
- -
|
153
|
+
- - ">"
|
125
154
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
155
|
+
version: 1.3.1
|
127
156
|
requirements: []
|
128
157
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.1
|
158
|
+
rubygems_version: 2.5.1
|
130
159
|
signing_key:
|
131
160
|
specification_version: 4
|
132
161
|
summary: A storage adapter for integrating MongoDB and rdf.rb, a Ruby library for
|