Parent

Methods

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]

Public Class Methods

new(sd, query, output = 'json') click to toggle source
# File examples/sdjas.rb, line 180
def initialize(sd, query, output = 'json')
    @_sd = sd;
    @_query = query;
    @_data = {
        'query' => query,
        'output' => output
    }
    #self.response = requests.get(self._sd.url, params = self._data)
    #puts "url = " + str(self._sd.url)
    uri = URI("http://" + @_sd.url.to_s)
    #puts "uri      = " + uri.to_s
    #puts "uri.host = " + uri.host.to_s
    #puts "uri.port = " + uri.port.to_s
    Net::HTTP.start( uri.host, uri.port ) do |conn|
       #puts "conn = " + str(conn)

       #puts "query = " + str(query)
       #_path = @_sd.sqpath + "?" + URI.encode_www_form(@_data)
       uri.path = @_sd.sqpath
       uri.query = URI.encode_www_form(@_data)
       #puts "uri       = ", uri
       #puts "uri       = " + str(uri)
       #puts "uri.path  = " + uri.path.to_s
       #puts "uri.query = " + uri.query.to_s
       req = Net::HTTP::Get.new(uri.request_uri)
       #puts "req = " + str(req)
       response = conn.request( req );
       if not response.is_a?(Net::HTTPSuccess)
          puts "response = " + response.to_s + "\n"
          raise RuntimeError, "HTTP GET #{uri} not successful" 
       end

       #head = response.code.to_s + " " + response.msg
       #puts "head = " + str(head) + "\n"
       @text = response.body()
       #puts "body = " + str(@text)
       @json = JSON.load(@text)
       #puts "json = " + str(@json)
    end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.