【发布时间】:2014-01-16 15:32:35
【问题描述】:
我正在使用以下 ruby 库来查询 SPARQL 端点。 http://ruby-rdf.github.io/sparql-client/
我真的很接近实现我想要的。使用以下代码,我可以打印出数据库中的所有三元组。
sparql = SPARQL::Client.new("http://localhost:3030/ds/query")
query = sparql.select.where([:s, :p, :o]).offset(100).limit(1000)
query.each_solution do |solution|
puts solution.inspect
end
但现在我想稍微改变一下,选择给定主题的所有三元组。我认为以下方法会起作用,但它不起作用。
sparql = SPARQL::Client.new("http://localhost:3030/ds/query")
itemname = "lectio1"
query = sparql.select.where(["<http://scta.info/items/#{itemname}>", :p, :o]).offset(100).limit(1000)
query.each_solution do |solution|
puts solution.inspect
end
这可以在简单的 SPARQL 语法中使用,但是以某种方式将符号 :s 替换为我想要查询的文字主题不起作用。 Sinatra 给我的错误是:
预期的主题为 nil 或一个术语,为
"<http://scta.info/items/lectio1>";
【问题讨论】:
-
sparql.rubyforge.org/client/SPARQL/Client/Query.html 参见
where方法。这可能会有所帮助,我无法完全破译它 -
好的,你现在有答案了(我要删除其中的一些 cmets)