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
@@ -2,46 +2,33 @@
|
|
2
2
|
require 'queryengine/query2sparql'
|
3
3
|
|
4
4
|
# Generic superclass of all adapters
|
5
|
-
|
6
|
-
class ActiveRdfAdapter
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
+
# translate a query to its string representation
|
20
|
+
def translate(query)
|
21
|
+
Query2SPARQL.translate(query)
|
22
|
+
end
|
41
23
|
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
8
|
-
class
|
9
|
-
|
7
|
+
module ActiveRDF
|
8
|
+
class ConnectionPool
|
9
|
+
class << self
|
10
|
+
attr_accessor :write_adapter
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
-
|
21
|
+
# pool of connection parameters to all adapter
|
22
|
+
@@adapter_parameters = Array.new
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
# currently active write-adapter (we can only write to one at a time)
|
25
|
+
self.write_adapter = nil
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
# default setting for auto_flush
|
28
|
+
self.auto_flush = true
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
35
|
+
# clears the pool: removes all registered data sources
|
36
|
+
def ConnectionPool.clear
|
36
37
|
ActiveRdfLogger::log_info "Clear called", self
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
@@adapter_pool = []
|
39
|
+
@@adapter_parameters = []
|
40
|
+
self.write_adapter = nil
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def ConnectionPool.adapters
|
44
|
+
@@adapter_pool.dup
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
# flushes all openstanding changes into the original datasource.
|
48
|
+
def ConnectionPool.flush
|
49
|
+
write_adapter.flush
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def ConnectionPool.adapter_types
|
53
|
+
@@registered_adapter_types.keys
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
61
|
+
def ConnectionPool.write_adapters
|
62
|
+
@@adapter_pool.select {|adapter| adapter.writes? && adapter.enabled?}
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
84
|
-
|
84
|
+
adapter = @@adapter_pool[index]
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
87
|
+
# sets the adapter as current write-source if it can write
|
88
|
+
self.write_adapter = adapter if adapter.writes?
|
88
89
|
|
89
|
-
|
90
|
-
|
90
|
+
return adapter
|
91
|
+
end
|
91
92
|
|
92
|
-
|
93
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
135
|
-
|
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
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
149
|
-
|
156
|
+
# raise error if adapter type unknown
|
157
|
+
raise(ActiveRdfError, "unknown adapter type #{connection_params[:type]}") if klass.nil?
|
150
158
|
|
151
|
-
|
152
|
-
|
153
|
-
|
159
|
+
# create new adapter-instance
|
160
|
+
klass.send(:new,connection_params)
|
161
|
+
end
|
154
162
|
|
155
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
20
|
+
ConnectionPool.write_adapter.add(s,p,o,c)
|
21
|
+
end
|
16
22
|
end
|
17
|
-
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
33
|
+
ConnectionPool.write_adapter.delete(s,p,o,c)
|
34
|
+
end
|
29
35
|
end
|
30
|
-
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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.
|
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
|
-
|
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
|
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
|
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]
|
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
|
-
|
111
|
-
|
112
|
-
end
|
109
|
+
end # End benchmark
|
110
|
+
end # End query
|
111
|
+
end
|
112
|
+
end
|
@@ -1,7 +1,13 @@
|
|
1
|
-
|
2
|
-
|
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
|