rdf-4store 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rdf/four_store/repository.rb +68 -40
- metadata +4 -12
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -17,7 +17,7 @@ module RDF::FourStore
|
|
17
17
|
|
18
18
|
attr_reader :endpointURI, :dataURI, :updateURI, :statusURI, :sizeURI
|
19
19
|
|
20
|
-
DEFAULT_CONTEXT = "
|
20
|
+
DEFAULT_CONTEXT = "default:".freeze
|
21
21
|
|
22
22
|
##
|
23
23
|
# Constructor of RDF::FourStore::Repository
|
@@ -146,12 +146,10 @@ module RDF::FourStore
|
|
146
146
|
# @see RDF::Mutable#insert_statement
|
147
147
|
# @private
|
148
148
|
def insert_statement(statement)
|
149
|
-
|
150
|
-
#
|
151
|
-
#unless has_statement?(statement)
|
149
|
+
unless has_statement?(statement)
|
152
150
|
dump = dump_statement(statement)
|
153
151
|
post_data(dump, statement.context)
|
154
|
-
|
152
|
+
end
|
155
153
|
end
|
156
154
|
|
157
155
|
##
|
@@ -184,58 +182,84 @@ module RDF::FourStore
|
|
184
182
|
# @yield [statement]
|
185
183
|
# @yieldparam [Statement]
|
186
184
|
# @return [Enumerable<Statement>]
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
185
|
+
# def query(pattern, &block)
|
186
|
+
# case pattern
|
187
|
+
# when RDF::Statement
|
188
|
+
# h = {
|
189
|
+
# :subject => pattern.subject || :s,
|
190
|
+
# :predicate => pattern.predicate || :p,
|
191
|
+
# :object => pattern.object || :o,
|
192
|
+
# :context => pattern.context || nil
|
193
|
+
# }
|
194
|
+
# super(RDF::Query::Pattern.new(h), &block)
|
195
|
+
# when Array
|
196
|
+
# h = {
|
197
|
+
# :subject => pattern[0] || :s,
|
198
|
+
# :predicate => pattern[1] || :p,
|
199
|
+
# :object => pattern[2] || :o,
|
200
|
+
# :context => pattern[3] || nil
|
201
|
+
# }
|
202
|
+
# super(RDF::Query::Pattern.new(h), &block)
|
203
|
+
# when Hash
|
204
|
+
# pattern[:subject] ||= :s
|
205
|
+
# pattern[:predicate] ||= :p
|
206
|
+
# pattern[:object] ||= :o
|
207
|
+
# super(RDF::Query::Pattern.new(pattern), &block)
|
208
|
+
# else
|
209
|
+
# super(pattern, &block)
|
210
|
+
# end
|
211
|
+
# end
|
214
212
|
|
215
213
|
def query_pattern(pattern, &block)
|
216
|
-
|
214
|
+
pattern = pattern.dup
|
215
|
+
pattern.subject ||= RDF::Query::Variable.new
|
216
|
+
pattern.predicate ||= RDF::Query::Variable.new
|
217
|
+
pattern.object ||= RDF::Query::Variable.new
|
218
|
+
pattern.context ||= nil
|
217
219
|
str = pattern.to_s
|
218
|
-
q = "
|
220
|
+
q = ""
|
221
|
+
if pattern.context
|
222
|
+
q = "CONSTRUCT { #{str} } WHERE { GRAPH <#{pattern.context}> { #{str} } } "
|
223
|
+
else
|
224
|
+
q = "CONSTRUCT { #{str} } WHERE { #{str} } "
|
225
|
+
end
|
219
226
|
result = @client.query(q)
|
220
227
|
if result
|
221
228
|
if block_given?
|
222
229
|
result.each_statement(&block)
|
223
230
|
else
|
224
|
-
result
|
231
|
+
result.solutions.to_a.extend(RDF::Enumerable, RDF::Queryable)
|
225
232
|
end
|
226
233
|
end
|
227
234
|
end
|
228
235
|
|
236
|
+
##
|
237
|
+
# Makes a RDF string from a RDF Statement
|
238
|
+
#
|
239
|
+
# @param [RDF::Statement] statement
|
240
|
+
# @return [String]
|
229
241
|
def dump_statement(statement)
|
230
242
|
dump_statements([statement])
|
231
243
|
end
|
232
|
-
|
244
|
+
|
245
|
+
##
|
246
|
+
# Makes a RDF string from RDF Statements
|
247
|
+
# Blank nodes are quoted to be used as constants in queries
|
248
|
+
#
|
249
|
+
# @param [Array(RDF::Statement)] statements
|
250
|
+
# @return [String]
|
251
|
+
# @see http://4store.org/presentations/bbc-2009-09-21/slides.html#(38)
|
233
252
|
def dump_statements(statements)
|
234
253
|
graph = RDF::Graph.new
|
235
254
|
graph.insert_statements(statements)
|
236
|
-
RDF::Writer.for(:ntriples).dump(graph)
|
255
|
+
dump = RDF::Writer.for(:ntriples).dump(graph)
|
256
|
+
dump.gsub(/(_:\w+?) /, "<#{DEFAULT_CONTEXT}\\1> ")
|
237
257
|
end
|
238
|
-
|
258
|
+
|
259
|
+
##
|
260
|
+
# Uploads a RDF string to a repository
|
261
|
+
# @param [String] content
|
262
|
+
# @param [String] context
|
239
263
|
def post_data(content, context = nil)
|
240
264
|
context ||= DEFAULT_CONTEXT
|
241
265
|
uri = URI.parse(@dataURI)
|
@@ -252,13 +276,17 @@ module RDF::FourStore
|
|
252
276
|
end
|
253
277
|
end
|
254
278
|
|
255
|
-
|
279
|
+
##
|
280
|
+
# Sends a SPARUL query to update content in a repository
|
281
|
+
# @param [String] query
|
282
|
+
# @param [String] context
|
283
|
+
def post_update(query, context = nil)
|
256
284
|
context ||= DEFAULT_CONTEXT
|
257
285
|
uri = URI.parse(@updateURI)
|
258
286
|
|
259
287
|
req = Net::HTTP::Post.new(uri.path)
|
260
288
|
req.form_data = {
|
261
|
-
'update' =>
|
289
|
+
'update' => query,
|
262
290
|
'graph' => context,
|
263
291
|
'content-type' => 'triples',
|
264
292
|
}
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-4store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 29
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Fumihiro Kato
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-12-09 00:00:00 +09:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
- 2
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 27
|
46
43
|
segments:
|
47
44
|
- 1
|
48
45
|
- 3
|
@@ -58,7 +55,6 @@ dependencies:
|
|
58
55
|
requirements:
|
59
56
|
- - ">="
|
60
57
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 19
|
62
58
|
segments:
|
63
59
|
- 0
|
64
60
|
- 2
|
@@ -74,7 +70,6 @@ dependencies:
|
|
74
70
|
requirements:
|
75
71
|
- - ">="
|
76
72
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 5
|
78
73
|
segments:
|
79
74
|
- 1
|
80
75
|
- 4
|
@@ -90,7 +85,6 @@ dependencies:
|
|
90
85
|
requirements:
|
91
86
|
- - ">="
|
92
87
|
- !ruby/object:Gem::Version
|
93
|
-
hash: 23
|
94
88
|
segments:
|
95
89
|
- 0
|
96
90
|
- 0
|
@@ -114,7 +108,7 @@ files:
|
|
114
108
|
- lib/rdf/4store.rb
|
115
109
|
- lib/rdf/four_store/repository.rb
|
116
110
|
- lib/rdf/four_store/version.rb
|
117
|
-
has_rdoc:
|
111
|
+
has_rdoc: false
|
118
112
|
homepage: http://github.com/fumi/rdf-4store
|
119
113
|
licenses:
|
120
114
|
- Public Domain
|
@@ -128,7 +122,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
122
|
requirements:
|
129
123
|
- - ">="
|
130
124
|
- !ruby/object:Gem::Version
|
131
|
-
hash: 57
|
132
125
|
segments:
|
133
126
|
- 1
|
134
127
|
- 8
|
@@ -139,7 +132,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
132
|
requirements:
|
140
133
|
- - ">="
|
141
134
|
- !ruby/object:Gem::Version
|
142
|
-
hash: 3
|
143
135
|
segments:
|
144
136
|
- 0
|
145
137
|
version: "0"
|