SWRL rules cause of slow response?

Hi there,

I am experiencing unbearably slow response when I make an assertion, then issue a sparql query with reasoning turned on. I have uploaded about 60-70 SWRL rules into my ontology and am wondering if

  • using rules; or
  • the number of rules; or
  • the way I have partitioned the rules into named graphs (should I house all the rules together for better performance?)

are the main cause of the slowdown. Any advice/suggestion would be much appreciated. Thanks in advance!


According to my experience, rules (not only SWRL) are a pain for any reasoner, even outside Stardog.
Unfortunately, they are also a fundamental way to formalize knowledge in an ontology.
In some cases, I also experienced a crash of the Pellet reasoner in Stardog.
Using stardog rules syntax would bring no apparent benefit.

So far, the only viable workaround I found is to translate the SWRL rule into a SPARQL construct query. For instance, if your SWRL RULE is like:
{condition1} ^ {condition2} ^ {condition3} -> {statement1} ^ {statement2}

the equivalent SPARQL construct would be




Then I elaborate the construct queries on Jena running on a java app in an iterative fashion, until no new statements are produced.

This brings the drawbacks of having an external, custom made app and a support graph where to store the inferred statements in the form of additionally asserted statements.
Processing times are still high but in any case slower than any other attempt with (SWRL) rules on stardog built-in reasoner.
And, as mentioned, the only viable solution I found as number and complexity of rules and model increases.

Hope this may have helped you in some way.

Thanks Lorenzo, for the time and effort to share. Much appreciated!

It is assuring to know that rule use is in itself problematic cos for a while now I have been grasping in the dark, wondering if I had somehow did a bad job defining the ontology.... although that could well be a culprit too, in my case. But I've also read about folks who had huge ontologies and rules (mainly in stackoverflow), reporting good/decent response times, which did not help me wondering what I did that had gone so wrong.

Once again, thanks,

rule use is in itself problematic

For the record, that's not remotely accurate. Most often, if you are using the Inference Engine with axioms and/or rules and experiencing slow queries, your ontology is the issue. OWL reasoning can get very computationally expensive very quickly if you're not careful. It can be used at scale without problems, but it does require up front design work, like any other engineering task.

rule use is in itself problematic

For the record, that's not remotely accurate.

Just my 2 cents: I often use SWRL. There are times when I will re-write my SWRL rules in SPARQL because for some problems with very large amounts of data SWRL can be slow and as a result some reasoners don't even support it. Which may seem like a waste of time (rewriting from SWRL to SPARQL) but in my experience, especially for complex rules, the hard part isn't writing the code it is making sure you really understand the rules. So I've often found it can be useful to work in SWRL when I'm doing my initial design and prototyping; then if needed to re-write in SPARQL. I was going to write some SPARQL code to automatically transform SWRL to SPARQL (since SWRL rules are still RDF graphs) but someone beat me to it. I don't know how robust his implementation is but in case anyone is interested here's a link to one of his papers: https://www.academia.edu/73613018/SWRL2SPIN_A_tool_for_transforming_SWRL_rule_bases_in_OWL_ontologies_to_object_oriented_SPIN_rules

But in general I agree with Michael Grove, to say that using rules is just "problematic" without any context is too simplistic. So much depends on the specific reasoner, how much data you have and the axioms in your ontology that can make the reasoner very slow and have nothing to do with SWRL.


fwiw, the Stardog Rules are just SWRL under the hood; same semantics, better syntax. And all rules are translated into queries, so SPARQL becomes a pretty handy tool in the rule development process, particularly if you need to debug something.

Hello all,

I know the rule comment does come across as a sweeping statement but for someone building an ontology+rules for the first time, I really dont have a good grasp of both. The first suspect was the rules (number of rules perhaps) but there was never any doubt that my ontology was likely sub-optimal too. That said, I do have to choose which area to tackle first and in this case, I chose rules.

Thanks all for your inputs.