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:

时间: 2025-01-04 00:43:04

No need to add "optional" in your insert section of your sparql code的相关文章

用Optional代替null源码

/* * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package java.util; import java.util.function.Consumer; im

java1.8新特性(optional 使用)

经常在程序中出现 java.lang.NullPointerException  为了避免  报错,总是要进行一些 是否为null 的if else 判断 ,1.8 可以使用optional 类 来简化处置   optional :A container object which may or may not contain a non-null value.:可能包含也可能不包含非空值的容器对象. 既然optional 是一个容器对象,那就应该先创建该 对象 才能调用该对象的一些方法 创建op

深入理解 lambda表达式 与 Optional Null 源码解析(Java11 三)

import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.*; import java.util.function.Function; import java.util

CRUD Operations In ASP.NET MVC 5 Using ADO.NET

Background After awesome response of an published by me in the year 2013: Insert, Update, Delete In GridView Using ASP.Net C#. It now has more than 140 K views, therefore to help beginners I decided to rewrite the article i with stepbystep approach u

NHibernate官方文档中文版--基础ORM(Basic O/R Mapping)

映射声明 对象/关系映射在XML文件中配置.mapping文件这样设计是为了使它可读性强并且可修改.mapping语言是以对象为中心,意味着mapping是围绕着持久化类声明来建立的,而不是围绕数据表. 要注意的是,尽管很多NHibernate使用者选择手动定义XML文件,但是仍然有很多工具可以用来生成mapping文件,包括NHibernate.Mapping.Attributes 库和各种各样基于模板的代码生成工具(CodeSmith, MyGeneration). 让我们用一个mappin

YASM User Manual

This document is the user manual for the Yasm assembler. It is intended as both an introduction and a general-purpose reference for all Yasm users. 1.?Introduction Yasm is a BSD-licensed assembler that is designed from the ground up to allow for mult

Rewrite MSIL Code on the Fly with the .NET Framework Profiling API

.NET Internals Rewrite MSIL Code on the Fly with the .NET Framework Profiling API Aleksandr Mikunov This article assumes you're familiar with the CLR and C# Level of Difficulty 1 2 3 Code download available at: NETProfilingAPI.exe (2,901KB) SUMMARY I

smtp

Network Working Group J. Klensin, EditorRequest for Comments: 2821 AT&T LaboratoriesObsoletes: 821, 974, 1869 April 2001Updates: 1123Category: Standards Track Simple Mail Transfer Protocol Status of this Memo This document specifies an Internet stand

Flask系列:数据库

这个系列是学习<Flask Web开发:基于Python的Web应用开发实战>的部分笔记 对于用户提交的信息,包括 账号.文章 等,需要能够将这些数据保存下来 持久存储的三种方法: 文件:shelve(pickle 和 DBM 的结合)等,提供类似字典的对象接口 关系型数据库(SQL) 非关系型数据库(NoSQL) 其他 通常会使用数据库保存信息,并向数据库发起查询获取信息 SQL,关系型数据库 关系型数据库把数据存储在表中,表在程序中通过 Python 的类实现.例如,订单管理程序的数据库中