2DI ENS, ENS, CNRS, PSL University & Inria, France
A General Sufficient Condition for Rewriting Atomic Queries into GQL
Abstract
The emergence of the ISO standard GQL introduces a powerful query language extending first-order logic with controlled recursion, raising the question of its applicability to evaluation of ontology-mediated queries (OMQs). We focus on OMQs consisting of atomic queries over ontologies expressed in , an expressive Description Logic that is not, in general, first-order rewritable. To address this, we introduce DL automata, a novel formalism that captures the semantics of such OMQs via runs over fact sets. We then identify a large class of DL automata that can be rewritten into unions of conjunctive two-way regular path queries (UC2RPQs), a central fragment of GQL. Our class of automata relies on a stratification of their states, ruling out specific forms of cyclic dependencies known to raise the complexity. This yields a broad class of OMQs that are GQL-rewritable.
1 Introduction
In ontology-mediated query answering, user queries are enriched with conceptual knowledge about the domain of interest, described in the form of an ontology. This conceptual layer enables the use of a more user-friendly vocabulary and supports the retrieval of implicit information derived from the explicit knowledge in the ontology, thereby enriching query answers. Description Logics (DLs) are a predominant formalism for representing ontologies [3]. They provide the logical foundations of the OWL web ontology language, a W3C-standardized language for the Semantic Web [13]. In this work, we focus on the DL , an expressive language that allows the use of inverse roles and role constructors; the following example illustrates its usefulness.
Example 1
Consider the set of axioms111In the literature, DL axioms are often presented using a dedicated syntax [17]; we use equivalent first-order formulas, which are more familiar to a broader audience. given below, which formalises the notion of a ed user in a computer network.
Furthermore, consider the fact set , defined below and illustrated in Figure˜1.
The ontology entails the fact : indeed, node has a path to a itive node and another such path to a way node (see Figure˜1); moreover, by the second axiom of , every way node has a to some ine node. Therefore, the ontology also entails .
In the presence of DL axioms, a central reasoning task is to decide whether a given unary fact is entailed; together with the axioms, such a query forms a rule query. A common approach to evaluating a rule query over a database is to rewrite it into a classical query language, typically an FO query, while preserving equivalence, that is, ensuring that the original rule query and its rewriting are entailed by the same fact sets. This approach requires a target query language that is expressive enough to capture the ontological knowledge encoded in the axioms, but it also allows one to reuse existing database technologies, thereby avoiding the need to develop new evaluation tools.
The recently released ISO standard GQL,222https://www.iso.org/standard/76120.html for graph query languages, extends the expressive power of traditional FO queries (as captured by the SQL standard) by allowing controlled forms of regular recursion. GQL can express conjunctions of two-way regular path queries and their unions (UC2RPQs), and the evaluation problem for queries at its core has been shown to be NL-complete [7, 11]. As a new standard, GQL is expected to play a central role in a wide range of applications, making it important to understand which rule queries can be rewritten into this language. Example 2 presents an equivalent rewriting into UC2RPQs, and hence into GQL, of a rule query based on Example 1.
Example 2
Consider the query , where is the set of DL axioms described in Example˜1. This query is equivalent to the following positive conjunctive regular path query:
That is, these two boolean queries induce the same partition over the set of all fact sets. Put differently, for any given fact set , the DL ontology entails the fact if and only if satisfies the query . Consequently, instead of verifying whether entails using a dedicated DL reasoner, we may simply check whether satisfies using a database management system. To conclude the example, observe that the fact set from Example˜1 satisfies , as expected, since does entail . Moreover, the rule query is not expressible as an FO query, thereby motivating the need for rewriting techniques that go beyond this limited database query language.
Contributions.
We focus on rule queries with unary facts such as the one in the previous example, with rules expressed in the positive fragment of DL, defined in Section˜2. We show that these rules can be normalised into Datalog ones, in Section˜3. We then identify a large class of rule queries that can be rewritten into GQL; we proceed in two main steps. First, in Section˜4, we turn our rule queries into equivalent automata of a new form, closely related to the usual tree automata and which we refer to as DL automata. Second, in Section˜5, we identify a class of DL automata that can be rewritten into positive two-way regular path queries (PQs), and thus into UC2RPQs which in turn fall within GQL (Section˜6). Our criteria for rewritability relies on the existence of a stratification of the DL automata, which forbids some (but not all!) cyclic dependencies within its transition function. Interestingly, rule queries based upon the DL-Lite family trivially enjoy stratified automata, and thus the class we pinpoint extends DL-Lite. Additionally, our class guarantees the rewritability of rule queries that were not covered by prior attempts at rewriting into GQL [18], such as the one from Example˜2. Section˜7 elaborates further on related work; we discuss our conclusions and future work in Section˜8. This extended version of a paper to appear at ISWC 2026 contains proofs for all results in the appendix.
2 Preliminaries
We assume that the reader is familiar with the syntax and semantics of first-order (FO) logic, as well as with basic notions from automata theory.
Existential Rules and FO Facts.
We fix pairwise disjoint, countably infinite sets , , , and of unary predicates, binary predicates, constants, and variables respectively. We often refer to unary and binary predicates as classes and roles, respectively. An inverse role is an element of . A role expression is an element of . A term is an element of . Lists of terms are written as and are often treated as sets.
A class atom is a formula of the form with and . A role atom is a formula of the form with and . A FO atom is either a class atom or a role atom. Class facts, role facts, and FO facts are variable-free class atoms, role atoms, and FO atoms, respectively.
For an FO formula and a list of variables, we write to indicate that is the set of all free variables in . An (existential) rule is a FO sentence of the form where , , and are lists of variables such that , and and are conjunctions of FO atoms with .
The rule is Datalog if is the empty list. We refer to and as the body and the head of , respectively. When discussing rules, we omit universal quantifiers and often identify conjunctions of atoms such as and above with the corresponding set. We allow rules to contain unsafe variables–universally quantified variables that appear in the head but not in the body of the rule. A knowledge base (KB) is a pair consisting of a finite rule set and a finite fact set.
Description Logics.
A (positive) rule is one of the following rules:
| (1) | ||||||
| (2) | ||||||
| (3) | ||||||
| (4) | ||||||
| (5) | ||||||
| (6) | ||||||
| (7) |
Here, , , and are classes, and and are roles. We restrict ourselves to the positive fragment of , in which the bottom class is not allowed; in Section˜8, we discuss how our rewriting techniques could be adapted to handle this class. We consider rules in a restricted normal form, which is without loss of generality [16]. The right-hand side shows the corresponding Description Logic syntax, included for reference only and not used further in this paper. We adopt the rule-based presentation because rules are FO logic formulas and are therefore accessible to a wider audience, and because this syntax allows us to define fact entailment for naturally via the well-known chase procedure, which we briefly present below. We consider entailment under active domain semantics as discussed later, and hence rules of type (4) are not domain-dependent. A KB is a KB whose rule set is .
Query Languages.
In this paper, a rule query is a pair consisting of a finite rule set and a class fact. A Datalog query is a rule query whose rule set is Datalog. A query is a rule query whose rule set is .
A regular expression is an expression generated by the grammar
where . For a regular expression , let denote the set of all words over role expressions generated by . A RE atom is a formula of the form with a regular expression and . A RE fact is a variable-free RE atom. A positive two-way regular path query (PQ) is a formula without occurrences of free variables generated by the grammar
where is a class atom, is a RE atom, and is a variable. Note that, under our definition, all PQs are Boolean queries since every occurrence of a variable in a PQ lies within the scope of an existential quantifier. Without loss of generality, we assume that every variable is quantified exactly once in a PQ.
Semantics.
Consider some FO sentence . Given another FO sentence , we write to denote entailment under under active domain semantics, that is, standard FO semantics with quantifiers ranging over the active domain. Given a finite set of FO sentences, we write to denote . Given a KB , we write to denote .
A substitution is a function mapping variables to terms. For a substitution and a FO formula , let denote the formula obtained from by replacing all occurrences of every variable with .
Consider a fact set . We define . A (possibly empty) word over role expressions is a path from a constant to a constant in if both and occur in , and there exists a list of constants such that , , and for every . In particular, for , the empty word is a path from any constant occuring in to itself. For some constants and occurring , we write for the set of all paths from to in . Entailment of a PQ by , written , is defined inductively as follows:
-
•
If , then .
-
•
If is a class fact, then if .
-
•
If is a RE fact , then if .
-
•
If is of the form , then if and .
-
•
If is of the form , then if or .
-
•
If is of the form , then if for some substitution mapping to some constant in .
Since PQs contain no free variables, defining for any ground atom suffices to fully specify the semantics of entailment.
For a rule query , we write or to refer to the set of all finite fact sets such that . For a PQ , let be the set of all finite fact sets that entail . Here, stands for “query mapping”, since it associates every rule query or PQ with its semantic extension, namely the set of finite fact sets that satisfy it. A rule query or PQ is contained in another such query if ; these are equivalent if .
The Chase.
The chase algorithm can be used to decide fact entailment and is defined here only for Datalog, since rules with existentially quantified variables can be normalised away, as explained in the following section. A trigger is a pair consisting of a Datalog rule and a substitution that is defined exactly on the set of all variables occurring in . The trigger is applicable to a fact set if and all constants in the range of occur in . We define and, for a fact set , we define as the set including for every trigger with that is applicable to . For a Datalog rule set and a fact set , let . For a Datalog KB , let be the sequence of fact sets such that (i) , and (ii) for every . We define the chase of , written , as the union of all fact sets in this sequence. By our definition of applicable triggers, the chase is always finite, and it yields a set of facts that can be used to decide fact entailment under active domain semantics [1].
Proposition 1
A Datalog KB entails a fact if and only if .
For a Datalog KB , the chase depth of a fact with respect to is the least such that .
3 From to Queries
This section briefly recalls how to normalize away axioms of the form (5), (6), and (7) from a rule set.
Definition 1
To reduce to such rules, we proceed in two main steps. Assume we have a rule set . In the first step, we get rid of axioms of the forms (6) and (7). Let be the reflexive and transitive closure of the relation induced by on . Let be a copy of from which we remove all axioms of the forms (6) and (7) but add, for every such that or , the axioms:
-
•
for every axiom in ; and
-
•
for every axiom in ;
and, for every such that or , the axioms:
-
•
for every axiom in ; and
-
•
for every axiom in .
It is then routine to verify that for every class fact , the queries and are equivalent. We here strongly rely on the queries being based upon class facts, as this procedure would fail already for those based on role facts.
In the second step, we get rid of axioms of the form (5) by applying the translation to Datalog rules proposed in [10, Tables 2 and 3] for the more expressive . This reduction to their procedure is possible as our is already compliant with their notion of a rule set. We then remark that, given that we only input axioms of the forms (1)–(5) (or (F1), (F2), (F3) in the reference), their translation only outputs axioms of the form (1), (2), (3), or (4), as desired. In summary, we obtain the following:
Theorem 3.1
There is a computable function mapping every query to an equivalent query.
Example 3
Consider the set of rules obtained from the set from Example˜1 by removing and adding . Furthermore, observe that the DL queries and are equivalent.
We observe that, in general, the resulting query has an exponential size compared to the original query. This blow-up arises in the second step and cannot be avoided and already occurs in the part of the translation borrowed from [10]: when removing even a single axiom of form (5), one may need exponentially-many axioms of form (1) to preserve equivalence of the rule queries. Such pathological cases can be extracted from proofs of the ExpTime-hardness of basic reasoning tasks already in , see e.g. [16].
4 From Queries to DL Automata
We introduce DL automata as finite-state devices closely related to regular tree automata, tailored to capture the expressive power of queries. We first formally introduce these in Definition˜2 and then explain their semantics in Definition˜3. Next, in Definition˜4, we present a reduction from queries to DL automata and show that this translation preserves the semantics of the input queries. Finally, in Remark˜1, we state some properties of the automata produced by this translation, which are applied in the following section to develop an equivalence-preserving reduction from a class of DL automata to PQs.
Definition 2
We distinguish a special accepting state . A binary transition is an expression of the form , where is a state, , and is a set of states with . A multi-ary transition is an expression of the form , where is a state and is a set of states with . A transition is either a binary transition or a multi-ary transition. A DL automaton is a tuple , where is a constant, is a finite set of states, is a state, and is a transition function over , that is, a finite set of transitions featuring only states in .
Every DL automaton defines a boolean query and thereby partitions the set of all fact sets into those it accepts and those it rejects. As for rule queries and PQs, this partition is formalized by the “query mapping” function , defined below. To characterize the accepted fact sets, we first introduce the notion of a run of a DL automaton, analogous to a run of a tree automaton on a tree.
Definition 3
A run of a DL automaton over a fact set from , where is a state and is a constant, is a triple such that:
-
•
The pair is a finite rooted directed tree. Moreover, is a labeling function that maps every node to a pair consisting of a state and a constant, and maps the root to .
-
•
For every node with that has exactly one child in the tree, there is a binary transition satisfying all of the following implications: (i) If , then . (ii) If is a class, then and . (iii) If is a role expression, then there is some constant such that and .
-
•
For every node with with at least two children , there is a multi-ary transition such that for every .
Such a run is accepting if all leaf labels in the tree feature the accepting state, and the constant occurs in .
A DL automaton accepts a fact set if there is an accepting run of over from . Furthemore, let be the set of all fact sets accepted by . Such an automaton is contained in a rule query or a PQ if ; these two are equivalent if .
Example 4
In Figure˜2, we present a DL automaton together with one of its accepting runs over the fact set introduced in Example˜1. We will later argue that this automaton is equivalent to the query introduced in Example˜3; for now, the figure should help the reader understand why this automaton accepts this fact set.
In the following definition, we present a reduction from queries to DL automata that preserves equivalence (cf. Example˜5).
Definition 4
For every , let be a fresh state unique for . For a query , let denote the DL automaton where is the set of states containing and for every class occurring in , and is the transition function containing all of the following:
-
•
For every class occurring in , add .
-
•
For every rule such as , add .
-
•
For every rule such as , add .
-
•
For every rule such as , add .
-
•
For every rule such as , add .
Example 5
theoremCorrespondenceNormHornALCAutomata A query is equivalent to the DL automaton .
Proof(Sketch)
The theorem follows from the fact that, for every fact set and fact , the KB entails if and only if there is an accepting run of over starting from . The “if” direction is proved by induction on the height of the accepting run, while the “only if” direction is established by induction on the chase depth of with respect to .
To conclude the section, the following remark states several properties satisfied by every DL automaton produced by the reduction of Definition˜4.
Remark 1
Consider a query and the DL automaton . Then, all of the following hold:
-
1.
There are no transitions originating from the accepting state; that is, does not contain transitions of the form .
-
2.
Every (binary) transition labelled with a class points to the accepting state; that is, for every with , we have .
-
3.
Every non-final state directly reaches the accepting state through a binary transition; that is, for every , there is some transition of the form .
Properties 1 and 2 together ensure that transitions labelled with classes are considered only at the very end of an accepting run. This, in turn, simplifies the form of the regular expressions used in the following section to encode DL automata, since these only need to involve role expressions. Property 3 ensures that every state admits a path to the accepting state. If not for this restriction, a DL automaton may not accept any fact set. Such an automaton cannot be translated into a PQ, since the empty query is not a PQ under our definition.
5 From Stratified DL Automata to PQs
In this section, we present an equivalence-preserving reduction from a class of DL automata to PQs. More precisely, this reduction applies only to stratified automata, which we formally introduce in the following definition.
Definition 5
Consider a DL automaton .
-
•
For states and , we write if contains a binary transition of the form , and if contains a multi-ary transition of the form with .
-
•
We define as the union of and , and we define as the reflexive transitive closure of .
-
•
For states and , we write if there are and with , , , , and .
A DL automaton is stratified if the relation is acyclic, and if it satisfies the conditions in Remark˜1. If is stratified, we define as the function mapping a state to if has no successors with respect to , and to otherwise.
Example 6
Consider the DL automaton described in Figure˜2. For instance, we have , since all of the following hold:
Observe that is stratified, since every cycle in its transition function involves only binary transitions.
Our reduction from automata to PQs, formally introduced in Section˜5.2, proceeds by associating with every state of a stratified DL automaton a PQ describing the behaviour of when started in . This association is defined inductively: for states in stratum , the corresponding PQ is defined directly, whereas for states in stratum , it is defined using the PQs already associated with states in strictly lower strata. The role of stratification is to guarantee that this recursive construction is well defined. Indeed, the relation captures precisely those dependencies between states that arise when the translation encounters a path containing a binary transition labelled with a role expression and, possibly after intermediate transitions, a multi-ary transition. In this situation, our inductive construction branches out and introduces additional existentially quantified variables, thereby producing formulas such as the third disjunct of the PQ in Example˜2. If cycles over were allowed, the translation could follow the same dependencies indefinitely, repeatedly expanding the formula and introducing new existential variables, thus failing to produce a finite PQ.
We point out that in Definition˜5 we require stratified automata to satisfy the conditions of Remark˜1, since these are necessary to prove some of the results that follow. This is without loss of generality when considering DL automata corresponding to queries since, as explained in the previous section, all such automata satisfy these conditions. We define our reduction from automata to PQs in Section˜5.2; its definition relies on a preliminary translation for DL automata without multi-ary transitions, presented in Section˜5.1.
5.1 DL Non-Deterministic Finite Automata
In the following subsection, we present a reduction that transforms DL automata into equivalent PQs, that is, to positive FO formulas featuring regular expressions. To define such a transformation, we leverage existing automata-theoretic techniques defined for automata without multi-ary transitions.
Definition 6
A DL non-deterministic finite automaton (NFA) is a DL automaton without multi-ary transitions. Given states and , constants and , and a fact set , the automaton transitions from to in if there is a run of over from whose (unique) leaf is labelled with .
Observe that, by Definition˜3, in every run of a DL automaton without multi-ary transitions, each node has at most one child; hence, such a run has exactly one leaf. It is well known from classical automata theory that the set of all paths induced by such an automaton can be characterized by a regular expression [14].
Lemma 1
Consider a DL NFA that satisfies Remark˜1,333Recall that NFAs are DL automata by definition 6. and some states and of such that is different from . Then, there is a regular expression such that, for every fact set and constants and , the NFA can transition from to in if and only if .
Proof
By Kleene’s theorem [15], there is a regular expression such as over role expressions such that is the set of all words labelling the paths from to in . This applies because no path from to visits the accepting state since and is a sink in by Item 1 of Remark˜1. Therefore, these paths contain no classes, since by Item 2 of the same remark, all binary transitions of labelled with classes have as target.
The previous auxiliary result allows us to readily define an equivalence-preserving reduction from NFAs to PQs.
Definition 7
Given an NFA that satisfies Remark˜1, a state of , and a term , we define as the following PQ:
-
•
If is the accepting state , then this PQ is equal to .
-
•
Otherwise, this PQ is the disjunction containing, for every with , all of the following: (i) If for some , add the disjunct with a fresh variable. (ii) If , add the disjunct with a fresh variable.
Since above satisfies Remark˜1, every state distinct from the accepting state reaches it via a binary transition annotated with a class. Therefore, the corresponding PQ is either or a non-empty disjunction.
lemmalemmatransitioncrpq Consider a DL NFA that satisfies Remark˜1, a fact set , a state of different from , and a constant in . There is an accepting run of over starting at if and only if satisfies .
The previous result yields an equivalence-preserving reduction from NFAs to PQs illustrated in the following example.
Example 7
Consider the DL automaton depicted Figure˜2 and the NFA where is the set of all binary transitions in . By Definition˜7, this NFA is equivalent to the following PQ:
In the following subsection, we use the previously discussed reduction as a subroutine in a more general translation applicable to stratified DL automata, which may contain multi-ary transitions. To apply this subroutine, we define the NFA reachable from a given state in a DL automaton.
Definition 8
Given a DL automaton and a state of , we define as the NFA obtained from by performing the following modifications in sequence: remove all multi-ary transitions, remove all states that are not reachable from through the remaining (binary) transitions, and remove all (binary) transitions that mention a state removed in the previous step.
5.2 An Inductive Reduction for Stratified DL Automata
Before presenting our reduction, we define an extension of transition functions that allows adjacent -transitions to be handled in single step.
Definition 9
For a transition function over a set of states , let be the (minimal) set of multi-ary transitions such that: For every , we have . For every and with , we have .
Every DL automaton is equivalent to the extended automaton , since every transition in can be simulated by a finite sequence of -transitions already present in . Nevertheless, this extension allows every combination of states reachable via -transitions to be reached directly in a single step, thus avoiding potential cyclic dependencies in our reduction.
In the following definition, we formally introduce our equivalence-preserving reduction, which is admittedly concise and technically involved. We suggest that the reader first skim through it, then consult the examples that follow, and only then return to the definition for a clearer understanding.
Definition 10
Given a stratified DL automaton , a state , a term , we inductively define as the following PQ:
In the above, is the NFA and is a fresh variable.
In the following, we will sometimes write to refer to .
Observe that the above reduction is well defined since, for every stratified DL automaton , the relation is acyclic. Hence, we can first compute the PQs corresponding to all states in the lowest stratum, that is, states without successors with respect to . We then proceed stratum by stratum, computing the subsequent PQs by relying on those obtained previously. The following example illustrates both the base case and the inductive step of our construction.
Example 8
Consider the DL automaton from Figure˜2 and a constant . To illustrate the base case of our construction, we consider the state , which belongs to the lowest stratum of , and present the corresponding PQ.
The formula was already given in Example˜7. To illustrate the inductive step of our construction, we consider the state , which belongs to stratum of , and present the corresponding PQ.
theoremCorrespondenceAutomataCTRPQ A stratified DL automaton is equivalent to .
Proof(Sketch)
The theorem follows from the fact that, for every fact set and fact , the automaton has an accepting run from over if and only if entails . Both directions are proven by induction on the stratum of the state .
6 From Positive Queries to GQL Queries
In this section, we show that PQs can be expressed in the Graph Query Language (GQL) [7, 11]. Namely, we present an equivalence-preserving mapping from PQs to a query language that is already known to be expressible in GQL [12].
Definition 11
A union of conjunctive two-way regular path queries (UC2RPQ) is a PQ of the form where all are non-empty atom conjunctions.
Definition 12
Given a PQ , we define as a PQ obtained by exhaustively applying the following replacement rules:
-
1.
Replace a subformula of the form with , where is a fresh variable and is the formula that results from replacing all occurrences of in with .
-
2.
Replace a subformula of the form with .
-
3.
Replace a subformula of the form with .
The previous translation is included for completeness and is not an original contribution, as it relies on standard transformations [1, Chapter 5].
Lemma 2
For every PQ , the queries and are equivalent, and is a UC2RPQ.
Proof
One can prove the equivalence of the above formulas by induction on the sequence of formulas obtained by applying the replacement rules from Definition˜12 in the computation of . Since the latter formula is obtained by exhaustively applying Rules 1 and 2, disjunctions occur only at the outermost level. Moreover, by the exhaustive application of Rule 3, conjunctions occur only at the innermost level. Therefore, is a UC2RPQ.
The following is a corollary of the previous lemma and the equivalence-preserving reduction of unions of C2RPQs to GQL [12, Theorem 11].
Theorem 6.1
There is an equivalence-preserving reduction from PQs to GQL.
7 Related Work
In the line of work on rewriting DL queries, a cornerstone is the first-order rewritability of rule queries of the DL-Lite family, allowing translation into unions of Select-Project-Join SQL queries [5]. It is worth noting that DL automata associated to (the positive versions) of DL-Lite rule queries are always stratified. Indeed, the popular fragments of DL-Lite (DL-Litecore, DL-LiteR) forbid axioms of the form (1) for . By unraveling the successive steps exposed in Section˜3, it is not difficult to verify that axioms of the form (1), for , are not introduced throughout the normalization procedure. Multi-ary transitions are therefore absent from the corresponding DL automata, which guarantees the existence of a stratification with a single stratum.
Closer to our setting, rewriting of rule queries from (extensions of) into queries based upon regular expressions has also been studied. In [8], rule queries of linear are rewritten into regular-path queries, and this work was later extended to the so-called harmless linear [9] using UC2RPQs as a target query language. Harmless linear restricts axioms of the form (1) to the case of , as in DL-Lite, and limits the interaction of pairs of roles whenever there exists a third role such that both and are entailed by the set of rules. Already due to the restriction on conjunction, Example˜2 falls outside of the rule queries that their approach can rewrite. The nature of the restrictions in harmless linear makes a more formal comparison with our approach difficult. We have not found an example of a harmless linear rule query that does not have an associated stratified DL automaton.
More recently, and also motivated by the navigational features of GQL, quasi-linear with limited inverses () was introduced and has been shown to enjoy rewriting into UC2RPQs [18]. The definition of this latter extension of is characterized by a notion of locality. Typically, our axiom makes the class non-local, and forbids non-local classes from appearing in the head of an axiom of form 1. As a consequence, an axiom like is not allowed in . This shows that Example 2 is not a rule query, while being rewritable with our approach since its corresponding DL automaton is stratified (see Example 6). We speculate that by examining closely how the notion of (non-)locality is preserved through the different normalization steps exposed in Section˜3, one can establish that every rule query has an associate stratified DL automaton. Together with the previous remark regarding Example 2, such a verification would guarantee that our work strictly subsumes theirs.
A very recent work [2] has also pinpointed a subclass of queries that supports rewriting into nested 2RPQs, another fragment of GQL. The proposed subclass, namely , relies on the existence of a stratification of class and role expressions, constrained by the rule set. This stratification notably limits recursion to rules with shape or . As a consequence, their approach cannot rewrite the query , whose corresponding DL automaton is trivially stratified. Their work also seemingly varies from ours as the nested 2RPQs they consider support tests along the 2RPQs. However, we did not find an example of an query that is not already rewritable using our approach; a natural candidate exploiting the presence of tests in their formalism would have been the rule query , but both approaches fail to rewrite this query.
8 Conclusions and Future Work
As our main contribution, we define an equivalence-preserving procedure that transforms a class of queries into equivalent GQL formulas, proceeding in several steps. First, an input query is transformed into a query (Theorem˜3.1), which is then translated into a DL automaton (Example˜5). If the resulting automaton is stratified, it can be further translated into a PQ (Example˜8), and subsequently into a GQL query (Theorem˜6.1).
An immediate direction for future work is to extend our translation to handle other constructors available in standard DL languages. For instance, our technique can be readily adapted to incorporate disjointness rules of the form , which are typically allowed in Horn DLs [16]. When computing the rewriting of a query in the presence of such rules, we may treat as a normal class and instead compute a GQL rewriting for the rule query ; similar ideas have already been considered in e.g. [4]. This approach is correct since, for every fact set , the following hold: the KB is unsatisfiable if and only if it entails ; and entails if and only if it is unsatisfiable, or with the subset of without syntactic occurrences of . Extending our translation to other DL constructors, such as role chains, is likely to be more challenging. Nevertheless, complex roles appear amenable to our approach, since these closely correspond to regular languages [6, 21] and could in principle be handled using the techniques from Section˜5.1.
Another direction for future work is to relax the stratification condition in Definition˜5 to capture a broader class of queries expressible in GQL. Indeed, our approach is not complete and fails to characterise queries such as because this query is not equivalent to a PQ. Nevertheless, it can be translated into an equivalent nested regular path query, which can in turn be expressed in GQL [12, Theorem 11]. Considering nested regular path queries as a target language for our rewritings may therefore lead to a more general procedure.
Before diving into a deeper theoretical study, an empirical evaluation of our approach may be useful. Namely, one could consider a collection of real-world rule sets [20] and determine which are captured by our method, that is, determine how many correspond to a stratified DL automaton (cf. Definitions˜4 and 5). This would help assess (i) whether our translation procedure is sufficiently general to be useful in practice, and (ii) whether simple modifications could be introduced to capture existing queries outside its current scope.
Finally, another relevant direction for future work is to characterize those queries that do not admit an equivalent GQL formulation. In particular, one could aim to obtain results analogous to those in [19], which provide a decidable and complete characterization of queries that admit rewritings into first-order logic and linear Datalog. Our translation into DL automata presented in Section˜4 may prove useful in this regard, as it could enable the transfer of techniques from automata theory, a well-developed area of theoretical computer science, for establishing inexpressibility results.
Acknowledgements.
This research was funded by the Agence Nationale de la Recherche (ANR) under the Expand project (ANR-25-CE23-1215) and the France 2030 project (ANR-23-IACL-0008).
References
- [1] (1995) Foundations of databases. Addison-Wesley. External Links: ISBN 0-201-53771-0 Cited by: §2, §6.
- [2] (2026) A Horn extension of DL-Lite with NL data complexity. In Proceedings of the 39th International Workshop on Description Logics (DL 2026), CEUR Workshop Proceedings, Vol. 4230. External Links: Link Cited by: §7.
- [3] F. Baader, D. Calvanese, D. L. McGuinness, D. Nardi, and P. F. Patel-Schneider (Eds.) (2003) The description logic handbook: theory, implementation, and applications. Cambridge University Press. External Links: ISBN 0-521-78176-0 Cited by: §1.
- [4] (2012) A general datalog-based framework for tractable query answering over ontologies. J. Web Semant. 14, pp. 57–83. External Links: Link Cited by: §8.
- [5] (2007) Tractable reasoning and efficient query answering in description logics: the DL-Lite family. Journal of Automated Reasoning (JAR) 39 (3), pp. 385–429. External Links: ISSN 1573-0670, Link Cited by: Appendix 0.D, §7.
- [6] (2019) From Horn- to datalog: A data-independent transformation that preserves assertion entailment. In Proceedings of the 33rd AAAI Conference on Artificial Intelligence (AAAI 2019), pp. 2736–2743. External Links: Link Cited by: §8.
- [7] (2022) Graph pattern matching in GQL and SQL/PGQ. In Proceedings of the 2022 International Conference on Management of Data (SIGMOD 2022), pp. 2246–2258. External Links: Document Cited by: §1, §6.
- [8] (2016) Query rewriting under linear el knowledge bases. In Web Reasoning and Rule Systems, pp. 61–76. External Links: ISBN 978-3-319-45276-0 Cited by: §7.
- [9] (2025) Efficient ontology-mediated query answering: extending DL-liteR and linear . Journal of Artificial Intelligence Research 82, pp. 851–899. External Links: Link Cited by: §7.
- [10] (2021) Query rewriting for Horn- plus rules. Proceedings of the 35th AAAI Conference on Artificial Intelligence (AAAI 2021) 26 (1), pp. 726–733. External Links: Link Cited by: Appendix 0.A, Appendix 0.D, §3, §3.
- [11] (2023) A Researcher’s Digest of GQL. In Proceedings of the 26th International Conference on Database Theory (ICDT 2023), Vol. 255, pp. 1:1–1:22. External Links: Document Cited by: §1, §6.
- [12] (2023) GPC: a pattern calculus for property graphs. In Proceedings of the 42nd ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems (PODS 2023), pp. 241–250. External Links: Document Cited by: §6, §6, §8.
- [13] (2010) Foundations of semantic web technologies. Chapman and Hall/CRC Press. External Links: Link, ISBN 9781420090505 Cited by: §1.
- [14] (2007) Introduction to automata theory, languages, and computation, 3rd edition. Pearson international edition, Addison-Wesley. External Links: ISBN 978-0-321-47617-3 Cited by: §5.1.
- [15] (1979) Introduction to automata theory, languages and computation. Addison-Wesley. Cited by: §5.1.
- [16] (2013) Complexities of horn description logics. ACM Transactions on Computational Logic (TOCL) 14 (1), pp. 2:1–2:36. External Links: Link Cited by: §2, §3, §8.
- [17] (2012) A description logic primer. CoRR abs/1201.4089. External Links: Link, 1201.4089 Cited by: footnote 1.
- [18] (2025) Towards practicable algorithms for rewriting graph queries beyond DL-Lite. In The Semantic Web, E. Curry, M. Acosta, M. Poveda-Villalón, M. van Erp, A. Ojo, K. Hose, C. Shimizu, and P. Lisena (Eds.), pp. 342–361. External Links: ISBN 978-3-031-94575-5 Cited by: §1, §7.
- [19] (2022) A complete classification of the complexity and rewritability of ontology-mediated queries based on the description logic EL. Artificial Intelligence 308, pp. 103709. External Links: Link Cited by: §8.
- [20] (2014) The manchester OWL repository: system description. In Proceedings of the 13th International Semantic Web Conference, (ISWC 2014), Posters & Demonstrations Track, CEUR Workshop Proceedings, pp. 285–288. External Links: Link Cited by: §8.
- [21] (2012) Elimination of complex RIAs without automata. In Proceedings of the 25th International Workshop on Description Logics (DL 2012), Y. Kazakov, D. Lembo, and F. Wolter (Eds.), CEUR Workshop Proceedings. External Links: Link Cited by: §8.
Appendix 0.A Proofs of Section˜3
In this section, we prove the claims leading to Theorem˜3.1. Let be a query, and the rule set obtained as described in Section˜3.
We first verify that and are equivalent. Notice that axioms from are consequences of , and thus it is clear that . It remains to prove the converse, that is the following lemma.
Lemma 3
.
Proof
Let be a fact set such that , we need to prove that . Let be an FO-model of , we denote its domain and its interpretation function. We construct an FO-structure that extends and will be a model of . The domain of is also , it interprets every class as in , and every role as follows:
We further refer to the property that, by definition, and agree on the interpretation of classes as . We now verify that is a model of , which will conclude the proof since it guarantees using the assumption that and consequently by . It is clear that , it thus remains to verify . We examine each possible form of axiom in :
-
(1)
Immediate by .
-
(2)
Assume , and . By definition of , we have and, by , we have . By definition of , we have for some . Now, either , and then we have by definition of , or and we have . Either way, yields , and we conclude using .
-
(3)
Assume , and . By definition of , we have and, by , we have . By definition of , we have for some . Now, either , and then we have by definition of , or and we have . Either way, yields , and we conclude using .
-
(4)
Immediate by .
-
(5)
Assume and . By definition of , we have and, by , we have . Since , there exists such that . Using that is reflexive, the definition of yields . Using , we obtain and we are done.
-
(6)
Immediate by construction of and being transitive.
-
(7)
Immediate by construction of and being transitive.
We now explain how the Datalog translation proposed in [10] can be applied to . Let us highlight that complies with the normal form demanded in [10]: axioms of with forms (1) or (4) are exactly in their form (F1); those with forms (2) or (3) are exactly in their form (F2) (since the latter supports inverse roles!); and those with form (5) are exactly in their form (F3). In particular, does not contain any axiom in their form (F4). In turn, it follows that, when applying the inference rules from Table 2 in [10], their Rules and are never applied. The same holds for their Rule since does not contain role inclusions, and Rule since we restricted our attention to positive rules. These observations further guarantee that, applying the final translation in Table 3 [10], only the first two completion rules are ever applied. Therefore, we obtain a set of Datalog rules whose rules are of form and , where is possibly an inverse role. Now, rules are either in forms (1) or (4) in our formalism, while rules are either in form (3) if , or in form (2) if . Altogether, we obtained a set of rules such that, for every class fact , is equivalent to [10, Theorem 3], thus equivalent to . This concludes the proof of Theorem 3.1.
Appendix 0.B Proofs of Section˜4
In this section, we prove Example˜5, which establishes the equivalence between a query and the corresponding automaton . More precisely, we prove Lemmas˜5 and 4, from which the theorem follows directly as a corollary.
Lemma 4
A query is contained in the DL automaton .
Proof
We fix a query , the DL automaton , and a fact set . To prove the lemma, we assume that and show that this implies . More precisely, we establish that for any given fact , there is an accepting run of over from . Applying this claim to the fact , we obtain an accepting run of over from , and therefore . We prove the claim by induction on the depth of with respect to . Recall also that if and only if by Proposition˜1.
For the base case, we assume that has depth 1 with respect to , which implies that . Consider now the directed labelled tree , where is the labelling function mapping to and to . This tree is an accepting run of over from . Observe that it has a unique leaf labelled with the accepting state. Moreover, the edge is valid, since and .
For the induction step, we assume that has depth with respect to . Then at least one of the following cases applies:
-
•
There is a rule of the form and a constant such that . By induction hypothesis, there is an accepting run of over from . Consider the directed labelled tree where for some fresh node , where is the root node of , and is the function that extends and maps to . We argue that is an accepting run for over from :
-
–
Since , we have that . Since no rule allows the derivation of binary facts, we have that , which implies that the edge is valid as per Definition˜3. Therefore is a run, as all other edges in this tree satisfy the same definition by induction hypothesis.
-
–
The leaves in are exactly the leaves of . Hence, all of the leaves in feature the accepting state.
-
–
-
•
There is a rule of the form and a constant such that . This case is analogous to the previous one.
-
•
There is a rule of the form with . By induction hypothesis, there is an accepting run of over from for every . Consider the directed labeled tree where with a fresh node, with the root node of for every , and is the function that extends and maps to . We argue that is an accepting run for over from :
-
–
As , we have that . This implies that the edges through in are valid as per Definition˜3. Therefore is a run, as all other edges in this tree satisfy the same definition by induction hypothesis.
-
–
The leaves in are exactly the union of the leaves of the . Hence, all of the leaves in feature the accepting state.
-
–
-
•
There is a rule of the form . Consider the directed labelled tree , where maps to and to . This tree is an accepting run of over starting from . Note that since .
In either case, there is an accepting run of over from .
Lemma 5
A query contains the DL automaton .
Proof
We fix a query and a fact set . To prove the lemma, we assume that and show that . More precisely, we argue that, given some fact , if there is an accepting run of over from , then . This implies in particular that , and therefore that . The proof proceeds by induction on the height of the accepting run of the fact . Recall that a fact is entailed by if and only if it is in by Proposition˜1.
Given some fact , there is no accepting run of over from of height . Indeed, the unique node of such a run would have to feature both and in its label, which is impossible since these are distinct states. Hence, the base case of our induction starts with runs of height .
Regarding the base case, we assume that there is an accepting run of over from of height 2. In this case, the root node of this run is labelled and all of the labels of its children feature the accepting state. Therefore, there are only two possible cases:
-
•
We have that . Note that is a transition of .
-
•
We have that is a transition of . Note that, in this case, we have that .
In either case, we have that . Recall that occurs in since there is an accepting run of over from .
Regarding the induction step, let us consider an accepting run for over from of height . We consider two different cases depending if the root node of this run has one child or more.
-
•
Assume that the root has a unique child , which does not feature in its label by Remark˜1. Then, by Definition˜3 and Remark˜1, one of the following cases must hold:
-
–
There is some class such that is labelled with , , and . Now consider the tree obtained by removing from , which is of height and is an accepting run for from over . Hence, by induction hypothesis. Therefore, since .
-
–
There are a class and a constant such that is labelled with , , and . Now consider the tree obtained by removing from , which is of height and is accepting for over from . Hence, by the induction hypothesis. Therefore, since .
-
–
There are a class and a constant such that is labelled with , , and . This case is analogous to the previous one.
-
–
-
•
Consider the root and its multiple children . By Definition˜3, there are some such that is labelled with , with , and so on. Moreover, in . Now, for every , consider the subtree of rooted at , which is of height at most and is an accepting run of over from . From the existence of this trees, we conclude that by induction hypothesis. Therefore, since .
In either case above, we have .
Appendix 0.C Proofs of Section˜5
In this section, we provide complete proofs of the results from Section˜5. More precisely, we prove Lemmas 7, 7, and 8. Note that Example˜8 follows directly as a corollary of the latter two lemmas.
*
Proof
We first prove the forward implication of the equivalence stated in the lemma. Assume that there is an accepting run of on starting from , and let be the sequence of nodes occurring, in order, along the unique branch of this run. Note that since is different from the accepting state. Then we are in one of the following cases:
-
•
If , then either or, otherwise, for some . In the first case, the disjunct is in , and that disjunct is entailed by . In the second case, the disjunct is in , and that disjunct is entailed by since . Note that this fact is in because the run is accepting and .
-
•
If , then consider the node and its label . Since the NFA can transition from to in , we have that entails from Lemma˜1. Now, one of the following cases must hold:
-
–
If , then the disjunct is in and entails this disjunct, since this fact set entails .
-
–
If not, then there is some such that , and, since the run is accepting, . In this case, the disjunct occurs in and is entailed by . This is indeed the case since entails both and .
-
–
In either case, we have that satisfies .
For the reverse direction of the equivalence, assume that satisfies . Then satisfies at least one disjunct of this PQ. Depending on the type of disjunct satisfied by , one of the following cases applies:
-
•
If , then there is a transition . In that case, the run from to is accepting for in .
-
•
If for some , then we have . In that case, the run from to is accepting since .
-
•
Assume that is of the form . Then, there is some constant such that entails and , and . From Lemma˜1, we conclude that can transition from to in , that is, that there is a run of over that starts on a node labelled with and ends on a node labelled . If we append one more node at the end of this run labelled with , we obtain an accepting run of starting over ; recall that and that .
-
•
Assume that is of the form . Then, there is some constant such that entails , and . From Lemma˜1, we conclude that can transition from to in , that is, that there is a run of over that starts on a node labelled with and ends on a node labelled . If we append one more node at the end of this run labelled with , we obtain an accepting run of starting over ; recall that .
In any case, we have an accepting run for from over .
We then show a preliminary lemma allowing us to substitute an automaton to its extended version: for the following, we will assume that is in extended form.
Lemma 6
Consider an automaton and its extended version . For every fact set , state , and constant , there is an accepting run of over from if and only if there is an accepting run of over from . Therefore, and are equivalent.
Proof
The inclusion of in is trivial. For the other direction, we show that every - transition of can be simulated by a finite sequence of -transitions in : from this, it follows that if there is an accepting run on for some fact set , starting node then there is an accepting run on for the same fact set and starting node.
First note that we can express as the (finite) limit of some defined such that and for every , where is a state, and and are sets of states such that , and , and . We then show, by induction on , that every can be simulated by a finite sequence of transitions of . For the base case, if the transition is of form , then the transition can be simulated by an empty sequence of transitions: therefore can be simulated by a finite sequence of transitions of .
For the induction step, we assume that , and consider . Then there are some , , so that , and , and , and . Since , it can be simulated by a finite sequence of transitions in . Then, the sequence of transitions simulates : indeed, the transition can be added to the sequence since . Doing so removes and adds to the states at the end of the sequence: therefore, the states at the end of the new sequence are . Therefore we can simulate with a finite sequence of transitions of .
We then move on to the two main lemmas.
Lemma 7
A stratified DL automaton contains .
Proof
We fix a stratified DL automaton , its extended version , the query , and a fact set . To prove the lemma, we assume that entails and show that accepts . More precisely, we prove the following claim by induction on : if entails for some state of in stratum and some constant , then there is an accepting run of on starting from . Applying this claim to and , we obtain an accepting run of on starting from , and hence accepts . Recall that and are equivalent by Lemma˜6 and therefore, the lemma follows.
For the base case, let be a state in stratum and a constant such that satisfies . Since belongs to stratum , no state succeeds with respect to . Therefore, by Definition˜10, we have:
Since this PQ is entailed by , there is some such that satisfies . Since this formula is a conjunction, satisfies for every . Hence, there is an accepting run for over from every by Definition˜7. Therefore, for every , there is an accepting run for over from by Lemma˜6. Without loss of generality, we assume that the sets are mutually disjoint. Now, consider the tree defined as follows:
-
•
Let with a fresh node that is the root of this tree.
-
•
Let with the root of , the root of , and so on.
-
•
Let be the mapping extending for every and maps to .
We argue that is an accepting run for over from . This follows because and hence, the edges in this tree satisfy Definition˜3. Moreover, for every , we have that is an accepting run over from . Hence, all of the edges in also satisfy this definition, and all of the leaves in feature the accepting state.
For the induction step, we consider a state of stratum and a constant such that satisfies . Since satisfies , it satisfies some disjunct, there is some such that satisfies the following:
In the remainder of our argument, we define an accepting run for over from . The root node of this run is mapped by to . Moreover, there are some distinct nodes such that, for every , we have that and . Now, for every , we extend the run in the following manner:
-
•
If , there is an accepting run on over from as argued in the base case. We attach this directed tree to the node .
-
•
Otherwise, there is a constant and some states such that , , , …, , and satisfies the following PQ:
Since satisfies , we have from Lemma˜1 that there is a run whose root node is labeled and whose unique leaf is labeled : we attach this directed tree to , and call the fresh leaf node .
Since satisfies , the edge is valid: we attach it to , and label the fresh leaves nodes .
Since satisfies ,…, , by induction hypothesis, there are accepting runs from , …, . We attach each to .
After the modifications, has only accepting leaves: we have built an accepting run for over from . We conclude that there is an accepting run of over from , and the induction step holds. Therefore, if some satisfies the PQ , we have an accepting run of from over .
Lemma 8
A DL automaton is contained in .
Proof
We fix a DL automaton and a fact set . To prove the lemma, we assume that there is an accepting run of from over , and show that this implies that satisfies . More precisely, we show the following claim by induction on : for any state of in stratum and any constant , if has an accepting run from some we have . Applying this claim to and , it follows that if there is an accepting run for from , then satisfies .
For the base case, consider a state of stratum 1 and an accepting run whose root is labeled and whose leaves are labeled with for some in . We define the epsilon-section of , noted , as the (maximal) subset run starting from the root using only edges matched with -transitions. By the definition of , there is a transition such that the leaves of are labeled with the states of . Since is of stratum 1, there can be only binary edges below these nodes: if that was not the case, some states of leaves of the run would be of a lower strata than the state of the root. Moreover, for every , there is an accepting run from in over . By Definition˜7, this means that accepts. Therefore, the PQ accepts and the property is verified.
For the induction step, if is of strata , we consider an accepting run for on . Similarly to the base case, we consider the epsilon-section of the run: if there are only binary edges outside of it, then we are in the same situation as in the base case. If not, we consider the leaves of the epsilon-section of the run, labeled . For each , we are in one of two cases:
-
•
If has only binary edges descending from it, then the part of the tree rooted at is an accepting run for . In that case, is satisfied.
-
•
If that is not the case, consider the first multi-ary edge descending from , called with labeled and each labeled .
-
–
By definition, can transition to in : therefore, by Lemma˜1 we have .
-
–
Moreover, in the automaton, we have that , and since , …, and follow a multi-ary transition outside the epsilon-section of the run , …, and .
-
–
Since the run is accepting, the sub-runs starting at , …, are valid runs with only accepting leaves: they are also accepting for over . As have strata at most , by induction hypothesis, is satisfied by .
-
–
It follows that
is satisfied for some , and therefore that is.
Therefore, we have that for any state and constant , if there is an accepting run of from over , then satisfies .
Appendix 0.D Claim of Section˜7
We provide more details regarding our claim that positive fragments of DL-Litecore and DL-LiteR sets of rules always have stratified associate DL automata. We assume familiarity with DL-Lite and refer the reader to [5]; we discuss positive DL-LiteR since it subsumes DL-Litecore.
Let us first highlight that, to be seen as rules in our normal form, positive DL-LiteR rules requires the introduction of a placeholder class that replaces in every occurrence of a DL-Lite concept of form (or, as is common, simply ), where is possibly an inverse role. We add the rule (axiom of form (4)) to witness this behavior.
Let us now examine the normalization exposed in Section˜3. Getting rid of axioms of form (6) and (7) does not introduce any axiom of form (1) with , as desired. In Appendix˜0.A, we already established that inference rules Rules , , and never apply. Therefore, the only inference rule in [10, Table 2] that may introduce axioms of form (1) with is the rule . To apply, this rule requires an axiom with shape . However, none of the other rules may produce such axiom, therefore it must come directly from our DL-LiteR rules. This implies that . The body of the inferred rule thus, syntactically, takes the form (1) with . However, due to our rule , it is equivalent to the exact same inferred rule, but in which every occurrence of has been removed from its body, which restores .