Search code examples
sparqlrdfnamed-graphs

SPARQL Insert Into New Graph


I'm new to SPARQL/graph databases and am trying to insert some data into a new named graph in my graph database.

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

When I run this query, the graph "new_graph" is created but it contains no data. If I run the same query with a SELECT statement, it returns the data that it should, so the problem is likely in the INSERT section of the query.


Solution

  • I hope that the problem as been fixed since, but for the sake of it, it should work, could you provide a set of data like this (if I understand your intention):

    creation of the test data, a graph <http://example/shelf_A> is created with two resources, an author and a book referring to this author:

    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> .  
        } 
    }
    

    we create a second graph with the books referring to this author and state that they are in the previous graph:

    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"
    }
    

    the result are two graphs:

    graph http://example/shelf_A:

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

    graph http://example/shelf_B:

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