Is it possible to combine those 2 SPARQL INSERT in

2019-08-06 09:31发布

问题:

I want to perform the following queries, to add a relation skos:related between node a and node b :

  PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
  INSERT { GRAPH ?graph { ?a skos:related ?b } }
  WHERE{
    GRAPH ?graph {
      { ?a skos:inScheme ?scheme } .
      { ?b skos:inScheme ?scheme }
    }
 };
 INSERT { GRAPH ?graph { ?b skos:related ?a } }
 WHERE{
   GRAPH ?graph {
     { ?a skos:inScheme ?scheme } .
     { ?b skos:inScheme ?scheme }
   }
 };

I would prefer to send a single query to the RDF store, but can't find a way to do so. Obviously, the queries are here in generic form, and ?a, ?b, ?scheme and ?graph variables are bound with specific values at execution.

Is there a way?

回答1:

Can't you just assert both directions of the skos:related relation in a single query pattern? I.e.:

PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
INSERT { GRAPH ?graph { ?a skos:related ?b . ?b skos:related ?a } }
WHERE{
  GRAPH ?graph {
    { ?a skos:inScheme ?scheme } .
    { ?b skos:inScheme ?scheme }
  }
};


标签: rdf sparql