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
@@ -2,46 +2,33 @@
2
2
  require 'queryengine/query2sparql'
3
3
 
4
4
  # Generic superclass of all adapters
5
-
6
- class ActiveRdfAdapter
7
- # indicate if adapter can read and write
8
- bool_accessor :reads, :writes, :enabled
9
-
10
- def initialize
11
- @enabled = true
12
- end
13
-
14
- # Indicate if the adapter supports contexts
15
- def supports_context?
16
- self.class.supports_context?
17
- end
18
-
19
- # translate a query to its string representation
20
- def translate(query)
21
- Query2SPARQL.translate(query)
22
- end
23
-
24
- # Clear the adapter. Crude default implementation, which can be overwritten
25
- # in subclasses. TODO: This queries all adapters, this may lead to problems...
26
- def clear
27
- raise(ActiveRdfError, "Can only delete from writing adapters") unless(writes?)
28
- to_delete = Query.new.select(:s, :p, :o).where(:s, :p, :o).execute
29
- to_delete.each do |s, p, o|
30
- delete(s, p, o)
5
+ module ActiveRDF
6
+ class ActiveRdfAdapter
7
+ # indicate if adapter can read and write
8
+ bool_accessor :reads, :writes, :contexts, :enabled
9
+
10
+ def initialize(params = {})
11
+ # defaults
12
+ @enabled = true
13
+ @reads = true
14
+ @writes = truefalse(params[:write], true)
15
+ @new = truefalse(params[:new], false)
16
+ @contexts = truefalse(params[:contexts], false)
31
17
  end
32
- end
33
-
34
- # Indicates if this adapter class supports contexts
35
- def self.supports_context?
36
- @context_supported = false if(@context_supported == nil)
37
- @context_supported
38
- end
39
18
 
40
- private
19
+ # translate a query to its string representation
20
+ def translate(query)
21
+ Query2SPARQL.translate(query)
22
+ end
41
23
 
42
- # Method to set the "context_supported" flag
43
- def self.supports_context
44
- @context_supported = true
24
+ # Clear the adapter. Crude default implementation, which can be overwritten
25
+ # in subclasses. TODO: This queries all adapters, this may lead to problems...
26
+ def clear
27
+ raise(ActiveRdfError, "Can only delete from writing adapters") unless(writes?)
28
+ to_delete = Query.new.select(:s, :p, :o).where(:s, :p, :o).execute
29
+ to_delete.each do |s, p, o|
30
+ delete(s, p, o)
31
+ end
32
+ end
45
33
  end
46
-
47
- end
34
+ end
@@ -1,138 +1,146 @@
1
1
  # require 'active_rdf'
2
2
 
3
- # Maintains pool of adapter instances that are connected to datasources. Returns
3
+ # Maintains pool of adapter instances that are connected to datasources. Returns
4
4
  # right adapter for a given datasource, by either reusing an
5
5
  # existing adapter-instance or creating new a adapter-instance.
6
6
 
7
- class ConnectionPool
8
- class << self
9
- attr_accessor :write_adapter
7
+ module ActiveRDF
8
+ class ConnectionPool
9
+ class << self
10
+ attr_accessor :write_adapter
10
11
 
11
- # sets automatic flushing of data from adapters to original datasources
12
- # (e.g. redland on-file database). If disabled, changes to an adapter are
13
- # not written back into the original source: you need to invoke
14
- # ConnectionPool.flush manually
15
- bool_accessor :auto_flush
16
- end
17
- # pool of all adapters
18
- @@adapter_pool = Array.new
12
+ # sets automatic flushing of data from adapters to original datasources
13
+ # (e.g. redland on-file database). If disabled, changes to an adapter are
14
+ # not written back into the original source: you need to invoke
15
+ # ConnectionPool.flush manually
16
+ bool_accessor :auto_flush
17
+ end
18
+ # pool of all adapters
19
+ @@adapter_pool = Array.new
19
20
 
20
- # pool of connection parameters to all adapter
21
- @@adapter_parameters = Array.new
21
+ # pool of connection parameters to all adapter
22
+ @@adapter_parameters = Array.new
22
23
 
23
- # currently active write-adapter (we can only write to one at a time)
24
- self.write_adapter = nil
24
+ # currently active write-adapter (we can only write to one at a time)
25
+ self.write_adapter = nil
25
26
 
26
- # default setting for auto_flush
27
- self.auto_flush = true
27
+ # default setting for auto_flush
28
+ self.auto_flush = true
28
29
 
29
- # adapters-classes known to the pool, registered by the adapter-class
30
- # itself using register_adapter method, used to select new
31
- # adapter-instance for requested connection type
32
- @@registered_adapter_types = Hash.new
30
+ # adapters-classes known to the pool, registered by the adapter-class
31
+ # itself using register_adapter method, used to select new
32
+ # adapter-instance for requested connection type
33
+ @@registered_adapter_types = Hash.new
33
34
 
34
- # clears the pool: removes all registered data sources
35
- def ConnectionPool.clear
35
+ # clears the pool: removes all registered data sources
36
+ def ConnectionPool.clear
36
37
  ActiveRdfLogger::log_info "Clear called", self
37
- @@adapter_pool.clear
38
- @@adapter_parameters.clear
39
- self.write_adapter = nil
40
- end
38
+ @@adapter_pool = []
39
+ @@adapter_parameters = []
40
+ self.write_adapter = nil
41
+ end
41
42
 
42
- def ConnectionPool.adapters
43
- @@adapter_pool.dup
44
- end
43
+ def ConnectionPool.adapters
44
+ @@adapter_pool.dup
45
+ end
45
46
 
46
- # flushes all openstanding changes into the original datasource.
47
- def ConnectionPool.flush
48
- write_adapter.flush
49
- end
47
+ # flushes all openstanding changes into the original datasource.
48
+ def ConnectionPool.flush
49
+ write_adapter.flush
50
+ end
50
51
 
51
- def ConnectionPool.adapter_types
52
- @@registered_adapter_types.keys
53
- end
52
+ def ConnectionPool.adapter_types
53
+ @@registered_adapter_types.keys
54
+ end
54
55
 
55
- # returns the set of currently registered read-access datasources
56
- def ConnectionPool.read_adapters
57
- @@adapter_pool.select {|adapter| adapter.reads? && adapter.enabled?}
58
- end
56
+ # returns the set of currently registered read-access datasources
57
+ def ConnectionPool.read_adapters
58
+ @@adapter_pool.select {|adapter| adapter.reads? && adapter.enabled?}
59
+ end
59
60
 
60
- def ConnectionPool.write_adapters
61
- @@adapter_pool.select {|adapter| adapter.writes? && adapter.enabled?}
62
- end
61
+ def ConnectionPool.write_adapters
62
+ @@adapter_pool.select {|adapter| adapter.writes? && adapter.enabled?}
63
+ end
63
64
 
64
- # returns adapter-instance for given parameters (either existing or new)
65
- def ConnectionPool.add_data_source(connection_params)
65
+ # returns adapter-instance for given parameters (either existing or new)
66
+ def ConnectionPool.add_data_source(connection_params)
66
67
  ActiveRdfLogger::log_info(self) { "add_data_source with params: #{connection_params.inspect}" }
67
68
 
68
- # either get the adapter-instance from the pool
69
- # or create new one (and add it to the pool)
70
- index = @@adapter_parameters.index(connection_params)
71
- if index.nil?
72
- # adapter not in the pool yet: create it,
73
- # register its connection parameters in parameters-array
74
- # and add it to the pool (at same index-position as parameters)
69
+ # either get the adapter-instance from the pool
70
+ # or create new one (and add it to the pool)
71
+ index = @@adapter_parameters.index(connection_params)
72
+ if index.nil?
73
+ # adapter not in the pool yet: create it,
74
+ # register its connection parameters in parameters-array
75
+ # and add it to the pool (at same index-position as parameters)
75
76
  ActiveRdfLogger::log_debug(self) { "Create a new adapter for parameters #{connection_params.inspect}" }
76
- adapter = create_adapter(connection_params)
77
- @@adapter_parameters << connection_params
78
- @@adapter_pool << adapter
79
- else
80
- # if adapter parametrs registered already,
81
- # then adapter must be in the pool, at the same index-position as its parameters
77
+ adapter = create_adapter(connection_params)
78
+ @@adapter_parameters << connection_params
79
+ @@adapter_pool << adapter
80
+ else
81
+ # if adapter parametrs registered already,
82
+ # then adapter must be in the pool, at the same index-position as its parameters
82
83
  ActiveRdfLogger::log_debug("Reusing existing adapter")
83
- adapter = @@adapter_pool[index]
84
- end
84
+ adapter = @@adapter_pool[index]
85
+ end
85
86
 
86
- # sets the adapter as current write-source if it can write
87
- self.write_adapter = adapter if adapter.writes?
87
+ # sets the adapter as current write-source if it can write
88
+ self.write_adapter = adapter if adapter.writes?
88
89
 
89
- return adapter
90
- end
90
+ return adapter
91
+ end
91
92
 
92
- # remove one adapter from activerdf
93
- def ConnectionPool.remove_data_source(adapter)
93
+ # remove one adapter from activerdf
94
+ def ConnectionPool.remove_data_source(adapter)
94
95
  ActiveRdfLogger.log_info(self) { "ConnectionPool: remove_data_source with params: #{adapter.to_s}" }
95
96
 
96
- index = @@adapter_pool.index(adapter)
97
-
98
- # remove_data_source mit be called repeatedly, e.g because the adapter object is stale
99
- unless index.nil?
100
- @@adapter_parameters.delete_at(index)
101
- @@adapter_pool.delete_at(index)
102
- if self.write_adapters.empty?
103
- self.write_adapter = nil
104
- else
105
- self.write_adapter = self.write_adapters.first
97
+ index = @@adapter_pool.index(adapter)
98
+
99
+ # remove_data_source mit be called repeatedly, e.g because the adapter object is stale
100
+ unless index.nil?
101
+ @@adapter_parameters.delete_at(index)
102
+ @@adapter_pool.delete_at(index)
103
+ if self.write_adapters.empty?
104
+ self.write_adapter = nil
105
+ else
106
+ self.write_adapter = self.write_adapters.first
107
+ end
106
108
  end
109
+
107
110
  end
108
111
 
109
- end
112
+ # closes and removes adapter from pool
113
+ def ConnectionPool.close_data_source(adapter)
114
+ remove_data_source(adapter)
115
+ adapter.close
116
+ end
110
117
 
111
- # sets adapter-instance for connection parameters (if you want to re-enable an existing adapter)
112
- def ConnectionPool.set_data_source(adapter, connection_params = {})
113
- index = @@adapter_parameters.index(connection_params)
114
- if index.nil?
115
- @@adapter_parameters << connection_params
116
- @@adapter_pool << adapter
117
- else
118
- @@adapter_pool[index] = adapter
118
+ # sets adapter-instance for connection parameters (if you want to re-enable an existing adapter)
119
+ def ConnectionPool.set_data_source(adapter, connection_params = {})
120
+ index = @@adapter_parameters.index(connection_params)
121
+ if index.nil?
122
+ @@adapter_parameters << connection_params
123
+ @@adapter_pool << adapter
124
+ else
125
+ @@adapter_pool[index] = adapter
126
+ end
127
+ self.write_adapter = adapter if adapter.writes?
128
+ adapter
119
129
  end
120
- self.write_adapter = adapter if adapter.writes?
121
- adapter
122
- end
123
130
 
124
- # aliasing add_data_source as add
125
- # (code bit more complicad since they are class methods)
126
- class << self
127
- alias add add_data_source
128
- end
131
+ # aliasing add_data_source as add
132
+ # (code bit more complicad since they are class methods)
133
+ class << self
134
+ alias add add_data_source
135
+ alias close close_data_source
136
+ end
129
137
 
130
- # adapter-types can register themselves with connection pool by
131
- # indicating which adapter-type they are
132
- def ConnectionPool.register_adapter(type, klass)
138
+ # adapter-types can register themselves with connection pool by
139
+ # indicating which adapter-type they are
140
+ def ConnectionPool.register_adapter(type, klass)
133
141
  ActiveRdfLogger::log_info(self) { "Registering adapter of type #{type} for class #{klass}" }
134
- @@registered_adapter_types[type] = klass
135
- end
142
+ @@registered_adapter_types[type] = klass
143
+ end
136
144
 
137
145
  # unregister adapter-type
138
146
  def ConnectionPool.unregister_adapter(type)
@@ -140,17 +148,18 @@ class ConnectionPool
140
148
  @@registered_adapter_types.delete type
141
149
  end
142
150
 
143
- # create new adapter from connection parameters
144
- def ConnectionPool.create_adapter connection_params
145
- # lookup registered adapter klass
151
+ # create new adapter from connection parameters
152
+ def ConnectionPool.create_adapter connection_params
153
+ # lookup registered adapter klass
146
154
  klass = @@registered_adapter_types[connection_params[:type].to_sym]
147
155
 
148
- # raise error if adapter type unknown
149
- raise(ActiveRdfError, "unknown adapter type #{connection_params[:type]}") if klass.nil?
156
+ # raise error if adapter type unknown
157
+ raise(ActiveRdfError, "unknown adapter type #{connection_params[:type]}") if klass.nil?
150
158
 
151
- # create new adapter-instance
152
- klass.send(:new, connection_params)
153
- end
159
+ # create new adapter-instance
160
+ klass.send(:new,connection_params)
161
+ end
154
162
 
155
- private_class_method :create_adapter
156
- end
163
+ private_class_method :create_adapter
164
+ end
165
+ end
@@ -2,61 +2,66 @@ require 'federation/connection_pool'
2
2
 
3
3
  include ActiveRdfBenchmark
4
4
 
5
- # Manages the federation of datasources: distributes queries to right
5
+ # Manages the federation of datasources: distributes queries to right
6
6
  # datasources and merges their results
7
7
 
8
- class FederationManager
9
- # add triple s,p,o (context is optional) to the currently selected write-adapter
10
- def FederationManager.add(s,p,o,c=nil)
11
- benchmark("SPARQL/RDF", Logger::DEBUG) do |bench_message|
12
- bench_message << "ADD #{s} - #{p} - #{o} : #{c}" if(bench_message)
8
+ module ActiveRDF
9
+ class FederationManager
10
+ def FederationManager.contexts
11
+ ConnectionPool.adapters.collect{|adapter| adapter.contexts if adapter.respond_to?(:contexts)}.flatten.compact
12
+ end
13
+
14
+ # add triple s,p,o (context is optional) to the currently selected write-adapter
15
+ def FederationManager.add(s,p,o,c=nil)
16
+ benchmark("SPARQL/RDF", Logger::DEBUG) do |bench_message|
17
+ bench_message << "ADD #{s} - #{p} - #{o} : #{c}" if(bench_message)
13
18
  # TODO: allow addition of full graphs
14
19
  raise ActiveRdfError, "cannot write without a write-adapter" unless ConnectionPool.write_adapter
15
- ConnectionPool.write_adapter.add(s,p,o,c)
20
+ ConnectionPool.write_adapter.add(s,p,o,c)
21
+ end
16
22
  end
17
- end
18
23
 
19
- # delete triple s,p,o (context is optional) to the currently selected write-adapter
20
- def FederationManager.delete(s,p,o,c=nil)
21
- benchmark("SPARQL/RDF", Logger::DEBUG) do |bench_message|
22
- bench_message << "DELETE #{s} - #{p} - #{o} : #{c}" if(bench_message)
24
+ # delete triple s,p,o (context is optional) to the currently selected write-adapter
25
+ def FederationManager.delete(s,p=nil,o=nil,c=nil)
26
+ benchmark("SPARQL/RDF", Logger::DEBUG) do |bench_message|
27
+ bench_message << "DELETE #{s} - #{p} - #{o} : #{c}" if(bench_message)
23
28
  raise ActiveRdfError, "cannot write without a write-adapter" unless ConnectionPool.write_adapter
24
29
  # transform wildcard symbols to nil (for the adaptors)
25
30
  s = nil if s.is_a? Symbol
26
31
  p = nil if p.is_a? Symbol
27
32
  o = nil if o.is_a? Symbol
28
- ConnectionPool.write_adapter.delete(s,p,o,c)
33
+ ConnectionPool.write_adapter.delete(s,p,o,c)
34
+ end
29
35
  end
30
- end
31
36
 
32
- # delete every triples about a specified resource
33
- def FederationManager.delete_all(resource)
34
- delete(resource, nil, nil)
35
- end
36
-
37
- # Clear the store (or the given context)
38
- def FederationManager.clear(context=nil)
39
- # FIXME: Make sure that all adapters support clearing
40
- raise(RuntimeError, "Adapter #{ConnectionPool.write_adapter.class} doesn't support clear") unless(ConnectionPool.write_adapter.respond_to?(:clear))
41
- ConnectionPool.write_adapter.clear(context)
42
- end
37
+ # delete every triples about a specified resource
38
+ def FederationManager.delete_all(resource)
39
+ delete(resource, nil, nil)
40
+ end
43
41
 
44
- # executes read-only queries
45
- # by distributing query over complete read-pool
46
- # and aggregating the results
47
- def FederationManager.query(q, options={:flatten => true, :result_format => nil})
48
- if ConnectionPool.read_adapters.empty?
49
- raise ActiveRdfError, "cannot execute query without data sources"
42
+ # Clear the store (or the given context)
43
+ def FederationManager.clear(context=nil)
44
+ # FIXME: Make sure that all adapters support clearing
45
+ raise(RuntimeError, "Adapter #{ConnectionPool.write_adapter.class} doesn't support clear") unless(ConnectionPool.write_adapter.respond_to?(:clear))
46
+ ConnectionPool.write_adapter.clear(context)
50
47
  end
51
48
 
52
- benchmark("SPARQL/RDF", Logger::DEBUG) do |bench_message|
53
- # Only build the benchmark message if we need it
54
- bench_message << ((q.class == String) ? q : q.to_sp) if(bench_message)
49
+ # executes read-only queries
50
+ # by distributing query over complete read-pool
51
+ # and aggregating the results
52
+ def FederationManager.execute(q, options={:flatten => false})
53
+ if ConnectionPool.read_adapters.empty?
54
+ raise ActiveRdfError, "cannot execute query without data sources"
55
+ end
56
+
57
+ benchmark("SPARQL/RDF", Logger::DEBUG) do |bench_message|
58
+ # Only build the benchmark message if we need it
59
+ bench_message << ((q.class == String) ? q : q.to_sp) if(bench_message)
55
60
  # ask each adapter for query results
56
61
  # and yield them consequtively
57
62
  if block_given?
58
63
  ConnectionPool.read_adapters.each do |source|
59
- source.query(q) do |*clauses|
64
+ source.execute(q) do |*clauses|
60
65
  yield(*clauses)
61
66
  end
62
67
  end
@@ -65,19 +70,17 @@ class FederationManager
65
70
  # TODO: write test for sebastian's select problem
66
71
  # (without distinct, should get duplicates, they
67
72
  # were filtered out when doing results.union)
68
- # FIXME: Calling get_sparql_query_results? This *only* exists on the redland adapter
69
73
  results = []
70
74
  ConnectionPool.read_adapters.each do |source|
71
- if (q.class != String)
72
- source_results = source.query(q)
73
- else
74
- source_results = source.get_sparql_query_results(q, RDFS::Resource, options[:result_format])
75
- end
75
+ source_results = source.execute(q)
76
76
  source_results.each do |clauses|
77
77
  results << clauses
78
78
  end
79
79
  end
80
80
 
81
+ # count
82
+ return results.flatten.inject{|mem,c| mem + c} if q.count?
83
+
81
84
  # filter the empty results
82
85
  results.reject {|ary| ary.empty? }
83
86
 
@@ -85,18 +88,14 @@ class FederationManager
85
88
  # adapters if asked for distinct query
86
89
  # (adapters return only distinct results,
87
90
  # but they cannot check duplicates against each other)
88
- results.uniq! if ((q.class != String) && (q.distinct?))
91
+ results.uniq! if q.distinct?
89
92
 
90
93
  # flatten results array if only one select clause
91
94
  # to prevent unnecessarily nested array [[eyal],[renaud],...]
92
- if (q.class != String)
93
- results.flatten! if (q.select_clauses.size == 1 or q.ask?)
94
- else
95
- results.flatten! if q.scan(/[?]/).length == 2
96
- end
95
+ results.flatten! if q.select_clauses.size == 1 or q.ask?
97
96
 
98
97
  # remove array (return single value or nil) if asked to
99
- if options[:flatten] or ((q.class != String) && (q.count?))
98
+ if options[:flatten]
100
99
  case results.size
101
100
  when 0
102
101
  results = nil
@@ -107,6 +106,7 @@ class FederationManager
107
106
  end
108
107
 
109
108
  results
110
- end # End benchmark
111
- end # End query
112
- end
109
+ end # End benchmark
110
+ end # End query
111
+ end
112
+ end
@@ -1,7 +1,13 @@
1
- module RDFS
2
- class BNode < Resource
1
+ require 'active_rdf'
2
+
3
+ module ActiveRDF
4
+ Namespace.register(:bnode, "http://www.activerdf.org/bnode#")
5
+
6
+ class BNode < RDFS::Resource
3
7
  def to_s
4
8
  "<_:#{uri}>"
5
9
  end
10
+
11
+ self.class_uri = RDFS::Resource.new("http://www.activerdf.org/bnode")
6
12
  end
7
13
  end