Discussion:
How to call CREATE / DELETE GRAPH in Fuseki
Arthur Keen
2014-07-31 21:47:11 UTC
Permalink
For executing CREATE or DELETE GRAPH in Fuseki
I tried to use them the same way as SPARQL INSERT/DELETE by posting to ../ds/update, but this did not work

Which Endpoint URL pattern I should use:
http://localhost:8080/ds/update,
http://localhost:8080/ds/graph

For Creating a graph do you use an http put or post request?
For deleting a graph do you use an http delete request

And the name of the variable to bind the query to. Using query, update, etc as variable names, see commented out lines of code below
Thanks very much,

Any guidance would be much appreciated

Arthur


For context, here is the node.js code that I am using to call fuseki, with commented out variations of httpreq that I have tried

//http://localhost:3000/graph/create?graphName=http://testGraph
app.get('/api/graph/create', function(req, res){
var update = "CREATE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:"+"graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function (geterr, getres){
//httpreq.post(endpoint.getGraphURL(), {parameters: {update: update}}, function (geterr, getres){
httpreq.put(endpoint.getGraphURL(), {parameters: {query: update}}, function (geterr, getres){
if (geterr) return console.log(geterr);
res.send(endpoint.getGraphURL()+" "+ update+" "+ graphName);
});
});

//http://localhost:3000/graph/delete?graphName=http://testGraph

app.get('/graph/delete', function(req, res) {
var update = "DELETE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:" + "graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function(geterr, getres) {
httpreq.delete(endpoint.getGraphURL(), {parameters: {graph: update}}, function(geterr, getres) {
if (geterr)
return console.log(geterr);
console.log(update);
res.send(endpoint.getGraphURL());
});
});
Andy Seaborne
2014-08-01 10:44:46 UTC
Permalink
It's DROP not DELETE in SPARQL Update.

DELETE is for triples, DROP is for whole graphs.

http://www.w3.org/TR/sparql11-update/#graphManagement
Post by Arthur Keen
For executing CREATE or DELETE GRAPH in Fuseki
I tried to use them the same way as SPARQL INSERT/DELETE by posting to ../ds/update, but this did not work
http://localhost:8080/ds/update,
http://localhost:8080/ds/graph
There are two things here:

1/ SPARQL Update -- CREATE and DROP -- use the "update" endpoint

2/ SPARQL Graph Store Protocol -- this is not SPARQL Update -- use a
writeable GSP endpoint.

GSP is normal HTTP usage on web resource GET/PUT/POST/DELETE/HEAD

http://www.w3.org/TR/sparql11-http-rdf-update/

what that document does is really explain how the REST(ish) use of HTTP
applies to graph store. It isn't defining anything new except the
naming scheme for graphs.

In GSP, the app (HTTP) PUT RDF syntax (Turtle, N-triples, JSON-LD) to
create or replace the contents of a graph and POST to create or add to a
graph.

HTTP DELETE deletes a web resource as normal.
Post by Arthur Keen
For Creating a graph do you use an http put or post request?
For deleting a graph do you use an http delete request
And the name of the variable to bind the query to. Using query, update, etc as variable names, see commented out lines of code below
Thanks very much,
They don't take variables.

Just do e.g.

INSERT DATA { GRAPH :g { :s :p :o } }

and a graph is created for :g

INSERT
{ GRAPH ?g { :s :p :o } }
WHERE
{ ... ?g ... }

Whether CREATE is necessary in other situations depends on the storage
implementation. In Fuseki, with all the Jena provided storage
alternative, it is not needed.

It's possible other storage layers need graphs creating beforehand. I
don't know of any. In a quad store, it's fairly irrelevant distinction.
Post by Arthur Keen
Any guidance would be much appreciated
Arthur
Hope that makes it clearer,
Andy
Post by Arthur Keen
For context, here is the node.js code that I am using to call fuseki, with commented out variations of httpreq that I have tried
//http://localhost:3000/graph/create?graphName=http://testGraph
app.get('/api/graph/create', function(req, res){
var update = "CREATE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:"+"graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function (geterr, getres){
//httpreq.post(endpoint.getGraphURL(), {parameters: {update: update}}, function (geterr, getres){
httpreq.put(endpoint.getGraphURL(), {parameters: {query: update}}, function (geterr, getres){
if (geterr) return console.log(geterr);
res.send(endpoint.getGraphURL()+" "+ update+" "+ graphName);
});
});
//http://localhost:3000/graph/delete?graphName=http://testGraph
If you are using the default naming /delete and /create don't exist as
services.
Post by Arthur Keen
app.get('/graph/delete', function(req, res) {
var update = "DELETE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:" + "graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function(geterr, getres) {
httpreq.delete(endpoint.getGraphURL(), {parameters: {graph: update}}, function(geterr, getres) {
if (geterr)
return console.log(geterr);
console.log(update);
res.send(endpoint.getGraphURL());
});
});
If you want security, you can either front Fuseki with httpd/nginx
(that's advisable anyway for any java web container), or wait for Fuseki2.

Andy
Arthur Keen
2014-08-01 20:49:27 UTC
Permalink
This post might be inappropriate. Click to display it.
Arthur Keen
2014-08-02 18:47:32 UTC
Permalink
Pilot error: The issue was caused by my using
SELECT DISTINCT ?g WHERE{GRAPH ?g {?s ?p ?o}}

Which finds non empty named graphs (containing one or more statements). I should have been using:

SELECT DISTINCT ?g WHERE {GRAPH ?g{}}

Which finds empty graphs
Post by Arthur Keen
Andy,
Thanks for clearing that up. One cannot underestimate Occam's Razor. I switched my code back to update and replaced DELETE with DROP and that is working, and INSERT also works to create graphs, but using CREATE on update is not creating graphs.
When I tried the same queries from the Fuseki control panel and observed the same behavior, ie., the CREATE query
In SPARQL Update Panel
CREATE SILENT GRAPH <http://testGraph10.com/graph10>
In SPARQL Query Panel
SELECT DISTINCT ?g WHERE{GRAPH ?g {?s ?p ?o}}
---------------------------
| g |
===========================
| <http://testGraph1> |
| <http://booger.com/boo> |
| <http://queries> |
---------------------------
Am I missing something in the CREATE?
Arthur
Post by Andy Seaborne
It's DROP not DELETE in SPARQL Update.
DELETE is for triples, DROP is for whole graphs.
http://www.w3.org/TR/sparql11-update/#graphManagement
Post by Arthur Keen
For executing CREATE or DELETE GRAPH in Fuseki
I tried to use them the same way as SPARQL INSERT/DELETE by posting to ../ds/update, but this did not work
http://localhost:8080/ds/update,
http://localhost:8080/ds/graph
1/ SPARQL Update -- CREATE and DROP -- use the "update" endpoint
2/ SPARQL Graph Store Protocol -- this is not SPARQL Update -- use a writeable GSP endpoint.
GSP is normal HTTP usage on web resource GET/PUT/POST/DELETE/HEAD
http://www.w3.org/TR/sparql11-http-rdf-update/
what that document does is really explain how the REST(ish) use of HTTP applies to graph store. It isn't defining anything new except the naming scheme for graphs.
In GSP, the app (HTTP) PUT RDF syntax (Turtle, N-triples, JSON-LD) to create or replace the contents of a graph and POST to create or add to a graph.
HTTP DELETE deletes a web resource as normal.
Post by Arthur Keen
For Creating a graph do you use an http put or post request?
For deleting a graph do you use an http delete request
And the name of the variable to bind the query to. Using query, update, etc as variable names, see commented out lines of code below
Thanks very much,
They don't take variables.
Just do e.g.
INSERT DATA { GRAPH :g { :s :p :o } }
and a graph is created for :g
INSERT
{ GRAPH ?g { :s :p :o } }
WHERE
{ ... ?g ... }
Whether CREATE is necessary in other situations depends on the storage
implementation. In Fuseki, with all the Jena provided storage
alternative, it is not needed.
It's possible other storage layers need graphs creating beforehand. I
don't know of any. In a quad store, it's fairly irrelevant distinction.
Post by Arthur Keen
Any guidance would be much appreciated
Arthur
Hope that makes it clearer,
Andy
Post by Arthur Keen
For context, here is the node.js code that I am using to call fuseki, with commented out variations of httpreq that I have tried
//http://localhost:3000/graph/create?graphName=http://testGraph
app.get('/api/graph/create', function(req, res){
var update = "CREATE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:"+"graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function (geterr, getres){
//httpreq.post(endpoint.getGraphURL(), {parameters: {update: update}}, function (geterr, getres){
httpreq.put(endpoint.getGraphURL(), {parameters: {query: update}}, function (geterr, getres){
if (geterr) return console.log(geterr);
res.send(endpoint.getGraphURL()+" "+ update+" "+ graphName);
});
});
//http://localhost:3000/graph/delete?graphName=http://testGraph
If you are using the default naming /delete and /create don't exist as services.
Post by Arthur Keen
app.get('/graph/delete', function(req, res) {
var update = "DELETE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:" + "graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function(geterr, getres) {
httpreq.delete(endpoint.getGraphURL(), {parameters: {graph: update}}, function(geterr, getres) {
if (geterr)
return console.log(geterr);
console.log(update);
res.send(endpoint.getGraphURL());
});
});
If you want security, you can either front Fuseki with httpd/nginx (that's advisable anyway for any java web container), or wait for Fuseki2.
Andy
Andy Seaborne
2014-08-03 09:17:24 UTC
Permalink
Post by Arthur Keen
Pilot error: The issue was caused by my using
SELECT DISTINCT ?g WHERE{GRAPH ?g {?s ?p ?o}}
SELECT DISTINCT ?g WHERE {GRAPH ?g{}}
(DISTINCT not needed)
Post by Arthur Keen
Which finds empty graphs
Sort of :-)

The default in-memory dataset knows about empty graphs because it's a
map of (URI->Graph). TDB does not because it is a set of triples and a
set of quads with no separate graph management.

So in TDB the names of all graphs is calculated by looking in the graph
field of the quads with the effect that no quad (no triple in graph)
means no name. It is like (but more efficient) than the first way with
{?s ?p ?o}.

Andy
Post by Arthur Keen
Post by Arthur Keen
Andy,
Thanks for clearing that up. One cannot underestimate Occam's Razor. I switched my code back to update and replaced DELETE with DROP and that is working, and INSERT also works to create graphs, but using CREATE on update is not creating graphs.
When I tried the same queries from the Fuseki control panel and observed the same behavior, ie., the CREATE query
In SPARQL Update Panel
CREATE SILENT GRAPH <http://testGraph10.com/graph10>
In SPARQL Query Panel
SELECT DISTINCT ?g WHERE{GRAPH ?g {?s ?p ?o}}
---------------------------
| g |
===========================
| <http://testGraph1> |
| <http://booger.com/boo> |
| <http://queries> |
---------------------------
Am I missing something in the CREATE?
Arthur
Post by Andy Seaborne
It's DROP not DELETE in SPARQL Update.
DELETE is for triples, DROP is for whole graphs.
http://www.w3.org/TR/sparql11-update/#graphManagement
Post by Arthur Keen
For executing CREATE or DELETE GRAPH in Fuseki
I tried to use them the same way as SPARQL INSERT/DELETE by posting to ../ds/update, but this did not work
http://localhost:8080/ds/update,
http://localhost:8080/ds/graph
1/ SPARQL Update -- CREATE and DROP -- use the "update" endpoint
2/ SPARQL Graph Store Protocol -- this is not SPARQL Update -- use a writeable GSP endpoint.
GSP is normal HTTP usage on web resource GET/PUT/POST/DELETE/HEAD
http://www.w3.org/TR/sparql11-http-rdf-update/
what that document does is really explain how the REST(ish) use of HTTP applies to graph store. It isn't defining anything new except the naming scheme for graphs.
In GSP, the app (HTTP) PUT RDF syntax (Turtle, N-triples, JSON-LD) to create or replace the contents of a graph and POST to create or add to a graph.
HTTP DELETE deletes a web resource as normal.
Post by Arthur Keen
For Creating a graph do you use an http put or post request?
For deleting a graph do you use an http delete request
And the name of the variable to bind the query to. Using query, update, etc as variable names, see commented out lines of code below
Thanks very much,
They don't take variables.
Just do e.g.
INSERT DATA { GRAPH :g { :s :p :o } }
and a graph is created for :g
INSERT
{ GRAPH ?g { :s :p :o } }
WHERE
{ ... ?g ... }
Whether CREATE is necessary in other situations depends on the storage
implementation. In Fuseki, with all the Jena provided storage
alternative, it is not needed.
It's possible other storage layers need graphs creating beforehand. I
don't know of any. In a quad store, it's fairly irrelevant distinction.
Post by Arthur Keen
Any guidance would be much appreciated
Arthur
Hope that makes it clearer,
Andy
Post by Arthur Keen
For context, here is the node.js code that I am using to call fuseki, with commented out variations of httpreq that I have tried
//http://localhost:3000/graph/create?graphName=http://testGraph
app.get('/api/graph/create', function(req, res){
var update = "CREATE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:"+"graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function (geterr, getres){
//httpreq.post(endpoint.getGraphURL(), {parameters: {update: update}}, function (geterr, getres){
httpreq.put(endpoint.getGraphURL(), {parameters: {query: update}}, function (geterr, getres){
if (geterr) return console.log(geterr);
res.send(endpoint.getGraphURL()+" "+ update+" "+ graphName);
});
});
//http://localhost:3000/graph/delete?graphName=http://testGraph
If you are using the default naming /delete and /create don't exist as services.
Post by Arthur Keen
app.get('/graph/delete', function(req, res) {
var update = "DELETE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:" + "graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function(geterr, getres) {
httpreq.delete(endpoint.getGraphURL(), {parameters: {graph: update}}, function(geterr, getres) {
if (geterr)
return console.log(geterr);
console.log(update);
res.send(endpoint.getGraphURL());
});
});
If you want security, you can either front Fuseki with httpd/nginx (that's advisable anyway for any java web container), or wait for Fuseki2.
Andy
Arthur Keen
2014-08-03 18:07:11 UTC
Permalink
Post by Andy Seaborne
Post by Arthur Keen
Pilot error: The issue was caused by my using
SELECT DISTINCT ?g WHERE{GRAPH ?g {?s ?p ?o}}
SELECT DISTINCT ?g WHERE {GRAPH ?g{}}
(DISTINCT not needed)
Post by Arthur Keen
Which finds empty graphs
Sort of :-)
The default in-memory dataset knows about empty graphs because it's a map of (URI->Graph). TDB does not because it is a set of triples and a set of quads with no separate graph management.
So in TDB the names of all graphs is calculated by looking in the graph field of the quads with the effect that no quad (no triple in graph) means no name. It is like (but more efficient) than the first way with {?s ?p ?o}.
Andy
Thanks, that explains your earlier comment about CREATE being irrelevant for quad stores - no quads; no named graph. In this particular case, the query result is dependent on the physical implementation...

Arthur
Post by Andy Seaborne
Post by Arthur Keen
Post by Arthur Keen
Andy,
Thanks for clearing that up. One cannot underestimate Occam's Razor. I switched my code back to update and replaced DELETE with DROP and that is working, and INSERT also works to create graphs, but using CREATE on update is not creating graphs.
When I tried the same queries from the Fuseki control panel and observed the same behavior, ie., the CREATE query
In SPARQL Update Panel
CREATE SILENT GRAPH <http://testGraph10.com/graph10>
In SPARQL Query Panel
SELECT DISTINCT ?g WHERE{GRAPH ?g {?s ?p ?o}}
---------------------------
| g |
===========================
| <http://testGraph1> |
| <http://booger.com/boo> |
| <http://queries> |
---------------------------
Am I missing something in the CREATE?
Arthur
Post by Andy Seaborne
It's DROP not DELETE in SPARQL Update.
DELETE is for triples, DROP is for whole graphs.
http://www.w3.org/TR/sparql11-update/#graphManagement
Post by Arthur Keen
For executing CREATE or DELETE GRAPH in Fuseki
I tried to use them the same way as SPARQL INSERT/DELETE by posting to ../ds/update, but this did not work
http://localhost:8080/ds/update,
http://localhost:8080/ds/graph
1/ SPARQL Update -- CREATE and DROP -- use the "update" endpoint
2/ SPARQL Graph Store Protocol -- this is not SPARQL Update -- use a writeable GSP endpoint.
GSP is normal HTTP usage on web resource GET/PUT/POST/DELETE/HEAD
http://www.w3.org/TR/sparql11-http-rdf-update/
what that document does is really explain how the REST(ish) use of HTTP applies to graph store. It isn't defining anything new except the naming scheme for graphs.
In GSP, the app (HTTP) PUT RDF syntax (Turtle, N-triples, JSON-LD) to create or replace the contents of a graph and POST to create or add to a graph.
HTTP DELETE deletes a web resource as normal.
Post by Arthur Keen
For Creating a graph do you use an http put or post request?
For deleting a graph do you use an http delete request
And the name of the variable to bind the query to. Using query, update, etc as variable names, see commented out lines of code below
Thanks very much,
They don't take variables.
Just do e.g.
INSERT DATA { GRAPH :g { :s :p :o } }
and a graph is created for :g
INSERT
{ GRAPH ?g { :s :p :o } }
WHERE
{ ... ?g ... }
Whether CREATE is necessary in other situations depends on the storage
implementation. In Fuseki, with all the Jena provided storage
alternative, it is not needed.
It's possible other storage layers need graphs creating beforehand. I
don't know of any. In a quad store, it's fairly irrelevant distinction.
Post by Arthur Keen
Any guidance would be much appreciated
Arthur
Hope that makes it clearer,
Andy
Post by Arthur Keen
For context, here is the node.js code that I am using to call fuseki, with commented out variations of httpreq that I have tried
//http://localhost:3000/graph/create?graphName=http://testGraph
app.get('/api/graph/create', function(req, res){
var update = "CREATE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:"+"graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function (geterr, getres){
//httpreq.post(endpoint.getGraphURL(), {parameters: {update: update}}, function (geterr, getres){
httpreq.put(endpoint.getGraphURL(), {parameters: {query: update}}, function (geterr, getres){
if (geterr) return console.log(geterr);
res.send(endpoint.getGraphURL()+" "+ update+" "+ graphName);
});
});
//http://localhost:3000/graph/delete?graphName=http://testGraph
If you are using the default naming /delete and /create don't exist as services.
Post by Arthur Keen
app.get('/graph/delete', function(req, res) {
var update = "DELETE SILENT GRAPH <?:graphName>";
var graphName = req.param("graphName");
update = update.replaceAll("?:" + "graphName", graphName);
//httpreq.post(endpoint.getUpdateURL(), {parameters: {update: update}}, function(geterr, getres) {
httpreq.delete(endpoint.getGraphURL(), {parameters: {graph: update}}, function(geterr, getres) {
if (geterr)
return console.log(geterr);
console.log(update);
res.send(endpoint.getGraphURL());
});
});
If you want security, you can either front Fuseki with httpd/nginx (that's advisable anyway for any java web container), or wait for Fuseki2.
Andy
Loading...