SPARQL插入新图表

时间:2017-02-14 18:42:24

标签: sparql rdf

我是SPARQL /图形数据库的新手,我正在尝试将一些数据插入到我的图形数据库中的新命名图形中。

INSERT
{ GRAPH graphs:new_graph { ?code groups:memberOfGroup graphs:personGroup } } where 
{?code a obib:CRID .
 ?code obib:denotes ?person .
 ?person a obib:homoSapien .}

当我运行此查询时,会创建图形“new_graph”,但它不包含任何数据。如果我使用SELECT语句运行相同的查询,它将返回它应该的数据,因此问题可能出现在查询的INSERT部分。

1 个答案:

答案 0 :(得分:1)

我希望此问题已得到解决,但是为了解决这个问题,它应该可以解决,您能否提供这样的一组数据(如果我理解您的意图):

创建测试数据,使用两个资源(一个作者和一个引用该作者的书)创建了图<http://example/shelf_A>

PREFIX dcterms: <http://purl.org/dc/terms/>

INSERT DATA {
    # create graph <http://example/shelf_A> if it doesn't exist
    GRAPH <http://example/shelf_A> {
        # add triple (http://example/author, name, author)
        <http://example/author> dcterms:name "author" .

        # add triples (http://example/book, title, book)
        # and         (http://example/book, author, http://example/author)
        <http://example/book> dcterms:title "book" ;
                              dcterms:author <http://example/author> .  
    } 
}

我们用引用该作者的书创建第二张图,并声明它们在上一张图中:

PREFIX dcterms: <http://purl.org/dc/terms/>
INSERT
{
  # create graph is it doesn't exist
  GRAPH <http://example/shelf_B> {
    # add the triple (?bood, provenance, http://example/shelf_A)
    # ?book comes from the request below
    ?book dcterms:provenance <http://example/shelf_A> 
  } 
}
WHERE
{
  # select all books (?book) which have an author
  # and this author is named "author"
  ?book dcterms:author ?author .
  ?author dcterms:name "author"
}

结果是两个图:

http://example/shelf_A

http://example/author  dcterms:name          author
http://example/book    dcterms:author        http://example/author
http://example/book    dcterms:title         book

http://example/shelf_B

http://example/book    dcterms:provenance    <http://example/shelf_A>