I am trying to rename a ontotext graphdb repository programmatically (via a SPARQL query or rest endpoint).
I can use the following SPARQL documented here to delete old repository and insert new repository however this deletes all data from old repository
PREFIX sys:<http://www.openrdf.org/config/repository#>
DELETE { GRAPH ?g { ?repository sys:repositoryID ?old_name } }
INSERT { GRAPH ?g { ?repository sys:repositoryID ?new_name } }
WHERE {
GRAPH ?g { ?repository a sys:Repository . }
GRAPH ?g { ?repository sys:repositoryID ?old_name . }
FILTER( ?old_name = "old_repository_name" ) .
BIND( "new_repository_name" AS ?new_name ) .
}
I can manually copy over the index files to this new repository location, however Is there an inbuilt graphdb feature to do this.
The link you share is for the 6.6 documentation, which is a very old version of GraphDB. In the newer versions of GraphDB you can rename the repository from the Workbench Edit repository form.
http://graphdb.ontotext.com/documentation/free/configuring-a-repository.html?highlight=rename#configuring-a-repository-reconfigure-a-repository-using-the-workbench
Note that this also re-initializes the repository.
Related
I am trying to delete a known URI from our triplestore. It can be a subject or an object, by its predicates. So what I like to do is the following:
DELETE {
GRAPH <graph> {
<uri> ?p1 ?o1 .
?s2 ?p2 <uri> .
}
}
By executing the following query, all occurences of the known should be removed in the known . However I cannot use variables in a delete function. How can I make the above code working?
DELETE needs a template 9what to delete) and a pattern (binds variables).
There is the DELETE WHERE operation. https://www.w3.org/TR/sparql11-update/#deleteWhere
DELETE WHERE { .... is a short form of DELETE {...} WHERE {...} with the same {...} for template and pattern.
Good day, I am using Graphdb to store some triples as seen in the image below. This particular RDF node uses a regular URI http://example/regular/uri. What I wish to do is to not only completely delete all properties attached to this node, but also delete the node itself. (with the result that http://example/regular/uri does not appear in the graph database any longer)
So far I am only able to delete all properties, but I am not able to delete the actual RDF node itself. It seemed rather simple, but the more I research online, the more this seems impossible unless clearing the complete graph.
I have tried simple "delete where" queries as shown in example 11 of SPARQL documentation. And i have also tried using simple "delete where"-queries using the wildcard operator as shown in the query below:
Is there a way to delete such RDF nodes?
Thanks in advance!
A node exists in a graph as long as there is one or more triples with that node in subject or object position. So the easiest way would be to issue two delete statements, one deleting all statements with the node in subject position and one deleting all statements with the node in object position. But if you need/want to do it with a single operation you can do that as well with filters.
Here is a sample that delete uri://node/to/delete from uri://my/graph :
DELETE { GRAPH <uri://my/graph> {
?s ?p ?o .
}}
USING <uri://my/graph>
WHERE {
{
?s ?p ?o . VALUES ?s { <uri://node/to/delete>}
} UNION {
?s ?p ?o . VALUES ?o { <uri://node/to/delete>}
}
}
We have graphs containing oa:Annotations with certain properties. Since I am working on a local copy of the server, it would be useful to me to change these URIs to point to localhost. According to the book I read, I thought this should work, but it does not. It does not seem to change anything. Still, the server returns a 204, I am using the priting port and url (/update). So I definitely should be able to change things. There is no error message.
PREFIX oa: <http://www.w3.org/ns/oa#>
DELETE
{ GRAPH ?g {?oldIRI ?p ?o} }
INSERT
{ GRAPH ?g {?newIRI ?p ?o} }
WHERE
{
GRAPH ?g {
?oldIRI a oa:Annotation .
?oldIRI ?p ?o .
}
BIND(
CONCAT("http://localhost:80",
SUBSTR( STR(?oldIRI),
34,
STRLEN(STR(?oldIRI)) )
) AS ?newIRI
)
FILTER(CONTAINS(?oldIRI, "part_of_old_url"))
}
Any idea why this does not have the effect I hoped for? The book I use as reference does have "recipies" to change properties and it's values, but there is no example changing the subjects, so I assume there is a more general problem?
Update: using STR()
As suggested in the comments, I used CONTAINS(STR(?oldIRI), "part_of_old_url") to convert oldIRI to a string. I am not fully aware of all changes, but this is what I can say: (I have backups, no worry :D)
PREFIX oa: <http://www.w3.org/ns/oa#>
SELECT *
WHERE {
GRAPH ?g {
?iri a oa:Annotation .
}
} LIMIT 100
This query has zero results. It's a default query I often used to get some annotation uris for looking into things.
I've just started using the triple store RDF4J (I am using its workbench, version 2.3.1, run on Windows 10 with Tomcat 9.0)
I want to use the SPIN rules in RDF4J. Therefore, I created a new repository (In memory with RDFS+SPIN support).
I wanted to start with the SPIN example in RDF4J documentation concerning how to add SPIN rules. That is, I added the data (in Turtle, and imported to RDF4J)
#prefix ex: <http://example.org/>.
ex:John a ex:Father ;
ex:parentOf ex:Lucy .
ex:Lucy a ex:Person .
And the rule:
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix sp: <http://spinrdf.org/sp#>.
#prefix spin: <http://spinrdf.org/spin#>.
#prefix ex: <http://example.org/>.
ex:Person a rdfs:Class ;
spin:rule [
a sp:Construct ;
sp:text """PREFIX ex: <http://example.org/>
CONSTRUCT { ?this ex:childOf ?parent . }
WHERE { ?parent ex:parentOf ?this . }"""
] .
And as instructed in the documentation, I exposed the query (with the checkbox 'Include inferred statements' checked),
PREFIX ex: <http://example.org/>
SELECT ?child
WHERE { ?child ex:childOf ?parent }
However, no result returned:
Could someone, please tell me am I doing something wrong, why the SPIN rule doesn't work in my RDF4J workbench, have I missed something?
(reposting my comment as an answer for future readers)
The SPIN reasoner currently assumes that all data is in the default context, I think. Make sure that your data was not added to a named graph.
It looks like this question has been raised before, but subsequently deleted?!
For data in one SQL table, I can easily replicate the structure and then migrate the data to another table (or database?).
CREATE TABLE new_table
AS (SELECT * FROM old_table);
SELECT *
INTO new_table [IN externaldb]
FROM old_table
WHERE condition;
Is there something analogous for RDF/SPARQL? Something that combines a select and an insert into one SPARQL statement?
Specifically, I use Karma, which publishes data to an embedded OpenRDF/Sesame endpoint. There's a text box on the GUI for the endpoint, so I can change it to a free-standing RDF4J, since RDF4J is a fork of Sesame.
Unfortunately, I get an error like invalid SPARQL endpoint from Karma when I put the address for a Virtuoso, Stardog or Blazegraph endpoint in the endpoint text box. I suspect it might be possible to modify and recompile Karma, or (more realistically), I could write a small tool with the Jena or RDF4J libraries to select into RAM or scratch disk space and then insert into the other endpoint.
But if there's a pure-SPARQL solution, I'd sure like to hear it.
In SPARQL, you can only specify the source endpoint. Therefore, a partial pure-SPARQL solution would be to run the following update on your target triplestore:
INSERT { ?s ?p ?o }
WHERE { SERVICE <http://source/sparql>
{
?s ?p ?o
}
}
This will copy over all triples from the (remote) source's default graph to your target store, but it doesn't copy over any named graphs. To copy over any named graphs as well, you can execute this in addition:
INSERT { GRAPH ?g { ?s ?p ?o } }
WHERE { SERVICE <http://source/sparql>
{
GRAPH ?g {
?s ?p ?o
}
}
}
If you're not hung up on pure SPARQL though, different toolkits and frameworks offer you all sorts of options. For example, using RDF4J's Repository API you could just wrap both source and target in a SPARQLRepository proxy (or just use a HTTPRepository if either one is an actual RDF4J store), and then just run copy API operations. There's many different ways to do that, one possible approach (disclaimer: I didn't test this code fragment) is this:
SPARQLRepository source = new SPARQLRepository("http://source/sparql");
source.initialize();
SPARQLRepository target = new SPARQLRepository("http://target/sparql");
target.initialize();
try (RepositoryConnection sourceConn = source.getConnection();
RepositoryConnection targetConn = target.getConnection()) {
sourceConn.export(new RDFInserter(targetConn));
}