-->

Sesame repository not being updated using INSERT d

2019-08-03 09:24发布

问题:

I am trying to update a Sesame repository with data from dbpedia. I have the following query:

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

INSERT{?s ?p ?o}

WHERE {
 SERVICE <http://dbpedia.org/sparql>{

{:Rotavirus_vaccine ?p ?o.
}
UNION
{
?s ?p :Rotavirus_vaccine.
}
}
}

This query doesn't show any error doesn't update the repository. On the other hand, splitting the UNION into two separate queries and then updating the repository one by one works. Why do the queries work in isolation but not in union? The code of an individual query is:

INSERT{:Rotavirus_vaccine ?p ?o}        
WHERE {
SERVICE <http://dbpedia.org/sparql>{
{:Rotavirus_vaccine ?p ?o.
}
}
}

回答1:

?s ?p ?o must all be defined in a row for the template be meaningful. Any time a variable is not bound, no update is done.

In one branch of the UNION, ?s ?p are defined and in the other ?p ?o. So all 3 are not defined in the same row.

Either add a BIND or a FILTER e.g for the first part:

{:Rotavirus_vaccine ?p ?o. BIND(:Rotavirus_vaccine AS ?s) }

{?s ?p ?o. FILTER(?s = :Rotavirus_vaccine }

or use this

INSERT{:Rotavirus_vaccine ?p ?o.
       ?s ?p :Rotavirus_vaccine.
}

because exactly one of those is defined for each case.



回答2:

I've been able to execute a functional query by using BIND for both clauses of the UNION. The code is:

INSERT{?s ?p ?o} 
WHERE 
{ 
SERVICE <dbpedia.org/sparql>
{ 
{:Rotavirus_vaccine ?p ?o. BIND(:Rotavirus_vaccine AS ?s)} 
UNION {?s ?p :Rotavirus_vaccine. BIND(:Rotavirus_vaccine AS ?o) } 
} 
}