首页 > 代码库 > No need to add "optional" in your insert section of your sparql code
No need to add "optional" in your insert section of your sparql code
I was trying to insert new data while the where clauses have an "optional" clause. I thought I also need to use optional in the insert clause, but it‘s not true:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>INSERT { GRAPH <http://example/addresses> { ?person foaf:name ?name . optional { ?person foaf:mbox ?email } # what I thought, which is wrong . Also you can pay attention to optional syntax : use {} and no punctuation at the end of the triple. } }WHERE { GRAPH <http://example/people> { ?person foaf:name ?name . OPTIONAL { ?person foaf:mbox ?email } } }
the rigth version is :
PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>INSERT { GRAPH <http://example/addresses> { ?person foaf:name ?name . ?person foaf:mbox ?email . # you don‘t need to add optional here } }WHERE { GRAPH <http://example/people> { ?person foaf:name ?name . OPTIONAL { ?person foaf:mbox ?email } } }
As it puts here: http://www.w3.org/TR/sparql11-update/ (and you search example 9 in the page )
This example copies triples of name and email from one named graph to another. Some individuals may not have an address, but the name is copied regardless:
No need to add "optional" in your insert section of your sparql code
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。