'org.openrdf.query.MalformedQueryException for SparQL insert
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.
Solution 1:[1]
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 GroupGraphPatternDeleteClause ::= 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.
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | Vanya Usalko |
