Understanding data add and data remove + updating of data

Hi guys,

So my Abox and rulesets changes from time to time, and hence I would like to remove old triples and add new triples when needed. The Abox and rulesets are in different .ttl files, but I sent the data to the database during creation with bulk loading.

How to do this properly?

Hi Arbaz,

There are several valid ways to accomplish this. If you have small amounts of data to delete or insert, you can write a SPARQL DELETE/INSERT query. If you just have the files, you can manually stardog data remove myDb oldFile.ttl and stardog data add myDb newFile.ttl on the CLI. If you have versioning enabled on your database you can perform the delete and insert through one stardog vcs call like so.

Thanks stephen :slight_smile:

How to know if versioning is enabled?

and what does the comment (“This is an example commit”) do?:

stardog vcs commit --add add_file1.ttl add_file2.ttl --remove remove_file.ttl -m “This is an example commit” myDb

Versioning is not enabled by default, so chances are high you don't have it. You can read the versioning example in our stardog-examples repository for an in-depth tutorial on how our versioning works and what it does.

Stephen one more question to data add and remove.

I have the following, which I sent to the database with : stardog data add myDB35 ccsontology.ttl

ifcowl:IfcWallStandardCase rdfs:subClassOf   [ a  owl:Restriction ;
                                               owl:onProperty  ccs:productID ;
                                               owl:onProperty  ccs:typeID ;
                                               owl:hasValue "AD" 
					                         ] .

I then deleted it with: stardog data remove myDB35 ccsontology.ttl

Then I made some modification as follows:

ifcowl:IfcWallStandardCase rdfs:subClassOf   [ a  owl:Restriction ;
                                               owl:onProperty  ccs:productID ;
                                               owl:onProperty  ccs:typeID ;
                                               owl:hasValue "%AD" 
					                         ] . 

So now instead of "AD" it is "%AD" . However after I added this, when I ran my query I got both results as in :

What am I doing wrong?

Try your query from the CLI or try forcing the browser to reload the page. Sometimes the webconsole is a little too aggressive with caching.

Arbaz,

The problem is that Bnodes are anonymous resources which are assigned IDs at parsing time. The assigned IDs are not consistent across invocations. Let me illustrate this with an example.

Inability to remove Bnodes

  • Create a simple file with a Bnode, load it into Stardog and verify the data is present:
$ cat x.ttl
<urn:a> <urn:b> [ <urn:c> <urn:d> ] .
$ stardog data add test x.ttl
Adding data from file: x.ttl
Added 2 triples in 00:00:00.050
$ stardog query execute test 'select * where { ?s ?p ?o }'
+------------------------------------------------+-------+------------------------------------------------+
|                       s                        |   p   |                       o                        |
+------------------------------------------------+-------+------------------------------------------------+
| urn:a                                          | urn:b | _:bnode_5e84acc9_885d_4f49_8ca1_32aad1fbef5e_1 |
| _:bnode_5e84acc9_885d_4f49_8ca1_32aad1fbef5e_1 | urn:c | urn:d                                          |
+------------------------------------------------+-------+------------------------------------------------+

Query returned 2 results in 00:00:00.053
  • Note the generated ID in the Bnode namespace: _:bnode_5e84acc9_885d_4f49_8ca1_32aad1fbef5e_1.
  • If we try to delete the data by passing the same file to Stardog, a new Bnode ID will be generated and the deletion will not match any triples:
$ stardog data remove test x.ttl
Removing data from file: x.ttl
Removed 0 triples in 00:00:00.039

Removing triples deterministically

  • Now consider this example which does the same thing use an IRI:
$ cat x2.ttl
<urn:a> <urn:b> <urn:realIRI>
<urn:realIRI> <urn:c> <urn:d> .
$ stardog data add test x2.ttl
Adding data from file: x2.ttl
Added 2 triples in 00:00:00.070
$ stardog query execute test 'select * where { ?s ?p ?o }'
+-------------+-------+-------------+
|      s      |   p   |      o      |
+-------------+-------+-------------+
| urn:a       | urn:b | urn:realIRI |
| urn:realIRI | urn:c | urn:d       |
+-------------+-------+-------------+

Query returned 2 results in 00:00:00.036
$ stardog data remove test x2.ttl
Removing data from file: x2.ttl
Removed 2 triples in 00:00:00.035

In this example, we loaded the same structure but instead of using a Bnode, we used an IRI. The deletion worked because the urn:realIRI matched the object/subject of the associated triples.

Hope this helps.

Jess, but if you see my scenario (further up) I don’t have blank nodes. How would I apply your suggested concept?

You said you added and deleted a file with these contents:

ifcowl:IfcWallStandardCase rdfs:subClassOf   [ a  owl:Restriction ;
                                               owl:onProperty  ccs:productID ;
                                               owl:onProperty  ccs:typeID ;
                                               owl:hasValue "AD" 
					                         ] .

The [] is the blank node and everything inside of it is triples with the blank node as the subject. Please let me know if some aspect of my example was not clear.

Ah yes sorry of course. But how would I apply your concept?

ifcowl:IfcWallStandardCase rdfs:subClassOf   :SOMETHING.
:SOMETHING a  owl:Restriction ;
                        owl:onProperty  ccs:productID ;
                        owl:onProperty  ccs:typeID ;
                        owl:hasValue "AD" .
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.