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.
Files changed (85) hide show
  1. data/CHANGELOG +63 -0
  2. data/activerdf-jena/lib/activerdf_jena/jena.rb +4 -4
  3. data/activerdf-jena/lib/activerdf_jena/jena_adapter.rb +55 -55
  4. data/activerdf-jena/lib/activerdf_jena/lucene.rb +1 -1
  5. data/activerdf-jena/lib/activerdf_jena/ng4j.rb +7 -7
  6. data/activerdf-jena/lib/activerdf_jena/ng4j_adapter.rb +47 -47
  7. data/activerdf-jena/lib/activerdf_jena/pellet.rb +1 -1
  8. data/activerdf-jena/test/test_jena_adapter.rb +121 -120
  9. data/activerdf-jena/test/test_ng4j_adapter.rb +111 -110
  10. data/activerdf-rdflite/lib/activerdf_rdflite/fetching.rb +23 -19
  11. data/activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb +153 -277
  12. data/activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb +2 -2
  13. data/activerdf-rdflite/test/test_fetching.rb +7 -22
  14. data/activerdf-rdflite/test/test_rdflite.rb +44 -257
  15. data/activerdf-redland/lib/activerdf_redland/redland.rb +246 -282
  16. data/activerdf-redland/test/test_redland_adapter.rb +62 -224
  17. data/activerdf-sesame/ext/wrapper-sesame2.jar +0 -0
  18. data/activerdf-sesame/java/build.number +2 -2
  19. data/activerdf-sesame/java/build.xml +0 -0
  20. data/activerdf-sesame/java/lib/junit-3.8.2.jar +0 -0
  21. data/activerdf-sesame/java/settings.xml +0 -0
  22. data/activerdf-sesame/java/src/org/activerdf/wrapper/sesame2/WrapperForSesame2.java +0 -0
  23. data/activerdf-sesame/java/temp/build/org/activerdf/wrapper/sesame2/WrapperForSesame2.class +0 -0
  24. data/activerdf-sesame/java/temp/manifest/MANIFEST.MF +2 -2
  25. data/activerdf-sesame/java/test-src/org/activerdf/wrapper/sesame2/TestWrapperForSesame2.java +0 -0
  26. data/activerdf-sesame/lib/activerdf_sesame/sesame.rb +360 -364
  27. data/activerdf-sesame/test/test_sesame_adapter.rb +85 -83
  28. data/activerdf-sparql/lib/activerdf_sparql/sparql.rb +147 -148
  29. data/activerdf-sparql/lib/activerdf_sparql/sparql_result_parser.rb +5 -5
  30. data/activerdf-sparql/test/test_sparql_adapter.rb +2 -0
  31. data/activerdf-yars/lib/activerdf_yars/jars2.rb +85 -83
  32. data/lib/active_rdf/federation/active_rdf_adapter.rb +26 -39
  33. data/lib/active_rdf/federation/connection_pool.rb +119 -110
  34. data/lib/active_rdf/federation/federation_manager.rb +51 -51
  35. data/lib/active_rdf/objectmanager/bnode.rb +8 -2
  36. data/lib/active_rdf/objectmanager/literal.rb +81 -50
  37. data/lib/active_rdf/objectmanager/namespace.rb +117 -84
  38. data/lib/active_rdf/objectmanager/object_manager.rb +101 -96
  39. data/lib/active_rdf/objectmanager/ordered_set.rb +1 -1
  40. data/lib/active_rdf/objectmanager/property.rb +345 -0
  41. data/lib/active_rdf/objectmanager/property_list.rb +4 -4
  42. data/lib/active_rdf/objectmanager/property_lookup.rb +57 -0
  43. data/lib/active_rdf/objectmanager/resource.rb +293 -501
  44. data/lib/active_rdf/objectmanager/resource_like.rb +2 -2
  45. data/lib/active_rdf/objectmanager/resource_query.rb +85 -0
  46. data/lib/active_rdf/queryengine/ntriples_parser.rb +75 -68
  47. data/lib/active_rdf/queryengine/query.rb +237 -183
  48. data/lib/active_rdf/queryengine/query2jars2.rb +17 -15
  49. data/lib/active_rdf/queryengine/query2sparql.rb +107 -101
  50. data/lib/active_rdf.rb +28 -17
  51. data/lib/active_rdf_helpers.rb +37 -5
  52. data/lib/active_rdf_log.rb +11 -11
  53. data/test/adapters/test_activerdf_adapter.rb +138 -0
  54. data/test/{test_adapters.rb → adapters/test_adapters.rb} +6 -24
  55. data/test/adapters/test_bnode_capable_adapter.rb +31 -0
  56. data/test/adapters/test_context_aware_adapter.rb +31 -0
  57. data/test/adapters/test_network_aware_adapter.rb +29 -0
  58. data/test/adapters/test_persistent_adapter.rb +21 -0
  59. data/test/adapters/test_read_only_adapter.rb +15 -0
  60. data/test/adapters/test_reasoning_adapter.rb +11 -0
  61. data/test/adapters/test_writable_adapter.rb +163 -0
  62. data/test/common.rb +78 -96
  63. data/test/federation/test_connection_pool.rb +25 -44
  64. data/test/federation/test_federation_manager.rb +45 -45
  65. data/test/objectmanager/test_literal.rb +47 -26
  66. data/test/objectmanager/test_namespace.rb +3 -1
  67. data/test/objectmanager/test_object_manager.rb +35 -45
  68. data/test/objectmanager/test_ordered_set.rb +1 -1
  69. data/test/objectmanager/test_property.rb +261 -0
  70. data/test/objectmanager/test_resource_reading.rb +196 -104
  71. data/test/objectmanager/test_resource_reasoning.rb +26 -0
  72. data/test/objectmanager/test_resource_writing.rb +34 -25
  73. data/test/queryengine/my_external_resource.rb +5 -1
  74. data/test/queryengine/test_external_resource_class.rb +1 -8
  75. data/test/queryengine/test_ntriples_parser.rb +5 -3
  76. data/test/queryengine/test_query.rb +3 -3
  77. data/test/queryengine/test_query2jars2.rb +2 -2
  78. data/test/queryengine/test_query2sparql.rb +2 -2
  79. data/test/queryengine/test_query_engine.rb +46 -28
  80. metadata +16 -8
  81. data/activerdf-rdflite/test/test_bnode_data.nt +0 -5
  82. data/activerdf-rdflite/test/test_data.nt +0 -32
  83. data/activerdf-rdflite/test/test_escaped_data.nt +0 -2
  84. data/activerdf-redland/test/test_person_data.nt +0 -42
  85. data/test/objectmanager/test_talia_syntax.rb +0 -68
@@ -1,277 +1,64 @@
1
- å# Author:: Eyal Oren
1
+ # Author:: Eyal Oren
2
2
  # Copyright:: (c) 2005-2006
3
3
  # License:: LGPL
4
4
 
5
- require 'rubygems'
5
+ # require 'active_rdf'
6
6
  require 'test/unit'
7
7
  require 'active_rdf'
8
- require 'federation/federation_manager'
9
- require 'queryengine/query'
8
+ common_test_dir = File.dirname(File.expand_path(__FILE__)) + '/../../test'
9
+ require "#{common_test_dir}/adapters/test_persistent_adapter"
10
+ require "#{common_test_dir}/adapters/test_bnode_capable_adapter"
11
+ require "#{common_test_dir}/adapters/test_context_aware_adapter"
12
+ require "#{common_test_dir}/adapters/test_network_aware_adapter"
13
+ require "#{common_test_dir}/adapters/test_reasoning_adapter"
14
+
10
15
 
11
16
  class TestRdfLiteAdapter < Test::Unit::TestCase
12
- def setup
13
- ConnectionPool.clear
14
- end
17
+ include SetupAdapter
18
+ include TestNetworkAwareAdapter
19
+ include TestReasoningAdapter
15
20
 
16
- def teardown
21
+ def setup
22
+ super(:type => :rdflite)
17
23
  end
18
24
 
19
25
  def test_registration
20
- adapter = ConnectionPool.add_data_source(:type => :rdflite)
21
- assert_instance_of RDFLite, adapter
26
+ assert_instance_of RDFLite, @adapter
22
27
  end
23
28
 
24
29
  def test_initialise
25
- adapter = ConnectionPool.add_data_source(:type => :rdflite, :keyword => false)
26
- assert !adapter.keyword_search?
27
- end
28
-
29
- def test_duplicate_registration
30
- adapter1 = ConnectionPool.add_data_source(:type => :rdflite)
31
- adapter2 = ConnectionPool.add_data_source(:type => :rdflite)
32
-
33
- assert_equal adapter1, adapter2
34
- assert_equal adapter1.object_id, adapter2.object_id
35
- end
36
-
37
- def test_simple_query
38
- adapter = ConnectionPool.add_data_source(:type => :rdflite)
39
-
40
- eyal = RDFS::Resource.new 'eyaloren.org'
41
- age = RDFS::Resource.new 'foaf:age'
42
- test = RDFS::Resource.new 'test'
43
-
44
- adapter.add(eyal, age, test)
45
-
46
- result = Query.new.distinct(:s).where(:s, :p, :o).execute(:flatten => true)
47
- assert_instance_of RDFS::Resource, result
48
- assert_equal 'eyaloren.org', result.uri
49
- end
50
-
51
- def test_escaped_literals
52
- adapter = ConnectionPool.add_data_source(:type => :rdflite)
53
- eyal = RDFS::Resource.new 'eyal'
54
- comment = RDFS::Resource.new 'comment'
55
- string = 'test\nbreak\"quoted\"'
56
- interpreted = "test\nbreak\"quoted\""
57
-
58
- adapter.add(eyal, comment, string)
59
- assert_equal interpreted, eyal.comment
60
-
61
- description = RDFS::Resource.new 'description'
62
- string = 'ümlaut and \u00ebmlaut'
63
- interpreted = "ümlaut and ëmlaut"
64
-
65
- adapter.add(eyal, description, string)
66
- assert_equal interpreted, eyal.description
67
- end
68
-
69
- def test_load_escaped_literals
70
- adapter = ConnectionPool.add_data_source(:type => :rdflite)
71
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_escaped_data.nt')
72
- eyal = RDFS::Resource.new('http://activerdf.org/test/eyal')
73
-
74
- assert_equal 2, adapter.size
75
- assert_equal "ümlauts and ëmlauts", eyal.comment
76
- assert_equal "line\nbreaks, <p>'s and \"quotes\"", eyal.encoded
77
- end
78
-
79
- def test_federated_query
80
- adapter1 = ConnectionPool.add_data_source(:type => :rdflite)
81
- adapter2 = ConnectionPool.add_data_source(:type => :rdflite, :fake_symbol_to_get_unique_adapter => true)
82
-
83
- eyal = RDFS::Resource.new 'eyaloren.org'
84
- age = RDFS::Resource.new 'foaf:age'
85
- test = RDFS::Resource.new 'test'
86
- test2 = RDFS::Resource.new 'test2'
87
-
88
- adapter1.add(eyal, age, test)
89
- adapter2.add(eyal, age, test2)
90
-
91
- # assert only one distinct subject is found (same one in both adapters)
92
- assert_equal 1, Query.new.distinct(:s).where(:s, :p, :o).execute.size
93
-
94
- # assert two distinct objects are found
95
- results = Query.new.distinct(:o).where(:s, :p, :o).execute
96
- assert_equal 2, results.size
97
-
98
- results.all? {|result| assert result.instance_of?(RDFS::Resource) }
99
- end
100
-
101
- def test_query_with_block
102
- adapter = ConnectionPool.add_data_source(:type => :rdflite)
103
-
104
- eyal = RDFS::Resource.new 'eyaloren.org'
105
- age = RDFS::Resource.new 'foaf:age'
106
- test = RDFS::Resource.new 'test'
107
-
108
- adapter.add(eyal, age, test)
109
- Query.new.select(:s,:p).where(:s,:p,:o).execute(:flatten => false) do |s,p|
110
- assert_equal 'eyaloren.org', s.uri
111
- assert_equal 'foaf:age', p.uri
112
- end
113
- end
114
-
115
- def test_loading_data
116
- adapter = ConnectionPool.add_data_source :type => :rdflite
117
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
118
- assert_equal 32, adapter.size
119
-
120
- adapter.clear
121
- adapter.load('http://www.w3.org/2000/10/rdf-tests/rdfcore/ntriples/test.nt')
122
- assert_equal 30, adapter.size
123
-
124
- adapter.clear
125
- adapter.load('http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema.rdf')
126
- assert_equal 76, adapter.size
127
- end
128
-
129
- def test_load_bnodes
130
- adapter = ConnectionPool.add_data_source :type => :rdflite
131
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_bnode_data.nt')
132
-
133
- # loaded five triples in total
134
- assert_equal 5, adapter.size
135
-
136
- # triples contain two distinct bnodes
137
- assert_equal 2, Query.new.count.distinct(:s).where(:s,:p,:o).execute
138
-
139
- # collecting the bnodes
140
- bnodes = Query.new.distinct(:s).where(:s,:p,:o).execute
141
- # assert that _:#1 occurs in three triples
142
- assert_equal 3, Query.new.select(:p,:o).where(bnodes[0], :p, :o).execute.size
143
- # assert that _:#2 occurs in two triples
144
- assert_equal 2, Query.new.select(:p,:o).where(bnodes[1], :p, :o).execute.size
145
- end
146
-
147
- def test_count_query
148
- adapter = ConnectionPool.add_data_source :type => :rdflite
149
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
150
- assert_kind_of Fixnum, Query.new.count(:s).where(:s,:p,:o).execute
151
- assert_equal 32, Query.new.count(:s).where(:s,:p,:o).execute
152
- end
153
-
154
- def test_single_context
155
- adapter = ConnectionPool.add_data_source :type => :rdflite
156
- file = File.dirname(File.expand_path(__FILE__)) + '/test_data.nt'
157
- adapter.load(file)
158
-
159
- context = Query.new.distinct(:c).where(:s,:p,:o,:c).execute(:flatten => true)
160
- assert_instance_of RDFS::Resource, context
161
- assert_equal RDFS::Resource.new("file:#{file}"), context
162
- end
163
-
164
- def test_multiple_context
165
- adapter = ConnectionPool.add_data_source :type => :rdflite
166
- file = File.dirname(File.expand_path(__FILE__)) + '/test_data.nt'
167
- adapter.load(file)
168
- file_context = RDFS::Resource.new("file:#{file}")
169
-
170
- eyal = RDFS::Resource.new 'eyaloren.org'
171
- age = RDFS::Resource.new 'foaf:age'
172
- test = RDFS::Resource.new 'test'
173
- adapter.add(eyal, age, test, 'context')
174
-
175
- context = Query.new.distinct(:c).where(:s,:p,:o,:c).execute
176
- assert_equal file_context, context[0]
177
- assert_equal 'context', context[1]
178
-
179
- assert_equal 10, Query.new.count.distinct(:s).where(:s, :p, :o, nil).execute
180
- assert_equal 1, Query.new.count.distinct(:s).where(:s, :p, :o, 'context').execute
181
- assert_equal 9, Query.new.count.distinct(:s).where(:s, :p, :o, file_context).execute
182
- end
183
-
184
- def test_person_data
185
- adapter = ConnectionPool.add_data_source :type => :rdflite
186
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
187
-
188
- Namespace.register(:test, 'http://activerdf.org/test/')
189
- eyal = Namespace.lookup(:test, :eyal)
190
- eye = Namespace.lookup(:test, :eye)
191
- person = Namespace.lookup(:test, :Person)
192
- type = Namespace.lookup(:rdf, :type)
193
- resource = Namespace.lookup(:rdfs,:resource)
194
-
195
- color = Query.new.select(:o).where(eyal, eye,:o).execute(:flatten => true)
196
- assert 'blue', color
197
- assert_instance_of String, color
198
-
199
- ObjectManager.construct_classes
200
- assert eyal.instance_of?(TEST::Person)
201
- assert eyal.instance_of?(RDFS::Resource)
202
- end
203
-
204
- def test_delete_data
205
- adapter = ConnectionPool.add_data_source :type => :rdflite
206
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
207
- assert_equal 32, adapter.size
208
-
209
- eyal = RDFS::Resource.new('http://activerdf.org/test/eyal')
210
- adapter.delete(eyal, nil, nil)
211
- assert_equal 27, adapter.size
212
-
213
- adapter.delete(nil, nil, nil)
214
- assert_equal 0, adapter.size
215
- end
216
-
217
- def test_keyword_search
218
- adapter = ConnectionPool.add_data_source :type => :rdflite
219
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
220
-
221
- eyal = RDFS::Resource.new('http://activerdf.org/test/eyal')
222
-
223
- # we cant garantuee that ferret is installed
224
- if adapter.keyword_search?
225
- assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"blue").execute(:flatten => true)
226
- assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"27").execute(:flatten => true)
227
- assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"eyal oren").execute(:flatten => true)
228
- end
229
- end
230
-
231
- def test_bnodes
232
- adapter = ConnectionPool.add_data_source :type => :rdflite
233
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
234
-
235
- Namespace.register(:test, 'http://activerdf.org/test/')
236
- ObjectManager.construct_classes
237
- assert_equal 2, TEST::Person.find_all.size
238
- assert_equal 29, TEST::Person.find_all[1].age.to_i
239
- assert_equal "Another Person", TEST::Person.find_all[1].name
240
- end
241
-
242
- def test_multi_join
243
- adapter = ConnectionPool.add_data_source :type => :rdflite
244
- type = Namespace.lookup(:rdf, 'type')
245
- transProp = Namespace.lookup(:owl, 'TransitiveProperty')
246
-
247
- Namespace.register(:test, 'http://test.com/')
248
- ancestor = Namespace.lookup(:test, 'ancestor')
249
- sue = Namespace.lookup(:test, 'Sue')
250
- mary = Namespace.lookup(:test, 'Mary')
251
- anne = Namespace.lookup(:test, 'Anne')
30
+ @adapter = ConnectionPool.add(:type => :rdflite, :keyword => false)
31
+ assert !@adapter.keyword_search?
32
+ end
33
+
34
+ # def test_keyword_search
35
+ # @adapter = ConnectionPool.add(:type => :rdflite, :keyword => true)
36
+ #
37
+ # # we cant garantuee that ferret is installed
38
+ # if @adapter.keyword_search?
39
+ # assert_equal TEST::eyal, Query.new.distinct(:s).where(:s,:keyword,"blue").execute(:flatten => true)
40
+ # assert_equal TEST::eyal, Query.new.distinct(:s).where(:s,:keyword,"27").execute(:flatten => true)
41
+ # assert_equal TEST::eyal, Query.new.distinct(:s).where(:s,:keyword,"eyal oren").execute(:flatten => true)
42
+ # end
43
+ # end
44
+ end
252
45
 
253
- adapter.add ancestor, type, transProp
254
- adapter.add sue, ancestor, mary
255
- adapter.add mary, ancestor, anne
46
+ class TestRdfLiteAdapterMemory < Test::Unit::TestCase
47
+ include TestWritableAdapter
48
+ #include TestBnodeCapableAdapter
49
+ #include TestContextAwareAdapter
256
50
 
257
- # test that query with multi-join (joining over 1.p==2.p and 1.o==2.s) works
258
- query = Query.new.select(:Sue, :p, :Anne)
259
- query.where(:p, type, transProp)
260
- query.where(:Sue, :p, :Mary)
261
- query.where(:Mary, :p, :Anne)
262
- assert_equal 1, query.execute.size
51
+ def setup
52
+ super(:type => :rdflite, :new => true)
263
53
  end
54
+ end
264
55
 
265
- def test_limit_and_offset
266
- adapter = ConnectionPool.add_data_source :type => :rdflite
267
- adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
268
- Namespace.register(:test, 'http://activerdf.org/test/')
269
-
270
- assert_equal 7, RDFS::Resource.find(:all).size
271
- assert_equal 5, RDFS::Resource.find(:all, :limit => 5).size
272
- assert_equal 4, RDFS::Resource.find(:all, :limit => 4, :offset => 3).size
273
- assert RDFS::Resource.find(:all, :limit => 4, :offset => 3) != RDFS::Resource.find(:all, :limit => 4)
56
+ class TestRdfLiteAdapterFile < Test::Unit::TestCase
57
+ include TestPersistentAdapter
58
+ #include TestBnodeCapableAdapter
59
+ #include TestContextAwareAdapter
274
60
 
275
- assert_equal [TEST::eyal, TEST::age, TEST::car], RDFS::Resource.find(:all, :limit => 3, :order => RDF::type)
61
+ def setup
62
+ super(:type => :rdflite, :location => 'test_rdflite_db', :new => true)
276
63
  end
277
- end
64
+ end