Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this file runs a given sparql query on prism endpoint
- # run as /usr/bin/time -v ruby prism-query.rb
- require 'net/https'
- f = File.new(ARGV[0])
- text = f.read
- url = URI.encode("https://localhost:8443/prism/rest/sparql?query=#{text}")
- http = Net::HTTP.new('localhost', '8443')
- http.use_ssl = true
- http.read_timeout = 1800
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- p12 = OpenSSL::PKCS12.new(File.read("/usr/local/prism-1.0.9/certs/certs/testuser/testuser.p12"), "changeit")
- http.cert = p12.certificate
- http.key = p12.key
- url.gsub!("https://localhost:8443", "")
- url.gsub!("=", "%3D")
- url.gsub!("?", "%3F")
- url.gsub!("!", "%21")
- url.gsub!("&", "%26")
- url.gsub!("%3Fquery%3D", "?query=")
- req = Net::HTTP::Get.new(url)
- result = http.start {|http|
- result = http.request(req)
- #puts result.body
- if result.body.include?("<boolean>")
- puts "Boolean Result: " + result.body.match(/<boolean>(.+?)<\/boolean>/)[1]
- else
- puts "Number of Results: " + result.body.scan(/<result>/).length.to_s
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement