A Datalog Rewriting Algorithm for Warded Ontologies

Davide Benedetto, Marco Calautti, Hebatalla Hammad, Emanuel Sallinger, Adriano Vlad-StarrabbaIJCAI 2025 · DOI

TL;DR

This paper introduces "WardedRewrite," a novel algorithm for translating ontology-mediated queries (OMQs) over "warded ontologies" into Datalog queries. This translation makes it practical to use existing Datalog engines for complex reasoning tasks, achieving efficient query answering and demonstrating good performance in experiments.

What Problem Does This Paper Address?

Knowledge representation and artificial intelligence systems often use ontologies to enrich data with derived knowledge. Existential rules (TGDs) are a powerful formalism for encoding these ontologies. However, answering queries over general TGD-based ontologies is computationally intractable. To address this, researchers have identified specific fragments of TGDs that guarantee computability, with "warded ontologies" striking a good balance between expressiveness and complexity. While the theoretical foundations for warded ontologies are solid, practical algorithms for Ontology-Mediated Query (OMQ) answering over them have been lacking. Existing approaches are either theoretical or limited in scope. This paper aims to bridge this gap by providing a practical Datalog rewriting algorithm for OMQs over warded ontologies.

Methods

The core contribution is the WardedRewrite algorithm. This algorithm takes an OMQ (a query and a warded ontology) and produces an equivalent Datalog program. The algorithm operates by iteratively applying two main steps:

  • Decomposition: This step breaks down a complex query into smaller, independently processable subqueries. This is crucial for managing the complexity of warded ontologies and ensuring the finiteness of the resulting Datalog program. The algorithm uses an "optimal decomposition" strategy to factorize the query body.
  • Resolution: This step "unfolds" the decomposed queries by applying the rules of the warded ontology. This is achieved through a "chunk-based resolution" mechanism, which uses "most general chunk unifiers" (MGCUs) to describe how ontology rules can be applied to query atoms.

The algorithm iteratively processes queries, either decomposing them or resolving them with ontology rules, until no new queries can be generated. The output is a Datalog program that captures the same answers as the original OMQ.

Datasets

The paper does not introduce new datasets. Instead, it uses the IWARDED benchmark generator to create synthetic scenarios (database-OMQ pairs) for experimental evaluation. These scenarios are generated by varying parameters related to the ontology structure (number of left-right-join recursions, average recursion length) and the database size (number of facts per predicate). The authors also mention using structural scenarios from a previous work for validation.

Key Insights and Ideas

  • Bridging Theory and Practice: The paper successfully translates the theoretical concept of warded ontologies into a practical Datalog rewriting algorithm, making this powerful formalism accessible for real-world applications.
  • Decomposition is Key: The novel "decomposition" step is highlighted as the critical innovation that distinguishes WardedRewrite from algorithms for simpler ontology fragments, ensuring the generation of a finite Datalog query.
  • Datalog Engines Shine: The experimental results strongly suggest that existing, off-the-shelf Datalog engines are highly capable of evaluating the Datalog rewritings produced by WardedRewrite.
  • Rewriting Offers Efficiency Gains: For most tested engines, evaluating the rewritten Datalog query is significantly more efficient than directly answering the OMQ. This is attributed to avoiding the explicit construction of large intermediate "chase" instances, which are often required for direct OMQ answering and can lead to performance bottlenecks due to existential variables.
  • Wardedness as a Sweet Spot: The paper reinforces the idea that warded ontologies represent a valuable compromise between expressiveness and computational tractability for OMQ answering.

Key Results

  • WardedRewrite Algorithm: The paper presents a novel algorithm, WardedRewrite, which is proven to terminate and produce a Datalog rewriting for any OMQ over a warded ontology.
  • Rewriting Time: The rewriting process itself is shown to be efficient. For most scenarios, the rewriting time is on the order of minutes, even for demanding inputs. The runtime scales linearly with the number of left-right-join recursions but exponentially with the average recursion length.
  • Query Answering Efficiency: Experiments show that evaluating the Datalog rewriting using engines like DLV, DLV-E, and InteGraal is often significantly faster (up to 50% improvement) than directly answering the original OMQ.
  • Engine Performance: While most engines benefit from the rewriting, VLog shows less improvement, and Vadalog exhibits mixed results, sometimes performing better on the original OMQ due to its specialized chase handling.

Limitations and Future Work

  • Scalability with Recursion Length: The exponential increase in rewriting time with average recursion length suggests that very deep recursive structures in ontologies could still pose a challenge for the rewriting process.
  • Engine-Specific Performance: The performance of Datalog engines on the rewritten queries varies, with some showing more significant gains than others.
  • Future Work: The authors suggest parallelizing the WardedRewrite algorithm by exploiting the independent nature of intermediate queries generated during decomposition. Further investigation into optimizing the Datalog rewriting for specific engines and exploring its application to more complex ontology fragments are also potential future directions.

Summary updated

BibTeX
@inproceedings{benedetto2025datalog,
  author = {Davide Benedetto and Marco Calautti and Hebatalla Hammad and Emanuel Sallinger and Adriano Vlad-Starrabba},
  title = {{A Datalog Rewriting Algorithm for Warded Ontologies}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.24963/ijcai.2025/485},
}
Figure