49: def execute_sparql_query(qs, header=nil, &block)
50: header = header(nil) if header.nil?
51:
52:
53: url = "#@url?query=#{CGI.escape(qs)}"
54:
55: url = url.gsub("DISTINCT", "") if @yars2
56: $activerdflog.debug "executing: requesting #{url}"
57:
58:
59: response = ''
60: begin
61: open(url, header) do |f|
62: response = f.read
63: end
64: rescue OpenURI::HTTPError => e
65: raise ActiveRdfError, "could not query SPARQL endpoint, server said: #{e}"
66: return []
67: rescue Errno::ECONNREFUSED
68: raise ActiveRdfError, "connection refused on SPARQL endpoint #@url"
69: return []
70: end
71: $activerdflog.debug "response:\n#{response}"
72:
73:
74: results = case @result_format
75: when :json
76: parse_json(response)
77: when :xml, :sparql_xml
78: parse_xml(response)
79: end
80:
81: if block_given?
82: results.each do |*clauses|
83: yield(*clauses)
84: end
85: else
86: results
87: end
88: end