码迷,mamicode.com
首页 > 其他好文 > 详细

No need to add "optional" in your insert section of your sparql code

时间:2014-12-08 17:36:20      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   on   div   

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

标签:style   blog   http   io   ar   color   sp   on   div   

原文地址:http://www.cnblogs.com/RuiYan/p/4151181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!