class SPARQL
This is a ‘wrapper’ class for SPARQL
queries. A class might be a slight overkill. It was made with the idea, that one can store the query and the result together, to re-evaluate both without having to access the server. However, in the end this feature was not really needed.
Attributes
json[R]
The json representation of the query result
Public Class Methods
new(sd, query, output = 'json')
click to toggle source
Perform the SPARQL
query.
# File examples/sdjas.rb 185 def initialize(sd, query, output = 'json') 186 @_sd = sd; 187 @_query = query; 188 @_data = { 189 'query' => query, 190 'output' => output 191 } 192 #self.response = requests.get(self._sd.url, params = self._data) 193 #puts "url = " + str(self._sd.url) 194 uri = URI("http://" + @_sd.url.to_s) 195 #puts "uri = " + uri.to_s 196 #puts "uri.host = " + uri.host.to_s 197 #puts "uri.port = " + uri.port.to_s 198 Net::HTTP.start( uri.host, uri.port ) do |conn| 199 #puts "conn = " + str(conn) 200 201 #puts "query = " + str(query) 202 #_path = @_sd.sqpath + "?" + URI.encode_www_form(@_data) 203 uri.path = @_sd.sqpath 204 uri.query = URI.encode_www_form(@_data) 205 #puts "uri = ", uri 206 #puts "uri = " + str(uri) 207 #puts "uri.path = " + uri.path.to_s 208 #puts "uri.query = " + uri.query.to_s 209 req = Net::HTTP::Get.new(uri.request_uri) 210 #puts "req = " + str(req) 211 response = conn.request( req ); 212 if not response.is_a?(Net::HTTPSuccess) 213 puts "response = " + response.to_s + "\n" 214 raise RuntimeError, "HTTP GET #{uri} not successful" 215 end 216 217 #head = response.code.to_s + " " + response.msg 218 #puts "head = " + str(head) + "\n" 219 @text = response.body() 220 #puts "body = " + str(@text) 221 @json = JSON.load(@text) 222 #puts "json = " + str(@json) 223 end 224 end