将SPARQL插入新图

问题描述 投票:0回答:1

我是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部分。

sparql rdf
1个回答
0
投票

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

创建测试数据,使用两个资源创建了图<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>
© www.soinside.com 2019 - 2024. All rights reserved.