SPARQL UPDATE with named graphs?
852770Apr 4 2011 — edited Apr 20 2011Is SPARQL UPDATE with Named graphs supported?
The SPARQL udpate Spec [1] says I can do the following to specify a named graph to update:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{ GRAPH <http://example/bookStore> { <http://example/book3> dc:title "Fundamentals of Compiler Design" } }
But the program below (a modification of program Test16.java at [2]) does not work.
--- begin program ---
package com.modusoperandi.orardf.datastore;
import oracle.spatial.rdf.client.jena.GraphOracleSem;
import oracle.spatial.rdf.client.jena.ModelOracleSem;
import oracle.spatial.rdf.client.jena.Oracle;
import oracle.spatial.rdf.client.jena.OracleUtils;
import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.update.UpdateAction;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
public class TestUpdateNamedGraph {
public static void main(String[] args) throws Exception {
String szJdbcURL = args[0];
String szUser = args[1];
String szPasswd = args[2];
String szModelName = args[3];
Oracle oracle = new Oracle(szJdbcURL, szUser, szPasswd);
ModelOracleSem model = ModelOracleSem.createOracleSemModel(oracle,
szModelName);
GraphOracleSem g = model.getGraph();
// without named graph
String insertString = " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
+ " INSERT DATA "
+ " { <http://example/book3> dc:title \"A new book\" ; "
+ " dc:creator \"A.N.Other\" . "
+ " } ";
System.out.println(insertString);
UpdateAction.parseExecute(insertString, model);
ExtendedIterator ei = GraphUtil.findAll(g);
while (ei.hasNext()) {
System.out.println("Triple " + ei.next().toString());
}
// with named graph (http://www.w3.org/TR/sparql11-update/#t411 indicates
// this should work)
insertString = " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
+ " INSERT DATA "
+ " { GRAPH <http://example/bookStore>"
+ " { <http://example/book3> dc:title \"A new book\" ; "
+ " dc:creator \"A.N.Other\" . "
+ " } "
+ " } ";
System.out.println(insertString);
UpdateAction.parseExecute(insertString, model);
ei = GraphUtil.findAll(g);
while (ei.hasNext()) {
System.out.println("Triple " + ei.next().toString());
}
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
--- end program ---
Here is the program output showing the error:
--- begin program output ---
PREFIX dc: <http://purl.org/dc/elements/1.1/> INSERT DATA { <http://example/book3> dc:title "A new book" ; dc:creator "A.N.Other" . }
Triple http://example/book3 @dc:title "A new book"
Triple http://example/book3 @dc:creator "A.N.Other"
PREFIX dc: <http://purl.org/dc/elements/1.1/> INSERT DATA { GRAPH <http://example/bookStore> { <http://example/book3> dc:title "A new book" ; dc:creator "A.N.Other" . } }
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "graph" "GRAPH "" at line 1, column 64.
Was expecting one of:
<IRIref> ...
<PNAME_NS> ...
<PNAME_LN> ...
<BLANK_NODE_LABEL> ...
<VAR1> ...
<VAR2> ...
"true" ...
"false" ...
<INTEGER> ...
<DECIMAL> ...
<DOUBLE> ...
<INTEGER_POSITIVE> ...
<DECIMAL_POSITIVE> ...
<DOUBLE_POSITIVE> ...
<INTEGER_NEGATIVE> ...
<DECIMAL_NEGATIVE> ...
<DOUBLE_NEGATIVE> ...
<STRING_LITERAL1> ...
<STRING_LITERAL2> ...
<STRING_LITERAL_LONG1> ...
<STRING_LITERAL_LONG2> ...
"(" ...
<NIL> ...
"}" ...
"[" ...
<ANON> ...
at com.hp.hpl.jena.sparql.lang.ParserARQUpdate._parse(ParserARQUpdate.java:59)
at com.hp.hpl.jena.sparql.lang.ParserARQUpdate.parse(ParserARQUpdate.java:30)
at com.hp.hpl.jena.update.UpdateFactory.create(UpdateFactory.java:34)
at com.hp.hpl.jena.update.UpdateAction.parseExecute(UpdateAction.java:175)
at com.hp.hpl.jena.update.UpdateAction.parseExecute(UpdateAction.java:143)
at com.hp.hpl.jena.update.UpdateAction.parseExecute(UpdateAction.java:105)
at com.modusoperandi.orardf.datastore.TestUpdateNamedGraph.main(TestUpdateNamedGraph.java:49)
--- end program output ---
References:
[1] http://www.w3.org/TR/sparql11-update/#t411
[2] http://download.oracle.com/docs/cd/E18283_01/appdev.112/e11828/sem_jena.htm
-Mark