I am currently working with the SPARQL Ruby on Rails client to try to get information from the SPARQL open endpoint in dbpedia. The general query that I run is the following:
query = " PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX prop: <http://dbpedia.org/property/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT * WHERE { ?city prop:name 'Antwerpen'@en; a dbo:PopulatedPlace; dbo:abstract ?abstract . FILTER langMatches( lang(?abstract), 'en') OPTIONAL { ?city foaf:homepage ?homepage } OPTIONAL { ?city rdfs:comment ?comment . FILTER langMatches( lang(?comment), 'en') } }"
This is a general query that returns some general city information from dbpedia. I checked it manually on the sparql endpoint and it receives the information that I expect it to return. However, I cannot find a way to parse the answer in Ruby on Rails.
I am currently trying to use RDF for Ruby and sparql-client . The code looks like this (based on examples I could find):
result = {} client = SPARQL::Client.new("http://dbpedia.org/sparql") client.query(query).first.each_binding { |name, value| result[name] << value} result
But I canβt get anything. When working with the debugger to manually enter variables, it just stops as soon as the query is executed, and I canβt even look at the return values.
Does anyone have a good example of how to execute a query with an SPARQL endpoint and parse the answer?
source share