ruby-rdf / sparql-client Goto Github PK
View Code? Open in Web Editor NEWSPARQL client for Ruby.
Home Page: http://rubygems.org/gems/sparql-client
License: The Unlicense
SPARQL client for Ruby.
Home Page: http://rubygems.org/gems/sparql-client
License: The Unlicense
How are the authorization headers set and debugged? Is there a verbose option, like the curl -v option? Here's the code that fails (substitute real auth parameters), which is a query on a MarkLogic SPARQL endpoint where the Kb is running on port 8322.
auth_code = Base64.encode64('myUser:myPass').chomp
auth_header= {'Authorization' => "Basic #{auth_code}"}
uri = 'http://devbox.example.org:8322/v1/graphs/sparql?'
sparql = SPARQL::Client.new(uri, {headers: auth_header} )
q = sparql.select.where([:s, :p, :o]).limit(10)
q.each_statement {|s| puts s.inspect }
SPARQL::Client::ClientError: <rapi:error xmlns:rapi="http://marklogic.com/rest-api"><rapi:status-code>401</rapi:status-code><rapi:status>Failed Auth</rapi:status><rapi:message-code/><rapi:message>Unauthenticated</rapi:message></rapi:error>
Processing query SELECT * WHERE { ?s ?p ?o . } LIMIT 10
from /home/dlweber/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/sparql-client-1.1.3.1/lib/sparql/client.rb:342:in `block in response'
The same host and auth parameters work with curl, e.g.
curl -v --anyauth --user myUser:myPass "http:///devbox.example.org:8322/v1/graphs/sparql?query=DESCRIBE <http://id.loc.gov/authorities/names/n2006182879>"
* Hostname was NOT found in DNS cache
* Trying 172.XX.XX.XX...
* Connected to xxx (172.xx.xx.xx) port 8322 (#0)
> GET /v1/graphs/sparql?query=DESCRIBE <http://id.loc.gov/authorities/names/n2006182879> HTTP/1.1
> User-Agent: curl/7.37.1
> Host: xxx:8322
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< WWW-Authenticate: Digest realm="public", qop="auth", nonce="d01666e5d0158e66faa415f4fb21ccc6", opaque="5a267bbd6a277eb9"
< Content-type: application/xml
* Server MarkLogic is not blacklisted
< Server: MarkLogic
< Content-Length: 211
< Connection: close
<
* Closing connection 0
* Issue another request to this URL: 'http://xxx:8322/v1/graphs/sparql?query=DESCRIBE+<http://id.loc.gov/authorities/names/n2006182879>'
* Hostname was found in DNS cache
* Trying 172.xx.xx.xx...
* Connected to xxx (172.xx.xx.xx) port 8322 (#1)
* Server auth using Digest with user 'myUser'
> GET /v1/graphs/sparql?query=DESCRIBE+<http://id.loc.gov/authorities/names/n2006182879> HTTP/1.1
> Authorization: Digest username="myUser", realm="public", nonce="d01666e5d0158e66faa415f4fb21ccc6", uri="/v1/graphs/sparql?query=DESCRIBE+<http://id.loc.gov/authorities/names/n2006182879>", cnonce="NWFmZmNlYmM0ZWZhMWY1NmVmMzZkYjc2NTUyMGU0NTU=", nc=00000001, qop=auth, response="e2eed963198b23a165e652abc7bcf3c3", opaque="5a267bbd6a277eb9"
> User-Agent: curl/7.37.1
> Host: xxx:8322
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-type: application/n-quads
* Server MarkLogic is not blacklisted
< Server: MarkLogic
< Content-Length: 1155
< Connection: Keep-Alive
< Keep-Alive: timeout=5
SPARQL::Repository will query the entire repository and iterate for hash queries:
require 'sparql/client'
repo = SPARQL::Client::Repository.new 'http://sparql.org/books'
p repo.query(:subject => RDF::URI.new("http://example.com/foo/1")).to_a
#=> "CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
p repo.query(RDF::Statement.new(RDF::URI.new("http://example.com/foo/1"), nil, nil)).to_a
#=> "CONSTRUCT { <http://example.com/foo/1> ?p ?o . } WHERE { <http://example.com/foo/1> ?p ?o . }"
These queries should be equivalent (and in particular should be the form that RDF::Statement currently produces)
sparql = SPARQL::Client.new("http://teste:[email protected]:10035/repositories/projetos")
result = sparql.query("describe ?x WHERE { ?x #{"<"+RDF.type+">"} ?nome }")
result
irb(main):038:0>
I need to this query for RDF/XML..
Help me
I recently migrated to sparql-client 0.1.1 (from 0.0.11), and noticed an odd regression.
Steps to reproduce:
sparql = SPARQL::Client.new("http://dbpedia.org/sparql/")
query = sparql.select.where([:s, :p, :o]).offset(100).limit(10)
query.execute
which outputs:
SPARQL::Client::MalformedQuery: Virtuoso 22023 Error The request does not contain text of SPARQL query
I tried with a number of endpoints, and can confirm it's not specific to DBpedia
One could run into race condition issues when having one client used by multiple threads to run query
and update
calls. This is due to the use of instance variables in the make_post_request
method:
request['Content-Type'] = 'application/sparql-' + (@op || :query).to_s
https://github.com/ruby-rdf/sparql-client/blob/master/lib/sparql/client.rb#L505
I cannot find any option or function in query.rb
to set a union
of query patterns as in:
http://www.w3.org/TR/sparql11-query/#alternatives
Maybe there is a way to do this but I cannot find it.
It seems like something like people would like to have. I have implemented some simple union support in a fork. I could document it, add tests and do a pull request.
Hello, Thank you for your fast reply on my last question.
I learned how to use wildcards and had time trying it out on various query attempts. I was able to use wildcards on subjects and objects but whenever I use wildcard (in this case i used RDF::Node.new) i get an error saying that the query is malformed. Do you know any solution to this problem?
I want to make a rdf crawler that crawls linked data and want to dereference all the adjacent nodes.
Thanks again.
(I tried to raise the request in the ruby-rdf space, but it doesn't seem to have an 'Issues' tab for some reason)
COUNT queries are very useful for a wide range of reasons, e.g. pagination. Right now the only way to do such queries in sparql-client is to write a full SPARQL query. It would be good to be able to do something like:
client = SPARQL::Client.new 'http://dbpedia.org/sparql/'
client.count(:uri).where([:uri, RDF.type, RDF::OWL.Class])
--> 73
I am using the following monkey-patch to do that: https://gist.github.com/3053508 - there must be a cleaner way to do it though.
I just ran into a situation where I unfortunately had to abandon sparql-client for a query because I needed to restrict one of the variables using a VALUES
list. Is there any chance of supporting this in a future version?
Example code
require 'sparql/client'
SPARQL::Client::Query
.select
.where(%i[s p o])
.values(:s, RDF::URI('http://example.com/1'), RDF::URI('http://example.com/2'))
Result
$ bundle exec ruby /foo/bar/test.rb"
Traceback (most recent call last):
6: from /foo/bar/test.rb:5:in `<main>'
5: from /foo/bar/tmp/bundle/ruby/2.6.0/gems/sparql-client-3.0.1/lib/sparql/client/query.rb:598:in `values'
4: from /foo/bar/tmp/bundle/ruby/2.6.0/gems/sparql-client-3.0.1/lib/sparql/client/query.rb:598:in `map'
3: from /foo/bar/tmp/bundle/ruby/2.6.0/gems/sparql-client-3.0.1/lib/sparql/client/query.rb:599:in `block in values'
2: from /foo/bar/tmp/bundle/ruby/2.6.0/gems/sparql-client-3.0.1/lib/sparql/client/query.rb:599:in `map'
1: from /foo/bar/tmp/bundle/ruby/2.6.0/gems/sparql-client-3.0.1/lib/sparql/client/query.rb:603:in `block (2 levels) in values'
/foo/bar/tmp/bundle/ruby/2.6.0/gems/rdf-3.0.12/lib/rdf/mixin/enumerable.rb:761:in `method_missing': undefined local variable or method `graph_uri_or_var' for #<SPARQL::Client::Query:0x00007f95858a65c0> (NameError)
Process finished with exit code 1
The line raises exception is
sparql-client/lib/sparql/client/query.rb
Line 603 in 8957d3a
I think the return might be local variable nil_literal_or_term
instead of graph_uri_or_var
.
Since Ruby 2.7 a warning is shown:
.../lib/sparql/client.rb:10: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
.../.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sparql-client-3.1.0/lib/sparql/client.rb:311: warning: The called method `query_without_retry' is defined here
I noticed that the example in the docs for query.prefix produces a malformed query
require 'sparql/client'
client = SPARQL::Client.new('http://dbpedia.org/sparql')
query = client.select.
prefix(dc: RDF::URI("http://purl.org/dc/elements/1.1/")).
prefix(foaf: RDF::URI("http://xmlns.com/foaf/0.1/")).
where([:s, :p, :o])
puts query.to_s
# "PREFIX {:dc=>RDF::URI(<http://purl.org/dc/elements/1.1/>)} PREFIX {:foaf=>RDF::URI(<http://xmlns.com/foaf/0.1/>)} SELECT * WHERE { ?s ?p ?o . }"
query.each_solution do |solution|
puts solution.inspect
end
# <SPARQL::Client::MalformedQuery: Virtuoso 37000 Error SP030: SPARQL compiler, line 1: syntax error at '{' before ':dc'
# SPARQL query:
# PREFIX {:dc=>RDF::URI(<http://purl.org/dc/elements/1.1/>)} PREFIX {:foaf=>RDF::URI(<http://xmlns.com/foaf/0.1/>)} SELECT * WHERE { ?s ?p ?o . } Processing query PREFIX {:dc=>RDF::URI(<http://purl.org/dc/elements/1.1/>)} PREFIX {:foaf=>RDF::URI(<http://xmlns.com/foaf/0.1/>)} SELECT * WHERE { ?s ?p ?o . }>
Related to #4
How can I use wildcard in any of the triple attributes.
After adding PREFIX support, I noticed that I can't actually use it because of the way Query#where works:
>> SPARQL::Client::Query.select.prefix("dc: <http://purl.org/dc/elements/1.1/>").where([:s, :p, RDF::URI.new('dc:abstract')]).to_s
=> "PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT * WHERE { ?s ?p <dc:abstract> . }"
The above query isn't valid because I need 'dc:abstract' instead of 'dc:abstract'.
To fix this I looked inside RDF::Query::Pattern#to_s and noticed '<%s>' is hardcoded. From the fixme I'm guessing this behavior will eventually be moved into a Statement instance method.
But even when this is done, I'll still need a RDF::Value subclass which just returns the original string. I looked for one and didn't find one.
The solution I propose is just to add this as the first case statement in SPARQL::Client::Query#serialize_value:
when !value.is_a?(RDF::Value) then value.to_s
This would allow the above example to do:
>> SPARQL::Client::Query.select.prefix("dc: <http://purl.org/dc/elements/1.1/>").where([:s, :p, 'dc:abstract']).to_s
=> "PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT * WHERE { ?s ?p dc:abstract . }"
An added benefit to this change would be that any SPARQL syntax that isn't supported yet can just be passed as a string i.e. blank nodes:
>> SPARQL::Client::Query.select.where([ :s, :p, '[]' ])
=> "SELECT * WHERE { ?s ?p [] . }
Thoughts?
Gabriel
Hello, RDF.rb is awesome library suite, but can you explain the RDF::Repository
accessing feature?
I'm trying to do the following things:
puts 'Pure RDF'
repo = RDF::Repository.load('ontology.owl')
repo.each_subject { |s| p s }
puts 'SPARQL'
repo = SPARQL::Client::Repository.load('ontology.owl')
repo.each_subject { |s| p s }
p repo.client.ask.whether([:s, :p, :o]).true?
But all I see is just the following output instead of expected behavior:
Pure RDF
#<RDF::Node:0x16c16a4(_:g23860900)>
#<RDF::Node:0x16bd9a0(_:g23845280)>
#<RDF::Node:0x16b3ec8(_:g23805640)>
#<RDF::Node:0x16ae824(_:g23783460)>
...
SPARQL
/home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:472:in `connection_for': undefined method `downcase' for nil:NilClass (NoMethodError)
from /home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:806:in `request'
from /home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/sparql-client-0.1.1.1/lib/sparql/client.rb:300:in `get'
from /home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/sparql-client-0.1.1.1/lib/sparql/client.rb:124:in `response'
from /home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/sparql-client-0.1.1.1/lib/sparql/client.rb:111:in `query'
from /home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/sparql-client-0.1.1.1/lib/sparql/client.rb:90:in `block in call_query_method'
from /home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/sparql-client-0.1.1.1/lib/sparql/client/query.rb:276:in `result'
from /home/eveel/.rvm/gems/ruby-1.9.3-p194/gems/sparql-client-0.1.1.1/lib/sparql/client/query.rb:236:in `true?'
from test.rb:22:in `<main>'
Am I right? I just want to execute SPARQL queries with sparql-client against my ontology.
Is allowed Inferece? I need query with infer...
Using the sparql-client
gem, the results of queries with embedded quotes differ from when using the linkeddata
gem.
Expected Results:
Actual Results:
When I run the following code:
require 'linkeddata'
# require 'sparql/client'
sparql = SPARQL::Client.new("http://data.americanartcollaborative.org/sparql")
uri = RDF.URI("http://data.crystalbridges.org/object/2258")
label = RDF.URI("http://www.w3.org/2000/01/rdf-schema#label")
query = sparql.construct([uri, label, :o]).where([uri, label, :o])
query.each_statement {|s| puts s.inspect}
I get the results I expect:
#<RDF::Statement:0x3fdd71454f78(<http://data.crystalbridges.org/object/2258> <http://www.w3.org/2000/01/rdf-schema#label> "Bison-Dance of the Mandan Indians in front of their Medicine Lodge in Mih-Tuta-Hankush" .)>
#<RDF::Statement:0x3fdd71440a78(<http://data.crystalbridges.org/object/2258> <http://www.w3.org/2000/01/rdf-schema#label> "From \"Voyage dans l’intérieur de l’Amérique du Nord, executé pendant les années 1832, 1833 et 1834, par le prince Maximilien de Wied-Neuwied\" (Paris & Coblenz, 1839-1843)" .)>
but when I comment out the linkeddata
gem and instead use just the sparql-query
gem the results with embedded quotes no longer work, and my results look like:
#<RDF::Statement:0x3fd7f58e2ee0(<http://data.crystalbridges.org/object/2258> <http://www.w3.org/2000/01/rdf-schema#label> "Bison-Dance of the Mandan Indians in front of their Medicine Lodge in Mih-Tuta-Hankush" .)>
#<RDF::Statement:0x3fd7f58df2a4(<http://data.crystalbridges.org/object/2258> <http://www.w3.org/2000/01/rdf-schema#label> "From " .)>
I'm using ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16], and I'm using a gemfile that includes the line gem "linkeddata", '~> 2.1.0'
, and the Gemfile.lock file says I'm using
sparql-client (2.1.0)
linkeddata (2.1.0)
Dear developers,
I'm trying to upload some triples with SPARQL insert. For example i tried to insert a triple describing a 'title'. If it contains special characters or a german umlaut the following error is returned by the sparql client:
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sparql-client-3.0.0/lib/sparql/client.rb:351:in `block in response': Error 500: 400: Unable to parse form content (SPARQL::Client::ServerError)
...
Processing query INSERT DATA {
<http://kb.esit4sip.eu/learning-instances/dbc6b574906c57e6f531edcfa2df82ba> <http://kb.esit4sip.eu/learning/title> "!§$%&/()=?`*áé" .
}
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sparql-client-3.0.0/lib/sparql/client.rb:704:in `call'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sparql-client-3.0.0/lib/sparql/client.rb:704:in `block in request'
Futhermore my fuseki (3.8.0) server returns this error:
[2018-08-02 13:51:33] Fuseki INFO [1] POST http://localhost:3030/esit4sip-test1/update
[2018-08-02 13:51:33] Fuseki WARN [1] RC = 500 : 400: Unable to parse form content
org.eclipse.jetty.http.BadMessageException: 400: Unable to parse form content
at org.eclipse.jetty.server.Request.getParameters(Request.java:376)
at org.eclipse.jetty.server.Request.getParameterValues(Request.java:1049)
at javax.servlet.ServletRequestWrapper.getParameterValues(ServletRequestWrapper.java:221)
... ...
Caused by: org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! byte F5 in state 0
at org.eclipse.jetty.util.Utf8Appendable.appendByte(Utf8Appendable.java:247)
at org.eclipse.jetty.util.Utf8Appendable.append(Utf8Appendable.java:157)
at org.eclipse.jetty.util.UrlEncoded.decodeUtf8To(UrlEncoded.java:522)
at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:572)
at org.eclipse.jetty.server.Request.extractFormParameters(Request.java:525)
at org.eclipse.jetty.server.Request.extractContentParameters(Request.java:457)
at org.eclipse.jetty.server.Request.getParameters(Request.java:372)
... 50 more
[2018-08-02 13:51:33] Fuseki INFO [1] 500 400: Unable to parse form content (37 ms)
Here is the ruby code I'm using:
sparql = SPARQL::Client.new(SPARQL_ENDPOINT)
graph = RDF::Graph.new
title = "a german umlaut: ä "
graph << [LEARNING_INSTANCES[resource_id], LEARNING['title'], title]
sparql.insert_data(graph)
As soon as I'm using a title without special characters everything works fine with the sparql client. Furthermore, if I'm using the fuseki web-gui, the umlaut title is accepted. So it seems that the character encoding is making some trouble. Because I'm not an expert when it comes to programming, I can't say if this error comes from the sparql-client, fuseki or the jetty server. My google research didn't bring me further too. So feel free to comment, if this error does not come from the client.
I'm using the following software:
Thank you
Alexander
Code:
gem 'sparql-client', '~> 1.1.2'
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
result = sparql.ask.whether([:s, :p, :o]).true?
Error:
/home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:410:in fail_subject': ERROR [line 1] Expected subject (found: "{ \"head\": { \"link\": [] }, \"boolean\": true}") (RDF::ReaderError) from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/ntriples/reader.rb:210:in
block in read_triple'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/ntriples/reader.rb:204:in loop' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/ntriples/reader.rb:204:in
read_triple'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:391:in read_statement' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:308:in
block in each_statement'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:308:in loop' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:308:in
each_statement'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/util/aliasing.rb:46:in block in alias_method' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/mixin/countable.rb:12:in
empty?'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/sparql-client-1.1.2/lib/sparql/client/query.rb:268:in true?' from /home/USER/tutorial_workspace/sentiment_dev/sparql_query.rb:6:in
Hello, i'm currently using you gem which work well on de development mode but when i turn "config.cache_classes" (on rails) to true, my sparql requests don't give me results. And when i turn back "config.cache_classes" to false i have my results back.
the code:
$endpoint = "http://fr.dbpedia.org/sparql"
query = "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT * WHERE{
?a ?b ?c
} LIMIT 10"
store = SPARQL::Client.new($endpoint)
store.query(query).each do |item|
puts item[:label].value
end
thanks for this good tool, chris
I'm not sure how broadly this issue applies, for but for Open RDF Sesame, the update URL endpoint is host:port/openrdf-sesame/repositories/name/statements
, not host:port/openrdf-sesame/repositories/name
(the query endpoint).
As written, the SPARQL::Client#update
method sends the request to the same query endpoint (but with the form key update=
rather than query=
. This causes the server to respond back with a 400 Bad Request saying Missing parameter: query
.
If this is an issue that is true for all repositories, SPARQL::Client#update
should just append "/statements" to the path and be done with it. But if there is variation among different RDF servers, it's probably prudent to parameterize this in the #upload
call.
Hi,
I want to demonstrate the functionality of sparql-client
s querying API; therefore I want to translate the following query string into API calls:
%q(
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?country ?population
WHERE {
?country a dbpedia-owl:Country .
?country dbpprop:populationCensus ?population .
FILTER ( isNumeric(?population) && ?population > 50000000 )
}
ORDER BY DESC(?population)
LIMIT 5
)
=>
# - define ad-hoc vocabs
DBP_ONT = RDF::Vocabulary.new('http://dbpedia.org/ontology/')
DBP_PROP = RDF::Vocabulary.new('http://dbpedia.org/property/')
client = SPARQL::Client.new('http://dbpedia.org/sparql')
# - define SPARQL query
query = client.select(:country, :population)
.where([ :country, RDF.type, DBP_ONT.Country ])
.where([ :country, DBP_PROP.populationCensus, :population ])
# ...
but I just don't know how to "translate" the FILTER
and the ORDER BY
DESC
parts. Anyone done that and can support me here?
I am pretty sure this is just a very simple mistake on my side but I am not able to find any clues on google or elsewhere.
If I use sparql_client inside a rails 3.07 app to query against a local 4store or virtuoso sparql-endpoint the query results in an
EOFError
end of file reached exception.
sparql_client = SPARQL::Client.new("http://localhost:8890/sparql/")
result = sparql_client.query("SELECT * WHERE { ?s ?p ?o } LIMIT 10")
Against the dbpedia endpoint the same query works perfectly.
I am pretty sure I have set up my local sparql-endpoints as they should be - and using a simple http request as below returns a valid result.
query = "SELECT * WHERE { ?s ?p ?o } LIMIT 10"
baseURL = "http://localhost:8890/sparql/"
sparqlURL=baseURL+"?query=#{CGI.escape query}"
response = Net::HTTP.get_response(URI.parse(sparqlURL))
Any Idea what this may be causing?
I found a strange in HTTP headers made by sparql-client.
I dumped request header, and I could find 'Accept' header as below,
application/sparql-results+json, application/sparql-results+xml, text/boolean, text/tab-separated-values;p=0.8, text/csv;p=0.2, */*;p=0.1
I assume the quality parameter is q=?.?
, not p=?.?
.
This page may help,
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Thanks.
Reproduce steps:
sparql = SPARQL::Client.new("http://api.kasabi.com/dataset/foodista/apis/sparql?apikey=hi")
sparql.inspect
=> #SPARQL::Client:0xc90810(http://api.kasabi.com/dataset/foodista/apis/sparql?apikey=hi)
sparql.query(
"PREFIX dct: http://purl.org/dc/terms/
PREFIX f: http://linkedrecipes.org/schema/
PREFIX foaf: http://xmlns.com/foaf/0.1/
SELECT ?uri ?title ?recipePage WHERE {
?uri a f:Recipe;
dct:title ?title;
foaf:isPrimaryTopicOf ?recipePage;
<ngredient http://data.kasabi.com/dataset/foodista/food/4CXZ7VHS;
<ngredient http://data.kasabi.com/dataset/foodista/food/CX8CMQHZ.
}
LIMIT 10"
)
=> SPARQL::Client::ClientError: HTTP/1.1 403 Forbidden
The fix should be easy enough - just altering https://github.com/bendiken/sparql-client/blob/master/lib/sparql/client.rb#L287 to merge, not replace query_values
SPARQL::Client::Repository#query_pattern
runs afoul of a restriction in SPARQL about the allowed blank node labels in queries. I suspect most SPARQL implementations will just interpret these as two unique blank nodes without problem, but I noticed that Blazegraph throws errors and it seems technically correct to do so.
We have the option to change the node labels within the method, here; better might be to find a place somewhere in Pattern
to change the blank node labels so they won't be repeated.
Thoughts?
I'm looking to do this kind of SQPARQL query: (to http://dbpedia.org/sparql/ )
SELECT DISTINCT ?name ?country ?abstract ?coords
WHERE { ?city rdf:type dbpedia-owl:City ;
rdfs:label ?name ;
dbpedia-owl:country ?country;
dbpedia-owl:abstract ?abstract;
grs:point ?coords
FILTER (regex(?name, 'Abilene, Texas') && langmatches(lang(?name), "EN") && langmatches(lang(?abstract), "EN"))
I've tried some way to write it with the select/where/filter methods, but without success. Is it possible it with them? Otherwise I'll stay on
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
results = sparql.query("QUERY")
Thank you
Hello,
I'm already sorry if this question is totally irrelevant. I'm don't know Ruby at all but I show the issue to a few Ruby developers and none of them found a solution to it.
Here is the piece of code that is puzzling me in the SPARQL::Client:
def update(query, options = {})
@op = :update
@alt_endpoint = options[:endpoint] unless options[:endpoint].nil?
case @url
when RDF::Queryable
require 'sparql' unless defined?(::SPARQL::Grammar)
SPARQL.execute(query, @url, options.merge(update: true))
else
parse_response(response(query, options), options) # <------- here
end
self
end
As you can see. The result of the request is parsed but it is not stored and I believe it is not accessible to the caller since this method returns self.
Is there some magic somewhere that allows retrieving the parsed result?
Thanks
Anyone given any thought to implementing property paths?
SPARQL MINUS
is missing from the DSL, and are hard to write into queries created using SPARQL::Client::Query
.
We should consider ways to support this through the query builder.
Using a SPARQL rack/sinatra endpoint and RSpec::Rake update SPARQL::Client::Repository to use SPARQL gem for tests.
Requires support for SPARQL 1.1 Update. ruby-rdf/sparql#18
Hi, may be i'm not clearly understand Sparql Client, but i didn't find way how to define graph repository
For example, i follow to http://dbpedia.org/sparql and define Default Graph URI http://tema.livejournal.com/data/foaf.rdf and Query text Select select ?name WHERE { ?x foaf:knows ?name} (all this i do in web browser)
BUT!!! where i should define Default Graph URI in Sparql Client library?
Thanks
Originally reported by ekolvets:
Due to Net::HTTP's dependence on URI, SPARQL::Client connections to https endpoints fail because Net::HTTP::Persistent attempts to connect to port 80 instead of port 443.
URI.parse('https://dbpedia.org/').port # returns 443
Addressable::URI.parse("https://dbpedia.org/").port # returns nil
# queries with this wil fail
sparql = SPARQL::Client.new("https://dbpedia.org/sparql")
# queries with this will succeed
sparql = SPARQL::Client.new("https://dbpedia.org:443/sparql")
Not sure if this is a bug, but its something users should be aware of. The root of the issue is inside of Net::HTTP::Persisent where uri.address and uri.port are passed in to Net::HTTP.new(). Net::HTTP documents its dependence on URI, so I'm not sure if Net::HTTP::Persistent should change to work with Addressable::URIs or whether SPARQL::Client should be passing in a URI instead of an Addressable::URI.
Hello,
This issue is probably not related to you directly but I believe it can brings something good to this project. So please take it as a proposal of improvement for this project.
Here is my proposal:
I may be wrong but your version format looks like semantic versioning. Therefore it would be nice if you maintain a branch my MAJOR.MINOR.x version (1.99.x, 2.0.x, etc...). Every fixes should cherry-picked on every branch. And from time to time, you release a fixed version of the branch by tagging a commit in the specific branch with all the fixes and increasing the x value.
Which basically means that the fixes that got merged in the develop branch can be merged to 1.99.x and 2.0.x and can fix already released versions. (If they are considered as "fixes" (this can be argued)).
Why am I proposing this?
So the question is... cui bono? 😀 Well... _me_ in the first place because the maintainers of the public repository I'm currently "fixing" are reluctant to merge my PR because it's close to dirty monkey patching. Which is totally true 😄
So, there aren't many solutions:
So what do you think?
In brief:
(And I can help)
Thanks for taking time to read this
Additional info: a colleague just pointed out that the rubygems.org recommends the semantic versioning: http://guides.rubygems.org/patterns/#semantic-versioning
Hello,
I want to retrieve a TTL from a virtuoso endpoint.
query(construct_query).each_statement do |statement|
puts statement.inspect
end
The construct query returns ~652977 statements.
CONSTRUCT {
?s ?p ?o
}
FROM <http://tempgraph>
WHERE {
?s ?p ?o .
}
But I get a segmentation fault.
/usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:209: [BUG] Segmentation fault at 0x00000000000000
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0057 p:---- s:0289 e:000288 CFUNC :raptor_parser_parse_chunk
c:0056 p:0018 s:0282 E:001128 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:209
c:0055 p:0025 s:0278 E:001198 RESCUE /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:163
c:0054 p:0056 s:0275 E:001be0 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:157
c:0053 p:0175 s:0268 E:0006d8 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:92
c:0052 p:0018 s:0262 E:000110 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi.rb:118
c:0051 p:0048 s:0257 E:001290 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi.rb:84
c:0050 p:0130 s:0252 E:000f38 METHOD /app/lib/queries.rb:146
... etc
However testing to query the virtuoso endpoint via HTTP directly the result is successfully fetched and created.
require 'net/http'
require 'linkeddata'
require 'cgi'
query = "CONSTRUCT { ?s ?p ?o } FROM <http://tempgraph> WHERE { ?s ?p ?o . }"
baseURL = "http://localhost:8890/sparql/"
sparqlURL=baseURL+"?query=#{CGI.escape query}"
response = Net::HTTP.get_response(URI.parse(sparqlURL))
File.open("response.ttl", "wb") do |res|
res.puts response.body
end
And it creates the full TTL
$ cat response.ttl | wc -l
652996
Going through the SELECT example in the README, I noticed execute() wasn't being triggered. The example in the README therefore returns an empty array.
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
query = sparql.select.where([:s, :p, :o]).offset(100).limit(10)
query.each_solution do |solution|
puts solution.inspect
end
You can't query Wikidata without an User-Agent, so I propose to leave a note in the README to say that you should do things like:
SPARQL::Client.new(endpoint, :method => :get, :headers => { 'User-Agent': 'MyBotName'})
to use Wikidata.
Hi there,
I've been struggling with a problem for a while now in my rails of unclosed connections leading to the app exceeding its limits and returning errors like:
Error during failsafe response: Too many open files @ rb_sysopen - /app/app/views/errors/internal_server_error.html.erb
After making sure every open-uri request is closed and no luck solving the problem I've started investigating deeper.
using lsof I've noticed each page request delivers the following
TCP 192.168.0.22:52703->144.126.4.43:http (CLOSE_WAIT)
ruby 8093 jcwitt 50u IPv4 0x47acd29a34c3cb9b 0t0 TCP 192.168.0.22:52800->144.126.4.43:http (CLOSE_WAIT)
ruby 8093 jcwitt 51u IPv4 0x47acd29a34bd9b9b 0t0 TCP 192.168.0.22:52803->144.126.4.43:http (CLOSE_WAIT)
ruby 8093 jcwitt 52u IPv4 0x47acd29a2bec3f7b 0t0 TCP 192.168.0.22:52804->144.126.4.43:http (CLOSE_WAIT)
ruby 8093 jcwitt 53u IPv4 0x47acd29a33acf23b 0t0 TCP 192.168.0.22:52704->144.126.4.43:http (CLOSE_WAIT)
ruby 8093 jcwitt 54u IPv4 0x47acd29a2df4723b 0t0 TCP 192.168.0.22:52705->144.126.4.43:http (CLOSE_WAIT)
and as the app gets used the number of (CLOSE_WAIT) files keeps climbing, about 5 per page requests.
Using the IP, I learned that these requests are being made with the following snippet of code
sparql = SPARQL::Client.new(sparqlendpoint) result = sparql.query(query) return result
BTW I'm using sparql-client (~> 2.0).
So I'm wondering if I'm doing something wrong with the way I'm using SPARQL::Client or perhaps I've found a bug and SPARQL::Client should be closing connections and is not.
https://github.com/ruby-rdf/sparql-client/blob/develop/lib/sparql/client.rb#L726-L731
Among other places a http request is being opened at line 729.
Is getting closed anywhere?
I appreciate any help you can provide.
When running the README examples with SPARQL::Client 0.0.2 and RDF.rb 0.1.6:
irb(main):005:0> query = sparql.select.where([:s, :p, :o]).offset(100).limit(10)
=> #<SPARQL::Client::Query:0x810c3768(SELECT * WHERE { ?s ?p ?o . } OFFSET 100 LIMIT 10)>
irb(main):006:0> query.each_solution do |solution|
irb(main):007:1* puts solution.inspect
irb(main):008:1> end
NoMethodError: undefined method `is_a?' for #<RDF::Query::Solution:0x1020decd0>
from /opt/local/lib/ruby/gems/1.8/gems/rdf-0.1.6/lib/rdf/query/solution.rb:134:in `method_missing'
from /opt/local/lib/ruby/gems/1.8/gems/rdf-0.1.6/lib/rdf/query.rb:88:in `each_solution'
from /opt/local/lib/ruby/gems/1.8/gems/rdf-0.1.6/lib/rdf/query.rb:87:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/rdf-0.1.6/lib/rdf/query.rb:87:in `each_solution'
from (irb):6
I have a qurey :
result = sparql.query("SELECT * WHERE { ?s ?p ?o }")
result is "RDF::Query::Solution"
I need de result in RDF/XML, any suggest?
SERVICE is a feature of SPARQL 1.1 that allows an executing query to make a SPARQL protocol to another SPARQL endpoint.
It is very helpful to retrieve labels, as it reduces the complexity of SPARQL queries, but is not implemented in sparql-client yet.
From the README, I ran
require 'rubygems'
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
result = sparql.ask.whether([:s, :p, :o]).true?
puts result.inspect #=> true or false
but it seems sparql-client is not sending the query
Virtuoso 22023 Error The request does not contain text of SPARQL query (SPARQL::Client::MalformedQuery)
sparql/client.rb uses direct http connection to talk to SPARQL end points.
We have a use case for writing a query where the FILTER statement resides inside an OPTIONAL clause. The query was given to us by our triple store support engineers (AllegroGraph). The query looks like this:
SELECT DISTINCT ?id ?prefLabel ?synonym
FROM <http://data.bioontology.org/ontologies/CSV_TEST_BRO/submissions/1>
WHERE {
?id a <http://www.w3.org/2002/07/owl#Class> .
OPTIONAL {
?id ?rewrite0 ?prefLabel .
FILTER(?rewrite0 = <http://data.bioontology.org/metadata/def/prefLabel> ||
?rewrite0 = <http://www.w3.org/2004/02/skos/core#prefLabel>)
}
OPTIONAL {
?id ?rewrite1 ?synonym .
FILTER(?rewrite1 = <http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> ||
?rewrite1 = <http://purl.obolibrary.org/obo/synonym> ||
?rewrite1 = <http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym>)
}
FILTER(?id = <http://bioontology.org/ontologies/Activity.owl#Activity> ||
?id = <http://bioontology.org/ontologies/Activity.owl#Biospecimen_Management> ||
?id = <http://bioontology.org/ontologies/Activity.owl#Community_Engagement> ||
?id = <http://bioontology.org/ontologies/Activity.owl#Deprecated_Activity>)
}
I've reviewed the sparql-client API and didn't find an obvious way to embed a FILTER statement inside an OPTIONAL block. I wanted to check with you to make sure I'm not missing anything obvious. Is it possible to construct such a query without customizing the sparql-client?
Thank you!
sparql/client.rb uses direct http connection to talk to SPARQL end points.
Unesco provide a sparql endpoint http://vocabularies.unesco.org/sparql-form/
The first example on that page is
SELECT ?s ?p ?o
WHERE {
?s ?p ?o .
}
LIMIT 100
I tried to do the same thing using the sparql-client but I the following error:
sparql = SPARQL::Client.new("http://vocabularies.unesco.org/sparql")
query = sparql.select.where([:s, :p, :o]).limit(100)
query.each_solution {|solution| puts solution}
# error
SPARQL::Client::ServerError: Infinite redirect at http://vocabularies.unesco.org/sparql. Redirected more than 10 times.
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/sparql-client-1.99.1/lib/sparql/client.rb:699:in `request'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/sparql-client-1.99.1/lib/sparql/client.rb:344:in `response'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/sparql-client-1.99.1/lib/sparql/client.rb:305:in `query'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/sparql-client-1.99.1/lib/sparql/client.rb:270:in `block in call_query_method'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/sparql-client-1.99.1/lib/sparql/client/query.rb:416:in `result'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/sparql-client-1.99.1/lib/sparql/client/query.rb:409:in `each_solution'
from (irb):120
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/$user/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
http://vocabularies.unesco.org/sparql does redirect to http://vocabularies.unesco.org/sparql-form/,
but if the url has all the required params, e.g. this uri, generated by selecting the first query on the page and clicking run query, it resolves.
I'm not sure whether this is an issue with
I'm probably going to switch to using a regular http get for now using the url generated by the page,
but ideally I'd like to build the query using ruby. Thanks in advance!
Performing the following query:
select * where {<http://pl.dbpedia.org/resource/Ch%C5%82opi_%28powie%C5%9B%C4%87%29> <http://pl.dbpedia.org/property/językOrygWyd> ?value}
an exception is raised
incompatible character encodings: ASCII-8BIT and UTF-8
/home/fox/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:331:in `gsub'
/home/fox/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:331:in `unescape'
/home/fox/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:649:in `unescape'
/home/fox/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.6/lib/rdf/model/uri.rb:1276:in `normalize_segment'
/home/fox/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.6/lib/rdf/model/uri.rb:1240:in `block (2 levels) in query_values='
/home/fox/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.6/lib/rdf/model/uri.rb:1236:in `map'
/home/fox/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.6/lib/rdf/model/uri.rb:1236:in `block in query_values='
/home/fox/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.6/lib/rdf/model/uri.rb:1231:in `each'
/home/fox/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.6/lib/rdf/model/uri.rb:1231:in `map'
/home/fox/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.6/lib/rdf/model/uri.rb:1231:in `query_values='
/home/fox/.rvm/gems/ruby-2.1.2/gems/sparql-client-0.0.11/lib/sparql/client.rb:294:in `get'
/home/fox/.rvm/gems/ruby-2.1.2/gems/sparql-client-0.0.11/lib/sparql/client.rb:124:in `response'
/home/fox/.rvm/gems/ruby-2.1.2/gems/sparql-client-0.0.11/lib/sparql/client.rb:111:in `query'
./lib/download_authors.rb:12:in `get_values'
./lib/download_authors.rb:25:in `<main>'
The reason for that is the presence of ę
in the result which is passed to URI library.
Most tests are failing in 1.8.6 and 1.8.7 due to a whitespace issue starting from here http://github.com/bendiken/sparql-client/blob/3e000c36a84cfc8f9e4158ebe04fc7cb18651e80/lib/sparql/client/query.rb#L236
A failed test example:
7)
'SPARQL::Client::Query when building SELECT queries should support OFFSET' FAILED
expected: "SELECT * WHERE { ?s ?p ?o . } OFFSET 100",
got: "SELECT * WHERE { ?s ?p ?o . } OFFSET 100" (using ==)
./spec/query_spec.rb:64:
I don't mind forking and fixing as long as I know whether you want the whitespace removed from the tests or the library.
I get the following error:
>> client = SPARQL::Client.new('http://data.linkedmdb.org/sparql')
>> result = client.query('DESCRIBE ?kb WHERE { ?kb http://data.linkedmdb.org/resource/movie/actor_name "Kevin Bacon" . }')
>> result.map {|e| e.to_hash }
RDF::ReaderError: expected subject in #StringIO:0x19b37f4 line 2
from /Library/Ruby/Gems/1.8/gems/rdf-0.1.10/lib/rdf/reader.rb:177:in fail_subject' from /Library/Ruby/Gems/1.8/gems/rdf-0.1.10/lib/rdf/ntriples/reader.rb:176:in
read_triple'
from /Library/Ruby/Gems/1.8/gems/rdf-0.1.10/lib/rdf/ntriples/reader.rb:170:in loop' from /Library/Ruby/Gems/1.8/gems/rdf-0.1.10/lib/rdf/ntriples/reader.rb:170:in
read_triple'
from /Library/Ruby/Gems/1.8/gems/rdf-0.1.10/lib/rdf/reader.rb:165:in `read_statement'
I printed debug statements and found the error was occurring on the first line of the result on @prefix
. Here's the results returned by the above query. Since @prefix
is n3 notation, it seems @client.query
is detecting the wrong format in @client.parse_rdf_serialization
. I have rdf-n3 installed but it doesn't seem to be picking it up. This may be the website's fault for returning the wrong content type. If that's the case, perhaps @client.query
should take an option to explicitly set the reader in @client.parse_rdf_serialization
.
Thoughts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.