activerdf_net7 1.6.16 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +63 -0
- data/activerdf-jena/lib/activerdf_jena/jena.rb +4 -4
- data/activerdf-jena/lib/activerdf_jena/jena_adapter.rb +55 -55
- data/activerdf-jena/lib/activerdf_jena/lucene.rb +1 -1
- data/activerdf-jena/lib/activerdf_jena/ng4j.rb +7 -7
- data/activerdf-jena/lib/activerdf_jena/ng4j_adapter.rb +47 -47
- data/activerdf-jena/lib/activerdf_jena/pellet.rb +1 -1
- data/activerdf-jena/test/test_jena_adapter.rb +121 -120
- data/activerdf-jena/test/test_ng4j_adapter.rb +111 -110
- data/activerdf-rdflite/lib/activerdf_rdflite/fetching.rb +23 -19
- data/activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb +153 -277
- data/activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb +2 -2
- data/activerdf-rdflite/test/test_fetching.rb +7 -22
- data/activerdf-rdflite/test/test_rdflite.rb +44 -257
- data/activerdf-redland/lib/activerdf_redland/redland.rb +246 -282
- data/activerdf-redland/test/test_redland_adapter.rb +62 -224
- data/activerdf-sesame/ext/wrapper-sesame2.jar +0 -0
- data/activerdf-sesame/java/build.number +2 -2
- data/activerdf-sesame/java/build.xml +0 -0
- data/activerdf-sesame/java/lib/junit-3.8.2.jar +0 -0
- data/activerdf-sesame/java/settings.xml +0 -0
- data/activerdf-sesame/java/src/org/activerdf/wrapper/sesame2/WrapperForSesame2.java +0 -0
- data/activerdf-sesame/java/temp/build/org/activerdf/wrapper/sesame2/WrapperForSesame2.class +0 -0
- data/activerdf-sesame/java/temp/manifest/MANIFEST.MF +2 -2
- data/activerdf-sesame/java/test-src/org/activerdf/wrapper/sesame2/TestWrapperForSesame2.java +0 -0
- data/activerdf-sesame/lib/activerdf_sesame/sesame.rb +360 -364
- data/activerdf-sesame/test/test_sesame_adapter.rb +85 -83
- data/activerdf-sparql/lib/activerdf_sparql/sparql.rb +147 -148
- data/activerdf-sparql/lib/activerdf_sparql/sparql_result_parser.rb +5 -5
- data/activerdf-sparql/test/test_sparql_adapter.rb +2 -0
- data/activerdf-yars/lib/activerdf_yars/jars2.rb +85 -83
- data/lib/active_rdf/federation/active_rdf_adapter.rb +26 -39
- data/lib/active_rdf/federation/connection_pool.rb +119 -110
- data/lib/active_rdf/federation/federation_manager.rb +51 -51
- data/lib/active_rdf/objectmanager/bnode.rb +8 -2
- data/lib/active_rdf/objectmanager/literal.rb +81 -50
- data/lib/active_rdf/objectmanager/namespace.rb +117 -84
- data/lib/active_rdf/objectmanager/object_manager.rb +101 -96
- data/lib/active_rdf/objectmanager/ordered_set.rb +1 -1
- data/lib/active_rdf/objectmanager/property.rb +345 -0
- data/lib/active_rdf/objectmanager/property_list.rb +4 -4
- data/lib/active_rdf/objectmanager/property_lookup.rb +57 -0
- data/lib/active_rdf/objectmanager/resource.rb +293 -501
- data/lib/active_rdf/objectmanager/resource_like.rb +2 -2
- data/lib/active_rdf/objectmanager/resource_query.rb +85 -0
- data/lib/active_rdf/queryengine/ntriples_parser.rb +75 -68
- data/lib/active_rdf/queryengine/query.rb +237 -183
- data/lib/active_rdf/queryengine/query2jars2.rb +17 -15
- data/lib/active_rdf/queryengine/query2sparql.rb +107 -101
- data/lib/active_rdf.rb +28 -17
- data/lib/active_rdf_helpers.rb +37 -5
- data/lib/active_rdf_log.rb +11 -11
- data/test/adapters/test_activerdf_adapter.rb +138 -0
- data/test/{test_adapters.rb → adapters/test_adapters.rb} +6 -24
- data/test/adapters/test_bnode_capable_adapter.rb +31 -0
- data/test/adapters/test_context_aware_adapter.rb +31 -0
- data/test/adapters/test_network_aware_adapter.rb +29 -0
- data/test/adapters/test_persistent_adapter.rb +21 -0
- data/test/adapters/test_read_only_adapter.rb +15 -0
- data/test/adapters/test_reasoning_adapter.rb +11 -0
- data/test/adapters/test_writable_adapter.rb +163 -0
- data/test/common.rb +78 -96
- data/test/federation/test_connection_pool.rb +25 -44
- data/test/federation/test_federation_manager.rb +45 -45
- data/test/objectmanager/test_literal.rb +47 -26
- data/test/objectmanager/test_namespace.rb +3 -1
- data/test/objectmanager/test_object_manager.rb +35 -45
- data/test/objectmanager/test_ordered_set.rb +1 -1
- data/test/objectmanager/test_property.rb +261 -0
- data/test/objectmanager/test_resource_reading.rb +196 -104
- data/test/objectmanager/test_resource_reasoning.rb +26 -0
- data/test/objectmanager/test_resource_writing.rb +34 -25
- data/test/queryengine/my_external_resource.rb +5 -1
- data/test/queryengine/test_external_resource_class.rb +1 -8
- data/test/queryengine/test_ntriples_parser.rb +5 -3
- data/test/queryengine/test_query.rb +3 -3
- data/test/queryengine/test_query2jars2.rb +2 -2
- data/test/queryengine/test_query2sparql.rb +2 -2
- data/test/queryengine/test_query_engine.rb +46 -28
- metadata +16 -8
- data/activerdf-rdflite/test/test_bnode_data.nt +0 -5
- data/activerdf-rdflite/test/test_data.nt +0 -32
- data/activerdf-rdflite/test/test_escaped_data.nt +0 -2
- data/activerdf-redland/test/test_person_data.nt +0 -42
- data/test/objectmanager/test_talia_syntax.rb +0 -68
@@ -14,8 +14,9 @@ require "pp"
|
|
14
14
|
require "fileutils"
|
15
15
|
|
16
16
|
class TestNG4JAdapter < Test::Unit::TestCase
|
17
|
+
include ActiveRDF
|
17
18
|
|
18
|
-
def setup
|
19
|
+
def setup
|
19
20
|
@adapter = ConnectionPool.add_data_source(:type => :ng4j)
|
20
21
|
@eyal = RDFS::Resource.new 'http://eyaloren.org'
|
21
22
|
@age = RDFS::Resource.new 'foaf:age'
|
@@ -31,106 +32,106 @@ class TestNG4JAdapter < Test::Unit::TestCase
|
|
31
32
|
@adapter.close
|
32
33
|
# ConnectionPool.clear
|
33
34
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
|
36
|
+
|
37
|
+
|
37
38
|
def test_load_no_args
|
38
39
|
adapter = ConnectionPool.add_data_source(:type => :ng4j)
|
39
40
|
assert_instance_of NG4JAdapter, adapter
|
40
41
|
end
|
41
|
-
|
42
|
-
|
42
|
+
|
43
|
+
|
43
44
|
def test_retrieve_a_triple_with_only_uris
|
44
|
-
|
45
|
+
|
45
46
|
assert_instance_of NG4JAdapter, @adapter
|
46
|
-
|
47
|
+
|
47
48
|
@adapter.add(@eyal, @age, @test)
|
48
49
|
result = Query.new.distinct(:o).where(@eyal, :p, :o).execute
|
49
50
|
assert_equal 1, result.flatten.size
|
50
|
-
|
51
|
+
|
51
52
|
result = Query.new.distinct(:p, :o).where(@eyal, :p, :o).execute
|
52
53
|
assert_equal 2, result.flatten.size
|
53
|
-
|
54
|
+
|
54
55
|
result = Query.new.distinct(:o).where(@eyal, @age, :o).execute
|
55
56
|
assert_equal 1, result.flatten.size
|
56
|
-
|
57
|
+
|
57
58
|
result = Query.new.distinct(:s).where(:s, @age, @test).execute
|
58
59
|
assert_equal 1, result.flatten.size
|
59
|
-
|
60
|
+
|
60
61
|
result = Query.new.distinct(:p).where(@eyal, :p, @test).execute
|
61
62
|
assert_equal 1, result.flatten.size
|
62
|
-
|
63
|
+
|
63
64
|
end
|
64
|
-
|
65
|
+
|
65
66
|
def test_retrieve_a_triple_with_string
|
66
|
-
|
67
|
+
|
67
68
|
assert_instance_of NG4JAdapter, @adapter
|
68
|
-
|
69
|
+
|
69
70
|
@adapter.add(@eyal, @mbox, @mboxval)
|
70
71
|
result = Query.new.distinct(:o).where(@eyal, :p, :o).execute
|
71
72
|
assert_equal 1, result.flatten.size
|
72
|
-
|
73
|
+
|
73
74
|
result = Query.new.distinct(:p, :o).where(@eyal, :p, :o).execute
|
74
75
|
assert_equal 2, result.flatten.size
|
75
|
-
|
76
|
+
|
76
77
|
result = Query.new.distinct(:o).where(@eyal, @mbox, :o).execute
|
77
78
|
assert_equal 1, result.flatten.size
|
78
|
-
|
79
|
+
|
79
80
|
result = Query.new.distinct(:s).where(:s, @mbox, @mboxval).execute
|
80
81
|
assert_equal 1, result.flatten.size
|
81
|
-
|
82
|
+
|
82
83
|
result = Query.new.distinct(:p).where(@eyal, :p, @mboxval).execute
|
83
84
|
assert_equal 1, result.flatten.size
|
84
|
-
|
85
|
+
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
def test_retrieve_a_triple_with_fixnum
|
88
|
-
|
89
|
+
|
89
90
|
assert_instance_of NG4JAdapter, @adapter
|
90
|
-
|
91
|
+
|
91
92
|
@adapter.add(@eyal, @age, @ageval)
|
92
93
|
result = Query.new.distinct(:o).where(@eyal, :p, :o).execute
|
93
94
|
assert_equal 1, result.flatten.size
|
94
|
-
|
95
|
+
|
95
96
|
result = Query.new.distinct(:p, :o).where(@eyal, :p, :o).execute
|
96
97
|
assert_equal 2, result.flatten.size
|
97
|
-
|
98
|
+
|
98
99
|
result = Query.new.distinct(:o).where(@eyal, @age, :o).execute
|
99
100
|
assert_equal 1, result.flatten.size
|
100
|
-
|
101
|
+
|
101
102
|
result = Query.new.distinct(:s).where(:s, @age, @ageval).execute
|
102
103
|
assert_equal 1, result.flatten.size
|
103
|
-
|
104
|
+
|
104
105
|
result = Query.new.distinct(:p).where(@eyal, :p, @ageval).execute
|
105
106
|
assert_equal 1, result.flatten.size
|
106
|
-
|
107
|
+
|
107
108
|
end
|
108
|
-
|
109
|
+
|
109
110
|
def test_remove
|
110
111
|
@adapter.add(@eyal, @age, @ageval)
|
111
112
|
@adapter.add(@eyal, @mbox, @mboxval)
|
112
113
|
@adapter.delete(@eyal, @age, @ageval)
|
113
114
|
assert_equal 1, @adapter.size
|
114
|
-
|
115
|
-
|
115
|
+
|
116
|
+
|
116
117
|
@adapter.add(@eyal, @age, @ageval)
|
117
118
|
@adapter.add(@eyal, @mbox, @mboxval)
|
118
119
|
@adapter.delete(:s, :p, @ageval)
|
119
120
|
assert_equal 1, @adapter.size
|
120
|
-
|
121
|
+
|
121
122
|
@adapter.add(@eyal, @age, @ageval)
|
122
123
|
@adapter.add(@eyal, @mbox, @mboxval)
|
123
124
|
@adapter.delete(:s, @age, :o)
|
124
125
|
assert_equal 1, @adapter.size
|
125
|
-
|
126
|
+
|
126
127
|
@adapter.add(@eyal, @age, @ageval)
|
127
128
|
@adapter.add(@eyal, @mbox, @mboxval)
|
128
129
|
@adapter.delete(@eyal, :p, :o)
|
129
130
|
assert_equal 0, @adapter.size
|
130
131
|
end
|
131
|
-
|
132
|
+
|
132
133
|
# now tests with quads ----------------------------------------
|
133
|
-
|
134
|
+
|
134
135
|
def test_simple_add_and_remove_quad_of_uris
|
135
136
|
assert_equal 0, @adapter.size
|
136
137
|
@adapter.add(@eyal, @mbox, @mboxval, @context)
|
@@ -138,117 +139,117 @@ class TestNG4JAdapter < Test::Unit::TestCase
|
|
138
139
|
@adapter.delete(@eyal, @mbox, @mboxval, @context)
|
139
140
|
assert_equal 0, @adapter.size
|
140
141
|
end
|
141
|
-
|
142
|
+
|
142
143
|
def test_wildcard_add_and_remove_quad_of_uris
|
143
144
|
assert_equal 0, @adapter.size
|
144
145
|
@adapter.add(@eyal, @mbox, @mboxval, @context)
|
145
146
|
assert_equal 1, @adapter.size
|
146
147
|
@adapter.add(@eyal, @mbox, @mboxval)
|
147
|
-
assert_equal 2, @adapter.size
|
148
|
+
assert_equal 2, @adapter.size
|
148
149
|
@adapter.delete(:s, :p, :o, @context)
|
149
|
-
assert_equal 1, @adapter.size
|
150
|
+
assert_equal 1, @adapter.size
|
150
151
|
@adapter.add(@eyal, @mbox, @mboxval, @context2)
|
151
|
-
assert_equal 2, @adapter.size
|
152
|
+
assert_equal 2, @adapter.size
|
152
153
|
@adapter.add(@eyal, @mbox, @mboxval, @context)
|
153
|
-
assert_equal 3, @adapter.size
|
154
|
+
assert_equal 3, @adapter.size
|
154
155
|
@adapter.delete(@eyal, @mbox, @mboxval)
|
155
|
-
assert_equal 2, @adapter.size
|
156
|
+
assert_equal 2, @adapter.size
|
156
157
|
@adapter.delete(@eyal, @mbox, @mboxval, :c)
|
157
158
|
assert_equal 0, @adapter.size
|
158
159
|
end
|
159
|
-
|
160
|
+
|
160
161
|
def test_query_with_quads
|
161
162
|
lit1 = Literal.new(1)
|
162
163
|
lit2 = Literal.new("cat", "@en")
|
163
164
|
lit3 = Literal.new( "dog" , RDFS::Resource.new("http://www.w3.org/2001/XMLSchema#string"))
|
164
165
|
# TODO: if this is ..#stringy then it gets returned as ..#string. Whats happening there?
|
165
|
-
|
166
|
+
|
166
167
|
@adapter.add(@eyal, @mbox, lit1, @context)
|
167
168
|
@adapter.add(@eyal, @mbox, lit2, @context2)
|
168
169
|
@adapter.add(@eyal, @mbox, lit3)
|
169
|
-
assert_equal 3, @adapter.size
|
170
|
-
|
170
|
+
assert_equal 3, @adapter.size
|
171
|
+
|
171
172
|
res1 = Query.new.distinct(:o).where(@eyal, @mbox, :o, @context).execute(:flatten => true)
|
172
173
|
assert_equal lit1.value, res1.value
|
173
174
|
assert_equal lit1.type.uri, res1.type.uri
|
174
|
-
|
175
|
+
|
175
176
|
res2 = Query.new.distinct(:o).where(@eyal, @mbox, :o, @context2).execute(:flatten => true)
|
176
177
|
assert_equal lit2.value, res2.value
|
177
178
|
assert_equal lit2.language, res2.language
|
178
|
-
|
179
|
+
|
179
180
|
res3 = Query.new.distinct(:o).where(@eyal, @mbox, :o).execute(:flatten => true)
|
180
181
|
assert_equal 3, res3.size
|
181
|
-
|
182
|
+
|
182
183
|
res4 = Query.new.distinct(:c).where(@eyal, @mbox, :o, :c).execute(:flatten => true)
|
183
184
|
assert_equal 3, res4.size
|
184
|
-
|
185
|
+
|
185
186
|
res5 = Query.new.distinct(:o).where(@eyal, @mbox, :o, :c).execute(:flatten => true)
|
186
187
|
assert_equal 3, res5.size
|
187
188
|
end
|
188
|
-
|
189
|
+
|
189
190
|
# -------------------------------------------------------------
|
190
|
-
|
191
|
-
|
191
|
+
|
192
|
+
|
192
193
|
def test_dump
|
193
194
|
@adapter.add(@eyal, @age, @test)
|
194
|
-
|
195
|
-
stringDump = @adapter.dump
|
196
|
-
|
195
|
+
|
196
|
+
stringDump = @adapter.dump
|
197
|
+
|
197
198
|
assert_not_nil stringDump
|
198
199
|
assert_kind_of String, stringDump
|
199
200
|
end
|
200
|
-
|
201
|
+
|
201
202
|
def test_size
|
202
203
|
@adapter.add(@eyal, @age, @test)
|
203
|
-
|
204
|
-
assert 0 < @adapter.size
|
204
|
+
|
205
|
+
assert 0 < @adapter.size
|
205
206
|
end
|
206
|
-
|
207
|
+
|
207
208
|
def test_clear
|
208
209
|
@adapter.add(@eyal, @age, @test)
|
209
|
-
assert 0 < @adapter.size
|
210
|
-
|
210
|
+
assert 0 < @adapter.size
|
211
|
+
|
211
212
|
@adapter.clear
|
212
|
-
assert_equal 0, @adapter.size
|
213
|
-
end
|
214
|
-
|
215
|
-
|
213
|
+
assert_equal 0, @adapter.size
|
214
|
+
end
|
215
|
+
|
216
|
+
|
216
217
|
# may seem redundant, but nonetheless this is needed
|
217
218
|
# TODO: find out why this does not raise errors..
|
218
|
-
def test_close
|
219
|
-
|
219
|
+
def test_close
|
220
|
+
|
220
221
|
@adapter.close
|
221
|
-
|
222
|
+
|
222
223
|
my_adapter = ConnectionPool.add_data_source(:type => :jena, :ontology => :rdfs)
|
223
224
|
my_adapter.add(@eyal, @age, @test)
|
224
225
|
results = Query.new.select(:s,:p,:o).where(:s,:p,:o).execute
|
225
226
|
assert results.flatten.size > 0
|
226
|
-
|
227
|
+
|
227
228
|
my_adapter.close
|
228
229
|
# assert_raises ActiveRdfError do
|
229
230
|
# results = Query.new.select(:s,:p,:o).where(:s,:p,:o).execute
|
230
231
|
# end
|
231
|
-
|
232
|
+
|
232
233
|
my_adapter = ConnectionPool.add_data_source(:type => :jena, :ontology => :rdfs)
|
233
234
|
my_adapter.add(@eyal, @age, @test)
|
234
235
|
results = Query.new.select(:s,:p,:o).where(:s,:p,:o).execute
|
235
236
|
assert results.flatten.size > 0
|
236
|
-
|
237
|
+
|
237
238
|
my_adapter.close
|
238
239
|
# assert_raises ActiveRdfError do
|
239
240
|
# results = Query.new.select(:s,:p,:o).where(:s,:p,:o).execute
|
240
241
|
# end
|
241
242
|
end
|
242
|
-
|
243
|
-
|
243
|
+
|
244
|
+
|
244
245
|
def test_load_ntriples
|
245
246
|
assert_equal 0, @adapter.size
|
246
|
-
|
247
|
+
|
247
248
|
this_dir = File.dirname(File.expand_path(__FILE__))
|
248
249
|
@adapter.load("file://" + this_dir + "/eyal-foaf.nt", :format => :ntriples, :into => :default_model)
|
249
|
-
|
250
|
+
|
250
251
|
assert_not_equal 0, @adapter.size
|
251
|
-
|
252
|
+
|
252
253
|
#check for <https://launchpad.net/products/browserdf/+rdf> <http://xmlns.com/foaf/0.1/name> "BrowseRDF" .
|
253
254
|
project_browserdf = RDFS::Resource.new("https://launchpad.net/products/browserdf/+rdf")
|
254
255
|
foaf_name = RDFS::Resource.new("http://xmlns.com/foaf/0.1/name")
|
@@ -256,92 +257,92 @@ class TestNG4JAdapter < Test::Unit::TestCase
|
|
256
257
|
assert_equal 1, result.flatten.size
|
257
258
|
assert_equal "BrowseRDF", result[0].value
|
258
259
|
end
|
259
|
-
|
260
|
+
|
260
261
|
def test_load_rdf_xml
|
261
262
|
assert_equal 0, @adapter.size
|
262
|
-
|
263
|
+
|
263
264
|
this_dir = File.dirname(File.expand_path(__FILE__))
|
264
265
|
@adapter.load("file://" + this_dir + "/bnode_org_rss.rdf", :format => :rdfxml, :into => :default_model)
|
265
|
-
|
266
|
+
|
266
267
|
assert_not_equal 0, @adapter.size
|
267
|
-
|
268
|
+
|
268
269
|
a_post = RDFS::Resource.new("http://bnode.org/blog/2007/05/29/semantic-web-gets-a-mention-in-visual-x-mag-webinale-report")
|
269
270
|
rss_title = RDFS::Resource.new("http://purl.org/rss/1.0/title")
|
270
|
-
|
271
|
+
|
271
272
|
result = Query.new.distinct(:o).where(a_post, rss_title, :o).execute
|
272
273
|
assert_equal 1, result.flatten.size
|
273
274
|
assert_equal "Semantic Web gets a mention in Visual-x mag webinale report", result[0].value
|
274
275
|
end
|
275
|
-
|
276
|
+
|
276
277
|
def test_load_n3
|
277
278
|
assert_equal 0, @adapter.size
|
278
|
-
|
279
|
+
|
279
280
|
this_dir = File.dirname(File.expand_path(__FILE__))
|
280
281
|
@adapter.load("file://" + this_dir + "/s1.n3", :format => :n3)
|
281
282
|
#:into => :default_model)
|
282
|
-
|
283
|
+
|
283
284
|
assert_not_equal 0, @adapter.size
|
284
|
-
|
285
|
+
|
285
286
|
transy = RDFS::Resource.new("http://www.daml.org/2001/03/daml+oil#TransitiveProperty")
|
286
287
|
rdf_type = RDFS::Resource.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
|
287
288
|
result = Query.new.distinct(:s, :c).where(:s, rdf_type, transy, :c).execute
|
288
|
-
assert_equal 6, result.flatten.size
|
289
|
-
|
289
|
+
assert_equal 6, result.flatten.size
|
290
|
+
|
290
291
|
result2 = Query.new.distinct(:s).where(:s, rdf_type, transy).execute
|
291
|
-
assert_equal 3, result2.flatten.size
|
292
|
-
end
|
293
|
-
|
292
|
+
assert_equal 3, result2.flatten.size
|
293
|
+
end
|
294
|
+
|
294
295
|
def test_keyword_search
|
295
296
|
@adapter.close
|
296
|
-
|
297
|
+
|
297
298
|
this_dir = File.dirname(File.expand_path(__FILE__))
|
298
299
|
keyword_adapter = ConnectionPool.add_data_source(:type => :jena, :model => "superfunky", :lucene => true)
|
299
|
-
|
300
|
+
|
300
301
|
keyword_adapter.load("file://" + this_dir + "/test_data.nt", :format => :ntriples, :into => :default_model )
|
301
|
-
|
302
|
+
|
302
303
|
eyal = RDFS::Resource.new('http://activerdf.org/test/eyal')
|
303
|
-
|
304
|
+
|
304
305
|
assert keyword_adapter.keyword_search?
|
305
|
-
|
306
|
+
|
306
307
|
assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"blue").execute(:flatten => true)
|
307
308
|
assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"27").execute(:flatten => true)
|
308
309
|
assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"eyal oren").execute(:flatten => true)
|
309
|
-
|
310
|
+
|
310
311
|
keyword_adapter.close
|
311
312
|
end
|
312
|
-
|
313
|
+
|
313
314
|
def test_hsql_embedded_persistence
|
314
315
|
@adapter.close
|
315
316
|
this_dir = File.dirname(File.expand_path(__FILE__))
|
316
|
-
|
317
|
-
hsql1 = ConnectionPool.add_data_source(:type => :ng4j,
|
317
|
+
|
318
|
+
hsql1 = ConnectionPool.add_data_source(:type => :ng4j,
|
318
319
|
:database => {:url => "jdbc:hsqldb:file:/" + this_dir + "/db1", :type => "hsql", :username => "sa", :password => ""})
|
319
|
-
|
320
|
+
|
320
321
|
hsql1.add(@eyal, @age, @ageval)
|
321
322
|
hsql1.add(@eyal, @mbox, @mboxval)
|
322
|
-
|
323
|
+
|
323
324
|
result = Query.new.distinct(:o).where(@eyal, :p, :o).execute
|
324
325
|
assert_equal 2, result.flatten.size
|
325
|
-
|
326
|
+
|
326
327
|
hsql1.close
|
327
328
|
ConnectionPool.clear
|
328
|
-
|
329
|
+
|
329
330
|
hsql2 = ConnectionPool.add_data_source(:type => :ng4j, :id => "2",
|
330
|
-
:database => {:url => "jdbc:hsqldb:file:/" + this_dir + "/db1", :type => "hsql", :username => "sa", :password => ""})
|
331
|
-
|
331
|
+
:database => {:url => "jdbc:hsqldb:file:/" + this_dir + "/db1", :type => "hsql", :username => "sa", :password => ""})
|
332
|
+
|
332
333
|
result = Query.new.distinct(:o).where(@eyal, :p, :o).execute
|
333
334
|
assert_equal 2, result.flatten.size
|
334
|
-
|
335
|
+
|
335
336
|
hsql2.close
|
336
|
-
|
337
|
+
|
337
338
|
# begin
|
338
339
|
# java.sql.DriverManager.getConnection("jdbc:derby:;shutdown=true")
|
339
340
|
# rescue java.sql.SQLException
|
340
341
|
# # expected
|
341
342
|
# end
|
342
|
-
# FileUtils.rm_rf(this_dir + "/superfunky")
|
343
|
+
# FileUtils.rm_rf(this_dir + "/superfunky")
|
343
344
|
end
|
344
|
-
|
345
|
+
|
345
346
|
|
346
347
|
# def test_explore_sparql
|
347
348
|
# puts Query2SPARQL.translate(Query.new.distinct(:s).
|
@@ -3,32 +3,36 @@
|
|
3
3
|
# License:: LGPL
|
4
4
|
|
5
5
|
# FetchingAdapter is an extension to rdflite for fetching RDF from online sources.
|
6
|
-
|
7
|
-
|
6
|
+
module ActiveRDF
|
7
|
+
class FetchingAdapter < RDFLite
|
8
|
+
ConnectionPool.register_adapter(:fetching, self)
|
8
9
|
|
9
|
-
|
10
|
+
# TODO: check that rapper is installed
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
# fetches RDF/XML data from given url and adds it to the datastore, using the
|
13
|
+
# source url as context identifier.
|
14
|
+
def fetch(url, syntax = nil)
|
15
|
+
# check if url starts with http://
|
16
|
+
return unless url.match(/http:\/\/(.*)/)
|
16
17
|
|
17
18
|
ActiveRdfLogger::log_debug(self) { "Fetching from #{url}" }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
#model = Redland::Model.new
|
21
|
+
#parser = Redland::Parser.new('rdfxml')
|
22
|
+
#scan = Redland::Uri.new('http://feature.librdf.org/raptor-scanForRDF')
|
23
|
+
#enable = Redland::Literal.new('1')
|
24
|
+
#Redland::librdf_parser_set_feature(parser, scan.uri, enable.node)
|
25
|
+
#parser.parse_into_model(model, url)
|
26
|
+
#triples = Redland::Serializer.ntriples.model_to_string(nil, model)
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
opts = syntax ? "-i #{syntax}" : "--scan"
|
29
|
+
triples = `rapper #{opts} --quiet "#{url}"`
|
30
|
+
lines = triples.split($/)
|
29
31
|
ActiveRdfLogger::log_debug(self) { "Found #{lines.size} triples" }
|
30
32
|
|
31
33
|
context = Query.resource_class.new(url)
|
32
|
-
|
34
|
+
add_ntriples(triples, context)
|
35
|
+
end
|
36
|
+
alias :load :fetch
|
33
37
|
end
|
34
|
-
end
|
38
|
+
end
|