grel 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/grel/base.rb +23 -23
- metadata +1 -1
data/lib/grel/base.rb
CHANGED
@@ -4,31 +4,31 @@ module GRel
|
|
4
4
|
|
5
5
|
include Stardog
|
6
6
|
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :connection, :last_query_context
|
8
8
|
attr_reader :db_name, :schema_graph
|
9
9
|
|
10
10
|
def initialize(endpoint, options)
|
11
11
|
@options = options
|
12
12
|
@endpoint = endpoint
|
13
|
-
@
|
13
|
+
@connection = stardog(endpoint,options)
|
14
14
|
@validations = options[:validate] || false
|
15
|
-
@dbs = @
|
15
|
+
@dbs = @connection.list_dbs.body["databases"]
|
16
16
|
@reasoning = false
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
20
20
|
def with_reasoning(reasoning="QL")
|
21
21
|
@reasoning = true
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
22
|
+
@connection = stardog(@endpoint,@options.merge(:reasoning => reasoning))
|
23
|
+
@connection.offline_db(@db_name)
|
24
|
+
@connection.set_db_options(@db_name, "icv.reasoning.type" => reasoning)
|
25
|
+
@connection.online_db(@db_name, 'WAIT')
|
26
26
|
self
|
27
27
|
end
|
28
28
|
|
29
29
|
def without_reasoning
|
30
30
|
@reasoning = false
|
31
|
-
@
|
31
|
+
@connection = stardog(@endpoint,@options)
|
32
32
|
self
|
33
33
|
end
|
34
34
|
|
@@ -56,7 +56,7 @@ module GRel
|
|
56
56
|
GRel::Debugger.debug QL.to_turtle(data)
|
57
57
|
GRel::Debugger.debug "IN"
|
58
58
|
GRel::Debugger.debug @db_name
|
59
|
-
@
|
59
|
+
@connection.add(@db_name, QL.to_turtle(data), nil, "text/turtle")
|
60
60
|
end
|
61
61
|
self
|
62
62
|
rescue Stardog::ICVException => ex
|
@@ -111,7 +111,7 @@ module GRel
|
|
111
111
|
GRel::Debugger.debug triples
|
112
112
|
GRel::Debugger.debug "IN"
|
113
113
|
GRel::Debugger.debug @db_name
|
114
|
-
@
|
114
|
+
@connection.add(@db_name, triples, @schema_graph, "text/turtle")
|
115
115
|
self
|
116
116
|
end
|
117
117
|
|
@@ -126,7 +126,7 @@ module GRel
|
|
126
126
|
GRel::Debugger.debug triples
|
127
127
|
GRel::Debugger.debug "IN"
|
128
128
|
GRel::Debugger.debug @db_name
|
129
|
-
@
|
129
|
+
@connection.remove(@db_name, triples, @schema_graph, "text/turtle")
|
130
130
|
self
|
131
131
|
end
|
132
132
|
|
@@ -148,7 +148,7 @@ module GRel
|
|
148
148
|
GRel::Debugger.debug triples
|
149
149
|
GRel::Debugger.debug "IN"
|
150
150
|
GRel::Debugger.debug @db_name
|
151
|
-
@
|
151
|
+
@connection.add_icv(@db_name, triples, "text/turtle")
|
152
152
|
self
|
153
153
|
end
|
154
154
|
|
@@ -161,7 +161,7 @@ module GRel
|
|
161
161
|
GRel::Debugger.debug triples
|
162
162
|
GRel::Debugger.debug "IN"
|
163
163
|
GRel::Debugger.debug @db_name
|
164
|
-
@
|
164
|
+
@connection.remove_icv(@db_name, triples, "text/turtle")
|
165
165
|
self
|
166
166
|
end
|
167
167
|
|
@@ -171,15 +171,15 @@ module GRel
|
|
171
171
|
GRel::Debugger.debug QL.to_turtle(data)
|
172
172
|
GRel::Debugger.debug "IN"
|
173
173
|
GRel::Debugger.debug @db_name
|
174
|
-
@
|
174
|
+
@connection.remove(@db_name, QL.to_turtle(data), nil, "text/turtle")
|
175
175
|
else
|
176
176
|
args = {:describe => true}
|
177
177
|
args = {:accept => "application/rdf+xml"}
|
178
178
|
|
179
179
|
sparql = @last_query_context.to_sparql_describe
|
180
|
-
triples = @
|
180
|
+
triples = @connection.query(@db_name,sparql, args).body
|
181
181
|
|
182
|
-
@
|
182
|
+
@connection.remove(@db_name, triples, nil, "application/rdf+xml")
|
183
183
|
end
|
184
184
|
self
|
185
185
|
end
|
@@ -244,7 +244,7 @@ module GRel
|
|
244
244
|
args[:accept] = options[:accept] if options[:accept]
|
245
245
|
args[:offset] = @last_query_context.offset if @last_query_context.offset
|
246
246
|
args[:limit] = @last_query_context.limit if @last_query_context.limit
|
247
|
-
@
|
247
|
+
@connection.query(@db_name,query, args).body
|
248
248
|
end
|
249
249
|
|
250
250
|
def run_tuples(query, options = {})
|
@@ -257,14 +257,14 @@ module GRel
|
|
257
257
|
args[:accept] = options[:accept] if options[:accept]
|
258
258
|
args[:offset] = @last_query_context.offset if @last_query_context.offset
|
259
259
|
args[:limit] = @last_query_context.limit if @last_query_context.limit
|
260
|
-
@
|
260
|
+
@connection.query(@db_name,query, args).body
|
261
261
|
end
|
262
262
|
|
263
263
|
def with_validations(state = true)
|
264
264
|
@validations = state
|
265
|
-
@
|
266
|
-
@
|
267
|
-
@
|
265
|
+
@connection.offline_db(@db_name)
|
266
|
+
@connection.set_db_options(@db_name, "icv.enabled" => @validations)
|
267
|
+
@connection.online_db(@db_name, 'WAIT')
|
268
268
|
|
269
269
|
self
|
270
270
|
end
|
@@ -277,8 +277,8 @@ module GRel
|
|
277
277
|
|
278
278
|
def ensure_db(db_name)
|
279
279
|
unless(@dbs.include?(db_name))
|
280
|
-
@
|
281
|
-
@
|
280
|
+
@connection.create_db(db_name, :options => { "reasoning.schema.graphs" => "#{db_name}:schema" })
|
281
|
+
@connection.with_validations(@validations) if @validations == true
|
282
282
|
@dbs << db_name
|
283
283
|
end
|
284
284
|
yield if block_given?
|