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

Source: Internet
Author: User

I was trying to insert new data while the WHERE clauses has an "optional" clause. I thought I also need to use optional of the INSERT clause, but it's not true:

PREFIX FOAF:<http//Xmlns.com/Foaf/0.1/>PREFIX RDF:<http//www.w3.org/1999/ Geneva/ A-Rdf-Syntax-ns#>INSERT{GRAPH<http//Example/Addresses>{? person Foaf:name? name. Optional {person Foaf:mbox? e-mail} # What I thought, which iswrong.    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/ Geneva/ A-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 the name and email from one named graph to another. Some individuals may not have a address, but the name is copied regardless:

No need to add ' optional ' in your insert section of your SPARQL code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.