Sesame repository not being updated using INSERT despite no error

你说的曾经没有我的故事 提交于 2019-12-11 13:43:34

问题


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


来源:https://stackoverflow.com/questions/31234300/sesame-repository-not-being-updated-using-insert-despite-no-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!