activerdf_sesame 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+
2
+ require "java"
3
+
4
+ URLClassLoader = java.net.URLClassLoader
5
+ JFile = java.io.File
6
+ JURL = java.net.URL
7
+ JClass = java.lang.Class
8
+ JObject = java.lang.Object
9
+
10
+ # make file objects out of strings
11
+ jFile1 = JFile.new("/someplace/wrapper-sesame2.jar")
12
+ jFile2 = JFile.new("/someplace/openrdf-sesame-2.0-alpha4-onejar.jar")
13
+
14
+ #jFile1 = JFile.new("/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/ext/wrapper-sesame2.jar")
15
+ #jFile2 = JFile.new("/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/ext/openrdf-sesame-2.0-alpha4-onejar.jar")
16
+
17
+ # make an array of URL, which contains the URLs corresponding to the files
18
+ uris = JURL[].new(2)
19
+ uris[0] = jFile1.toURL
20
+ uris[1] = jFile2.toURL
21
+
22
+ # this is our custom class loader, yay!
23
+ myClassLoader = URLClassLoader.new(uris)
24
+
25
+ # and now we want our custom class loader to actually do some work
26
+ # --> fetch us the class object for the specified class name,
27
+ # intialize that class object, and use the specified class loader for it
28
+ classWrapper = JClass.forName("org.activerdf.wrapper.sesame2.WrapperForSesame2", true, myClassLoader)
29
+
30
+ # cool, so we got that class object, and it seems pretty valid:
31
+ puts classWrapper.java_class
32
+ # => java.lang.Class
33
+
34
+ # put this does not work !
35
+ myWrapperInstance = classWrapper.new
36
+
37
+ # instead we have to do this. this points to the guess that this is in fact
38
+ # not a class object but a constuctor object
39
+ # maybe this is the first bug here?
40
+ myWrapperInstance = classWrapper.new_instance
41
+
42
+ # okay, so far so good. the real problem is constructing the class with an
43
+ # argument
44
+
45
+ constructorArgs = JObject[].new(1)
46
+ constructorArgs[0] = "/someplace/sesame-rep.s2"
47
+ #constuctorArgs[0] = "/home/metaman/workspaces/deri-workspace/sioc-playground/data/sesame-rep.s2"
48
+
49
+ myWrapperInstance = classWrapper.new_instance(constructorArgs)
50
+ # NameError: no method 'newInstance' with arguments matching [[Ljava.lang.Object;]
51
+ # from /mnt/small/jruby-workspace/jruby-trunk/src/builtin/javasupport.rb:433:in `matching_method'
52
+ # from (irb):1:in `binding'
53
+
54
+ # If I would have just said this:
55
+ # WrapperForSesame2 = org.activerdf.wrapper.sesame2.WrapperForSesame2
56
+ # then I could say:
57
+ # myWrapperInstance = WrapperForSesame2.new("/someplace/sesame-rep.s2")
58
+ # no problem there.
59
+
60
+ # --> this seems to be the second bug?
@@ -0,0 +1,322 @@
1
+ # Author:: Eyal Oren
2
+ # Copyright:: (c) 2005-2006
3
+ # License:: LGPL
4
+
5
+ require 'test/unit'
6
+ require 'rubygems'
7
+ require '../../lib/active_rdf.rb'
8
+ require 'pp'
9
+ #require 'active_rdf'
10
+ #require 'federation/federation_manager'
11
+ #require 'queryengine/query'
12
+
13
+
14
+ class TestSesameAdapter < Test::Unit::TestCase
15
+ # TODO maybe put more stuff into setup and teardown...
16
+ def setup
17
+ ConnectionPool.clear
18
+ end
19
+
20
+ def teardown
21
+ end
22
+
23
+ def test_registration
24
+ # puts "registration test"
25
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
26
+ assert_instance_of SesameAdapter, adapter
27
+ adapter.close
28
+ end
29
+
30
+ def test_equality
31
+ # puts "equality test"
32
+ adapter1 = ConnectionPool.add_data_source(:type => :sesame, :name => :funky)
33
+ adapter2 = ConnectionPool.add_data_source(:type => :sesame, :name => :groovy)
34
+ assert_not_equal adapter1, adapter2
35
+ adapter1.close
36
+ adapter2.close
37
+ end
38
+
39
+ def test_add_and_retrieve_triple_with_just_uris
40
+ # puts "uri retr test"
41
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
42
+
43
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
44
+ age = RDFS::Resource.new 'foaf:age'
45
+ test = RDFS::Resource.new 'test:test'
46
+
47
+ adapter.add(eyal, age, test)
48
+ # pp Query.new.select(:p, :o).where(eyal, :p, :o).execute
49
+ result = Query.new.distinct(:o).where(eyal, :p, :o).execute
50
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
51
+ assert_equal 2, result.flatten.size
52
+
53
+ result = Query.new.distinct(:p, :o).where(eyal, :p, :o).execute
54
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
55
+ assert_equal 4, result.flatten.size
56
+
57
+ result = Query.new.distinct(:o).where(eyal, age, :o).execute
58
+ assert_equal 1, result.flatten.size
59
+
60
+ result = Query.new.distinct(:s).where(:s, age, test).execute
61
+ assert_equal 1, result.flatten.size
62
+
63
+ result = Query.new.distinct(:p).where(eyal, :p, test).execute
64
+ assert_equal 1, result.flatten.size
65
+
66
+ adapter.close
67
+ end
68
+
69
+ def test_add_and_retrieve_triple_with_an_object_string
70
+ # puts "string retr test"
71
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
72
+
73
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
74
+ age = RDFS::Resource.new 'foaf:age'
75
+ test = "23"
76
+
77
+ adapter.add(eyal, age, test)
78
+
79
+ result = Query.new.distinct(:o).where(eyal, :p, :o).execute
80
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
81
+ assert_equal 2, result.flatten.size
82
+
83
+ result = Query.new.distinct(:p, :o).where(eyal, :p, :o).execute
84
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
85
+ assert_equal 4, result.flatten.size
86
+
87
+ result = Query.new.distinct(:o).where(eyal, age, :o).execute
88
+ assert_equal 1, result.flatten.size
89
+
90
+ result = Query.new.distinct(:s).where(:s, age, test).execute
91
+ assert_equal 1, result.flatten.size
92
+
93
+ result = Query.new.distinct(:p).where(eyal, :p, test).execute
94
+ assert_equal 1, result.flatten.size
95
+
96
+ adapter.close
97
+ end
98
+
99
+ def test_add_and_retrieve_triple_with_an_object_fixnum
100
+ # puts "fixnum retr test"
101
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
102
+
103
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
104
+ age = RDFS::Resource.new 'foaf:age'
105
+ test = 23
106
+
107
+ adapter.add(eyal, age, test)
108
+
109
+ result = Query.new.distinct(:o).where(eyal, :p, :o).execute
110
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
111
+ assert_equal 2, result.flatten.size
112
+
113
+ result = Query.new.distinct(:p, :o).where(eyal, :p, :o).execute
114
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
115
+ assert_equal 4, result.flatten.size
116
+
117
+ result = Query.new.distinct(:o).where(eyal, age, :o).execute
118
+ assert_equal 1, result.flatten.size
119
+
120
+ result = Query.new.distinct(:s).where(:s, age, test).execute
121
+ assert_equal 1, result.flatten.size
122
+
123
+ result = Query.new.distinct(:p).where(eyal, :p, test).execute
124
+ assert_equal 1, result.flatten.size
125
+
126
+ adapter.close
127
+ end
128
+
129
+ def test_dump
130
+ # puts "dump test"
131
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
132
+
133
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
134
+ age = RDFS::Resource.new 'foaf:age'
135
+ test = 23
136
+
137
+ adapter.add(eyal, age, test)
138
+
139
+ stringDump = adapter.dump
140
+
141
+ assert_not_nil stringDump
142
+ assert_kind_of String, stringDump
143
+ adapter.close
144
+ end
145
+
146
+ def test_size
147
+ # puts "site test"
148
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
149
+
150
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
151
+ age = RDFS::Resource.new 'foaf:age'
152
+ test = 23
153
+
154
+ adapter.add(eyal, age, test)
155
+
156
+ assert_equal 1, adapter.size
157
+ adapter.close
158
+ end
159
+
160
+ def test_clear
161
+ # puts "clear test"
162
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
163
+
164
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
165
+ age = RDFS::Resource.new 'foaf:age'
166
+ test = 23
167
+
168
+ adapter.add(eyal, age, test)
169
+ assert_equal 1, adapter.size
170
+
171
+ # calling this reveals an unclosed iterator over statements. maybe this is a bug in sesame2, unclear...
172
+ # TODO: maybe check this. dont know if this has a high impact
173
+ adapter.clear
174
+ assert_equal 0, adapter.size
175
+ adapter.close
176
+ end
177
+
178
+ def test_load
179
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
180
+
181
+ adapter.load("/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/eyal-foaf.nt")
182
+
183
+ assert_not_equal 0, adapter.size
184
+
185
+ # puts adapter.dump
186
+
187
+ adapter.close
188
+ end
189
+
190
+ def test_remove_basic
191
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
192
+
193
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
194
+ age = RDFS::Resource.new 'foaf:age'
195
+ test = 23
196
+
197
+ adapter.add(eyal, age, test)
198
+ assert_equal 1, adapter.size
199
+
200
+ adapter.delete(:s,:p,:o)
201
+ assert_equal 0, adapter.size
202
+
203
+ adapter.close
204
+ end
205
+
206
+ def test_remove_permutations
207
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
208
+
209
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
210
+ age = RDFS::Resource.new 'foaf:age'
211
+ test = 23
212
+
213
+ adapter.add(eyal, age, test)
214
+ assert_equal 1, adapter.size
215
+ adapter.delete(:s,:p,test)
216
+ assert_equal 0, adapter.size
217
+
218
+ adapter.add(eyal, age, test)
219
+ assert_equal 1, adapter.size
220
+ adapter.delete(:s,age,:o)
221
+ assert_equal 0, adapter.size
222
+
223
+ adapter.add(eyal, age, test)
224
+ assert_equal 1, adapter.size
225
+ adapter.delete(eyal,:p,:o)
226
+ assert_equal 0, adapter.size
227
+
228
+ adapter.close
229
+ end
230
+
231
+ def test_remove_different_objects
232
+ adapter = ConnectionPool.add_data_source(:type => :sesame)
233
+
234
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
235
+ age = RDFS::Resource.new 'foaf:age'
236
+ test_uri = RDFS::Resource.new 'test:test'
237
+ test_string = "maple cured ham"
238
+ test_fixnum = 42
239
+
240
+ adapter.add(eyal, age, test_uri)
241
+ adapter.add(eyal, age, test_string)
242
+ adapter.add(eyal, age, test_fixnum)
243
+ assert_equal 3, adapter.size
244
+ adapter.delete(:s,:p,test_uri)
245
+ assert_equal 2, adapter.size
246
+ adapter.delete(:s,:p,test_string)
247
+ assert_equal 1, adapter.size
248
+ adapter.delete(:s,:p,test_fixnum)
249
+ assert_equal 0, adapter.size
250
+
251
+ adapter.close
252
+ end
253
+
254
+ def test_initialization
255
+ adapter1 = ConnectionPool.add_data_source(:type => :sesame)
256
+ assert_instance_of SesameAdapter, adapter1
257
+ adapter1.close
258
+
259
+ adapter2 = ConnectionPool.add_data_source(:type => :sesame, :inferencing => true)
260
+ assert_instance_of SesameAdapter, adapter2
261
+ adapter2.close
262
+
263
+ adapter3 = ConnectionPool.add_data_source(:type => :sesame, :inferencing => false)
264
+ assert_instance_of SesameAdapter, adapter3
265
+ adapter3.close
266
+
267
+ adapter1 = ConnectionPool.add_data_source(:type => :sesame, :location => :memory)
268
+ assert_instance_of SesameAdapter, adapter1
269
+ adapter1.close
270
+
271
+ adapter2 = ConnectionPool.add_data_source(:type => :sesame, :inferencing => true, :location => :memory)
272
+ assert_instance_of SesameAdapter, adapter2
273
+ adapter2.close
274
+
275
+ adapter3 = ConnectionPool.add_data_source(:type => :sesame, :inferencing => false, :location => :memory)
276
+ assert_instance_of SesameAdapter, adapter3
277
+ adapter3.close
278
+ end
279
+
280
+ def test_persistence_basic
281
+ adapter1 = ConnectionPool.add_data_source(:type => :sesame, :location => "/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2")
282
+ assert_instance_of SesameAdapter, adapter1
283
+ adapter1.close
284
+ `rm /home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2`
285
+
286
+ adapter1 = ConnectionPool.add_data_source(:type => :sesame, :inferencing => false, :location => "/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2")
287
+ assert_instance_of SesameAdapter, adapter1
288
+ adapter1.close
289
+ `rm /home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2`
290
+
291
+ adapter2 = ConnectionPool.add_data_source(:type => :sesame, :inferencing => true, :location => "/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2")
292
+ assert_instance_of SesameAdapter, adapter2
293
+ adapter2.close
294
+ `rm /home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2`
295
+ end
296
+
297
+ def test_persistence_reloading
298
+ adapter = ConnectionPool.add_data_source(:type => :sesame, :location => "/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2")
299
+
300
+ eyal = RDFS::Resource.new 'http://eyaloren.org'
301
+ age = RDFS::Resource.new 'foaf:age'
302
+ test = 23
303
+
304
+ adapter.add(eyal, age, test)
305
+
306
+ result = Query.new.distinct(:o).where(eyal, :p, :o).execute
307
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
308
+ assert_equal 2, result.flatten.size
309
+
310
+ adapter.close
311
+ ConnectionPool.clear
312
+
313
+ adapter2 = ConnectionPool.add_data_source(:name => :second_one, :type => :sesame, :location => "/home/metaman/workspaces/deri-workspace/activerdf/activerdf-sesame/test/sesame-persistence.s2")
314
+
315
+ result = Query.new.distinct(:o).where(eyal, :p, :o).execute
316
+ # sesame does rdfs inferencing and writes into the store that eyal is a resource
317
+ assert_equal 2, result.flatten.size
318
+
319
+ adapter2.close
320
+ end
321
+
322
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ platform: ruby
3
+ files:
4
+ - ext/openrdf-sesame-2.0-alpha4-onejar.jar
5
+ - ext/wrapper-sesame2.jar
6
+ - LICENSE
7
+ - README
8
+ - Rakefile
9
+ - lib/activerdf_sesame/init.rb
10
+ - lib/activerdf_sesame/sesame.rb
11
+ - test/activerdf.log
12
+ - test/eyal-foaf.nt
13
+ - test/eyal-foaf.rdf
14
+ - test/finalize-test.rb
15
+ - test/pathname.rb
16
+ - test/sesame-init-test.rb
17
+ - test/sesame-persistence.s2
18
+ - test/test_URLClassLoader.rb
19
+ - test/test_sesame_adapter.rb
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - '>'
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ extensions: []
27
+ autorequire:
28
+ authors:
29
+ - Benjamin Heitmann <benjamin.heitmann@deri.org>
30
+ executables: []
31
+ description: an RDF database for usage in ActiveRDF (based on sesame2)
32
+ summary: an RDF database for usage in ActiveRDF (based on sesame2)
33
+ date: 2007-02-06 00:00:00 +00:00
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirement:
37
+ version_requirements: !ruby/object:Gem::Version::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 0.2.1
42
+ version:
43
+ name: gem_plugin
44
+ - !ruby/object:Gem::Dependency
45
+ version_requirement:
46
+ version_requirements: !ruby/object:Gem::Version::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: !str 1.2
51
+ version:
52
+ name: activerdf
53
+ email:
54
+ cert_chain:
55
+ post_install_message:
56
+ rubygems_version: 0.9.0
57
+ requirements: []
58
+ signing_key:
59
+ rubyforge_project:
60
+ test_files: []
61
+ version: !ruby/object:Gem::Version
62
+ version: !str 0.1
63
+ require_paths:
64
+ - lib
65
+ has_rdoc: true
66
+ bindir: bin
67
+ name: activerdf_sesame
68
+ homepage:
69
+ rdoc_options: []
70
+ extra_rdoc_files:
71
+ - README
72
+ default_executable:
73
+ specification_version: 1