无法设置RDF Graph的上下文

时间:2014-10-01 15:34:04

标签: ruby rdf sesame

我试图给出三元组的背景:

repo = Sesame_Repository.new("http://localhost:8080/openrdf-sesame/repositories/CONTEXT")
graph = RDF::Graph.new

sub = RDF::URI("https://force.it/base")
pre = RDF::URI("https://force.it/has")
obj = RDF::Literal("ABC Weapons")
context = RDF::URI("https://force.it")

graph << [sub, pre, obj, context]
graph.each_statement do |statement|
repo.public_insert_statement(statement)
end

但是没有设定上下文。这不可能了吗?或者我如何设置上下文到我的图表?

(我可以保存三元组,但是当我添加上下文时,它会保存上下文和三元组)

编辑:当使用存储库而不是图形时,上下文保持空白

graph = RDF::Repository.new << RDF::Statement.new(sub, pre, obj, :context => RDF::URI("https://force.it"))

1 个答案:

答案 0 :(得分:1)

感谢gkellog(ruby rdf gem的开发人员):“图形是三元组的简单容器。当它创建时,你可以为它提供单个上下文。这是因为图形实际上是命名图形的投影来自存储库(dataset)。在这个例子中你可以使用RDF :: Repository而不是RDF :: Graph,因为存储库确实支持上下文.RDF概念是Quad,其中最后一个e,事件是一个选项图名(uri或BNode)。上下文的概念可以在RDF.rb中提到。“这个话题得到了更多澄清。 - to the github-issue of ruby RDF

芝麻的解决方案:

# create repository from public Sesame_Repository (see lib/rdf/sesame_repo.rb)
repo = Sesame_Repository.new("http://localhost:8080/openrdf-sesame/repositories/CONTEXT")
#Save Context
repo.set_context(RDF::URI("https://force.it/"))

# --intialize graph for sesame --
#create triple  
sub = RDF::URI("https://force.it/base")
pre = RDF::URI("https://force.it/has")
obj = RDF::Literal("Machinegun")
 # save triple to the repo
graph = RDF::Repository.new << RDF::Statement.new(sub, pre, obj)
graph.each_statement do |statement|
   repo.public_insert_statement(statement)
    puts statement.inspect
end