2

I've read ways on how to insert data using SPARQL. Some references use INSERT while other references use INSERT DATA. So, I'm confused on how will I do the query. My goal is to insert a data property which is the CourseName to a class "Course" in my ontology. Here is my query:

INSERT{
    <http://www.semanticweb.org/rocky/ontologies/2015/3/CurriculumOntology#Course> curr:CourseName "IT222".
            }

I've tried this query and an exception appears which says:

SparqlReasonerException: org.openrdf.query.MalformedQueryException: Encountered " "insert" "INSERT "" at line 9, column 1.
Was expecting one of:
    "base" ...
    "prefix" ...
    "select" ...
    "construct" ...
    "describe" ...
    "ask" ...

is the subject of the triple wrong? or what should i really need to put on the subject of the triple? and why does an exception appears? btw, I'm using Protege in modeling my ontology.

user205512
  • 8,798
  • 29
  • 28
Rocky
  • 429
  • 1
  • 9
  • 26
  • 1
    It looks like you're issuing a SPARQL *UPDATE* to something which is expecting a SPARQL *QUERY* instead. In SPARQL (and unlike SQL) you can't INSERT / DELETE etc where a query is expected. – user205512 Apr 10 '15 at 10:39

2 Answers2

3

I've read ways on how to insert data using SPARQL. Some references use INSERT while other references use INSERT DATA.

There's insert data for inserting literal data into a graph, and there's a more complicated delete/insert (which requires at least one delete or insert, but you don't have to do both), which will let you do insert { … } where { … }. These are defined in the standard which is freely available online; you don't have to resort to secondary sources. The standard defines insert data with syntax:

INSERT DATA QuadData

and delete/insert with syntax:

( WITH IRIref )?
( ( DeleteClause InsertClause? ) | InsertClause )
( USING ( NAMED )? IRIref )*
WHERE GroupGraphPattern

DeleteClause ::= DELETE QuadPattern
InsertClause ::= INSERT QuadPattern

So yours is a simple syntax error. You need INSERT DATA, not DELETE/INSERT. Thus:

INSERT DATA {
  <http://www.semanticweb.org/rocky/ontologies/2015/3/CurriculumOntology#Course> curr:CourseName "IT222".
}

You can check syntax with sparql.org's update validator.

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
0

Sorry for mine five cents. But perhaps it's a result of wrong "GET" or "POST" request to the SPARQL server.

Try to catch request to the server. In mine case I managed to the same issue after request string correction.

.../sparql?query=...

to

.../sparql?update=...

I believe that Protege has the option to send update data query correctly.

Vanya Usalko
  • 405
  • 7
  • 10