Infer when updating, possible?

Hi everyone,

I am trying to find a way to update values with reasoning. Is it possible to infer every time when I update the graph?

I have got SWRL rules in my ontology. At the moment, I can only infer the result when I make a query (set the boolean flag as true).

Thanks :slight_smile:

You can run SPARQL Update queries (aka DELETE/INSERT … WHERE queries) with reasoning, if that helps.

Cheers,
Pavel

Thank you! I used SPARQL Update to update my graph but I do not know how to use it with reasoning. Is there any way to enable it in SPARQL or any other way?

Hi,

It does look like there are a couple of issues specifically with reasoning in UPDATE queries. While we look into that further, there is a potential workaround for the case when you need your inferred triples to be materialized:

A) Run a construct query stardog query -r "CONSTRUCT {?x ?y ?z} WHERE {?x ?y ?z}", where ?x ?y ?z is your SWRL rule inferred triple, output to a file
B) stardog data add that file to your database. This would explicitly get your inferred triples into the database as asserted. However, to update using this method you would want to run DELETE {?x ?y ?z} WHERE {?x ?y ?z} so you don’t leave behind any false positives.

Hi,

Many thanks for your help! Regarding B), did you mean that I should delete old inferred triples first then assert new ones every time when I update?

Thanks!

If you’re intending to recalculate the inferences and materialize them, yes you would want to delete the old inferred triples so they will stop showing up if they’re no longer inferred.

Thanks! I will give a go :slight_smile:

Hi,

I am wondering if I can use stardog data remove myDb file.rdf instead? Thanks!

Kind regards

If your inferred triples are defined in file.rdf (i.e., it's the file generated by your CONSTRUCT query when doing this workaround), then yes, that would work just fine.

I have tested two ways including deleting old inferred triples and not deleting. It does not seem that there is any difference as the new inferred one would over write the corresponding old one. I have also checked the database where I did not find any fault. So just wonder if have to delete old inferred triples rather than overwrite them?

Thanks!

It’s hard to answer that question with any certainty without knowing your data. I personally would always want to err on the side of deleting the old data, since there is nothing stopping you from having an entity where [?x :hasState "active"] [?x :hasState "Inactive"] are both in the database, with potentially no way to know which is most up-to-date.

Thanks! It seems there is no [?x :hasState "active"] [?x :hasState "Inactive"] both existing case in my db somehow. But I will bear that in my mind. Thanks for the advice!

New question:

It seems that the database gets significantly larger after running the programme for a while. I checked the folder and it seems that there are several .page files created. Is there any quick way to decrease the size of the database?

Kind regards

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