Skip to main content

Query Extensions and Incremental Query Rewriting for OWL 2 QL Ontologies

Abstract

Query rewriting over lightweight ontologies, like DL-Lite ontologies, is a prominent approach for ontology-based data access. It is often the case in realistic scenarios that users ask an initial query which they later refine, e.g., by extending it with new constraints making their initial request more precise. So far, all DL-Lite systems would need to process the new query from scratch. In this paper, we study the problem of computing the rewriting of an extended query by ‘extending’ a previously computed rewriting of the initial query and avoiding recomputation. Interestingly, our approach also implies a novel algorithm for computing the rewriting of a fixed query. More precisely, the query can be ‘decomposed’ into its atoms and then each atom can be processed incrementally. We present detailed algorithms, several optimisations for improving the performance of our query rewriting algorithm, and finally, an experimental evaluation.

This is a preview of subscription content, access via your institution.

Fig. 1
Fig. 2

Notes

  1. Note that, in \(\text{ DL-Lite}_R\) one can also allow for concept (role) disjointness axioms of the form \(B_1\sqsubseteq \lnot B_2\) (\(R_1\sqsubseteq \lnot R_2\)). However, these axioms do not have any effects in query answering when \(\mathcal T \cup \mathcal A \) is consistent [8, 28]; hence we will discard them here.

  2. http://code.google.com/p/iqaros/

  3. http://swat.cse.lehigh.edu/projects/lubm/

  4. In the normalised ontologies each axiom of the form \(A\sqsubseteq \exists R.B\) in the original ontology is rewritten into the axioms \(A\sqsubseteq \exists R_n, R_n\sqsubseteq R,\) and \(\exists R_n^-\sqsubseteq B\) for \(R_n\) a new role.

  5. We consider a system X to be ‘notably faster’ than a system Y if \(t_Y-t_X>20\) ms.

References

  1. Acciarri A, Calvanese D, De Giacomo G, Lembo D, Lenzerini M, Palmieri M, Rosati R (2005) Quonto: querying ontologies. In: Proceedings of the 20th international conference on artificial intelligence (AAAI-05)

  2. Artale A, Calvanese D, Kontchakov R, Zakharyaschev M (2009) The DL-Lite family and relations. J Artif Intell Res 36:1–69

    MATH  MathSciNet  Google Scholar 

  3. Calì A, Gottlob G, Lukasiewicz T (2009) A general datalog-based framework for tractable query answering over ontologies. In: Proceedings of the twenty-eigth ACM SIGMOD-SIGACT-SIGART symposium on principles of database systems, PODS 2009, pp 77–86

  4. Calì A, Gottlob G, Pieris A (2009) Tractable query answering over conceptual schemata. In: Proceedings of the 28th international conference on conceptual modeling (ER 2009), pp 175–190

  5. Calì A, Gottlob G, Pieris A (2010) Advanced processing for ontological queries. Proceedings of the VLDB Endowment 3(1):554–565

  6. Calì A, Gottlob G, Pieris A (2012) Ontological query answering under expressive entity-relationship schemata. Inf Syst 37(4):320–335

    Article  Google Scholar 

  7. Calvanese D, De Giacomo G, Lembo D, Lenzerini M, Rosati R (2006) Data complexity of query answering in description logics. In: Proceedings of the 10th international conference on principles of knowledge representation and reasoning (KR 06), pp 260–270

  8. Calvanese D, De Giacomo G, Lembo D, Lenzerini M, Rosati R (2007) Tractable reasoning and efficient query answering in description logics: the DL-Lite family. J Autom Reasoning 39(3):385–429

    Article  MATH  Google Scholar 

  9. Chortaras A, Trivela D, Stamou G (2011) Optimized query rewriting in OWL 2 QL. In: Proceedings of the 23rd international conference on automated deduction (CADE 23), Polland, pp 192–206

  10. Cuenca Grau B, Horrocks I, Motik B, Parsia B, Patel-Schneider P, Sattler U (2008) OWL 2: the next step for OWL. J Web Semantics (JWS) 6(4), 309–322

    Google Scholar 

  11. Gottlob G, Orsi G, Pieris A (2011) Ontological queries: rewriting and optimization. In: Proceedings of the 27th international conference on data engineering (ICDE 2011), pp 2–13

  12. Gottlob G, Orsi G, Pieris A (2011) Ontological query answering via rewriting. In: Proceedings of the 15th international conference on advances in databases and information systems, Springer-Verlag, pp 1–18

  13. Gottlob G, Schwentick T (2012) Rewriting ontological queries into small nonrecursive datalog programs. In: Proceedings of the 13th international conference on principles of knowledge representation and reasoning (KR 2012)

  14. Gupta A, Mumick IS, Rossl KA (1995) Adapting materialized views after redefinitions. In: Proceedings of ACM SIGMOD international conference on management of data, pp 211–222

  15. Horrocks I, Patel-Schneider PF, van Harmelen F (2003) From SHIQ and RDF to OWL: the making of a web ontology language. J Web Semantics 1(1):7–26

    Article  Google Scholar 

  16. Jansen BJ, Spink A, Blakely C, Koshman S (2007) Defining a session on web search engines: research articles. J Am Soc Inf Sci Tech 58:862–871

    Article  Google Scholar 

  17. Jansen BJ, Spink A, Pedersen J (2005) A temporal comparison of altavista web searching: research articles. J Am Soc Inf Sci Tech 56:559–570

    Article  Google Scholar 

  18. Kikot S, Kontchakov R, Zakharyaschev M (2011) On (in)tractability of OBDA with OWL 2 QL. In: Proceedings of the 24th international workshop on description logics (DL 2011)

  19. Kontchakov R, Lutz C, Toman D, Wolter F, Zakharyaschev M (2010) The combined approach to query answering in DL-Lite. In: Proceedings of the 20th international conference principles of knowledge representation and reasoning (KR 2010)

  20. Lutz C (2008) The complexity of conjunctive query answering in expressive description logics. In: Proceedings of the 4th international joint conference on automated reasoning, IJCAR 2008, pp 179–193

  21. Lutz C, Toman D, Wolter F (2009) Conjunctive query answering in the description logic EL using a relational database system. In: Proceedings of the 21st international joint conference on artificial intelligence (IJCAI 2009), pp 2070–2075

  22. Mohania M (1997) Avoiding re-computation: view adaptation in data warehouses. In: Proceedings of 8 th international database workshop, pp 151–165

  23. Motik B, Cuenca Grau B, Horrocks I, Wu Z, Fokoue A, Lutz C (2009) OWL 2 web ontology language profiles

  24. Orsi G, Pieris A (2011) Optimizing query answering under ontological constraints. PVLDB 4(11):1004–1015

    Google Scholar 

  25. Ortiz M, Calvanese D, Eiter T (2008) Data complexity of query answering in expressive description logics via tableaux. J Autom Reasoning 41(1):61–98

    Google Scholar 

  26. Pass G, Chowdhury A, Torgeson C (2006) A picture of search. In: Proceedings of the 1st international conference on scalable information systems (InfoScale 06). ACM (2006)

  27. Pérez-Urbina H, Horrocks I, Motik B (2009) Efficient query answering for OWL 2. In: Proc. of the international semantic web conference (ISWC2009), pp 489–504

  28. Pérez-Urbina H, Motik B, Horrocks I (2010) Tractable query answering and rewriting under description logic constraints. J Appl Logic 8(2):186–209

    Article  MATH  Google Scholar 

  29. Poggi A, Lembo D, Calvanese D, De Giacomo G, Lenzerini M, Rosati R (2008) Linking data to ontologies. J Data Semantics X, 133–173

  30. Rodriguez-Muro M, Calvanese D (2012) High performance query answering over DL-Lite ontologies. In: Proceedings of the 13th international conference principles of knowledge representation and reasoning, KR 2012

  31. Rosati R (2012) Query rewriting under extensional constraints in DL-Lite. In: Proceedings of the international workshop on description logics, DL-2012

  32. Rosati R, Almatelli A (2010) Improving query answering over DL-Lite ontologies. In: Proceedings of the international conference on principles of knowledge representation and reasoning (KR-10)

  33. Venetis T, Stoilos G, Stamou G (2011) Query rewriting under query extensions for OWL 2 QL ontologies. In: Proceedings of the 7th international workshop on scalable semantic web Knowledge base systems (SSWS2011), Germany

Download references

Acknowledgments

Work by Giorgos Stoilos is supported by a Marie Curie Career Reintegration Grant within European Union’s Seventh Framework Programme (FP7/2007-2013) under REA grant agreement 303914.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Tassos Venetis.

Additional information

This is a revised and considerably extended version of the workshop paper [33].

A Omitted Proofs

A Omitted Proofs

Lemma 1

Let \(q_1,q_2\) be two CQs such that \(q_2\) subsumes \(q_1\) and let \(q^{\prime }_1\) be the result of applying an axiom \(I\) to \(q_1\). If \(q_2\) does not subsume \(q^{\prime }_1\), then either \(I\) is applicable to \(q_2\) and the result subsumes \(q^{\prime }_1\) or for \(1\le i\le n\), atoms of the form \(P(u,v),P(z_i,v)\) or \(P(v,u),P(v,z_i)\) exist in \(q_2\) such that for \(1\le i, j\le n\), \(i\ne j\) we have \(z_i\ne z_j\) and for \(\lambda =\{z_i\mapsto u\mid 1\le i\le n\}\), \(I\) is applicable to \(q_2{_\lambda }\) and the result subsumes \(q^{\prime }_1\).

Proof

Since \(q_2\) subsumes \(q_1\), there exists a substitution \(\theta \) s.t. \([\{Q(\mathsf{avar }(q_2))\}\cup q_2]_\theta \subseteq \{Q(\mathsf{avar }(q_1))\}\cup q_1\); however, \(Q\) does not appear in either \(q_1\) or \(q_2\), hence \(q_2{_\theta }\subseteq q_1\). Moreover, since \(q_2\) does not subsume \(q^{\prime }_1\) we have \(q_2{_\theta }\nsubseteq q^{\prime }_1\). Hence, since \(q^{\prime }_1\) is the result of applying \(I\) to \(q_1\) we have that \(I\) is applied to an atom \(\alpha \in q_1\) that is also in \(q_2{_\theta }\) replacing it with a new atom \(\beta \) that is not in \(q_2{_\theta }\). Next, \(\alpha \in q_2{_\theta }\) implies that \(q_2\) contains an atom \(\alpha _0\) such that \(\alpha =\alpha _0{_\theta }\), i.e., an atom with the same predicate name as \(\alpha \), but possibly containing different variables. By case analysis on the different types of applications between axioms and query atoms we show that either \(I\) is also applicable to \(\alpha _0\) and for \(q^{\prime }_2\) the result of applying \(I\) to \(q_2\), \(\theta \) can be extended to a new substitution \(\sigma \) s.t. \(q^{\prime }_2{_\sigma }\subseteq q^{\prime }_1\), or for \(i\ge 1\) atoms of the form \(P(u,v),P(z_i,v)\) or \(P(v,u),P(v,z_i)\) exist in \(q_2\) such that for \(\lambda =\{z_i\mapsto u\mid i\ge 1\}\), \(I\) is applicable to \(q_2{_\lambda }\) and the result subsumes \(q^{\prime }_1\).

Recall first that \(\alpha \in q_1\), \(\alpha \in q_2{_\theta }, \alpha _0\in q_2\), and \(\beta \in q^{\prime }_1\). We have the following cases:

  1. 1.

    If \(\alpha =A(x)\), then \(I\) is of the form \(C\sqsubseteq A\), with \(C\) a concept, \(\beta \) is of the form \(C(x)\), while \(\alpha _0\) is of the form \(A(u)\), with \(u\mapsto x\in \theta \). Then, clearly, \(I\) is also applicable to \(q_2\) creating a new query \(q^{\prime }_2\) that contains \(C(u)\). Then, we have the following cases:

    • If \(I\) is of the form \(B\sqsubseteq A\), then \(\beta =B(x)\). In this case, \(B(u)\in q^{\prime }_2\), and for \(\sigma =\theta \) we have \(B(x)\in q^{\prime }_2{_\sigma }\) which implies that \(q^{\prime }_2{_\sigma }\subseteq q^{\prime }_1\).

    • If \(I\) is of the form \(\exists P\sqsubseteq A\), then \(\beta =P(x,y)\) for \(y\) a new variable in \(q_1\). In this case, \(P(u,z)\in q^{\prime }_2\) for \(z\) a new variable in \(q_2\). Since \(z\) is new in \(q_2\), \(\theta \) can be extended to \(\sigma =\theta \cup \{z\mapsto y\}\). Then, \(P(x,y)\in q^{\prime }_2{_\sigma }\) which implies that \(q^{\prime }_2{_\sigma } \subseteq q^{\prime }_1\).

    • The case where \(I\) is of the form \(\exists P^-\sqsubseteq A\) is symmetric with the previous one.

  2. 2.

    If \(\alpha =P(x,y)\) and \(I\) is of the form \(S\sqsubseteq P\) (or equivalently \(S^-\sqsubseteq P^-\)), then \(\beta =S(x,y)\), while \(\alpha _0\) is of the form \(P(u,v)\) with \(\{u\mapsto x,v\mapsto y\}\subseteq \theta \). Then, clearly \(I\) is also applicable to \(q_2\) and its application creates \(q^{\prime }_2\) with \(S(u,v)\in q^{\prime }_2\), while for \(\sigma =\theta \) we have \(S(x,y)\in q^{\prime }_2{_\sigma }\) which implies that \(q^{\prime }_2{_\sigma }\subseteq q^{\prime }_1\). The cases where \(I\) is of the form \(S\sqsubseteq P^-\) or \(S^-\sqsubseteq P\) can be shown similarly.

  3. 3.

    If \(\alpha =P(x,y)\), \(y\) is unbound in \(q_1\), and \(I\) is of the form \(C\sqsubseteq \exists P\) with \(C\) a concept, then \(\beta =C(x)\) and \(\alpha _0=P(u,v)\) with \(\{u\mapsto x,v\mapsto y\}\subseteq \theta \). If \(v\) is also unbound in \(q_2\), then \(I\) is applicable to \(q_2\) and for \(q^{\prime }_2\) the result we will have \(A(u)\in q^{\prime }_2\); hence, for \(\sigma =\theta \) we will have \(A(x)\in q^{\prime }_2{_\sigma }\) and also \(q^{\prime }_2{_\sigma }\subseteq q^{\prime }_1\). If \(v\) is not unbound in \(q_2\) this implies that there is another atom \(\alpha _2\) in \(q_2\) that mentions \(v\). \(\alpha _2\) cannot be a concept atom of the form \(A(v)\) because due to \(q_2{_\theta } \subseteq q_1\) we would have \(A(v)_\theta =A(y)\in q_1\) and hence \(y\) would not be unbound in \(q_1\) as well (it would appear in \(A(y)\) and \(P(x,y)\)) leading to a contradiction; hence, \(\alpha _2\) must be a role atom. However, \(\alpha _2\) cannot be of the form \(P(v,z)\), for \(z\) an arbitrary variable since then, again \(q_2{_\theta } \subseteq q_1\) implies that \(P(v,z)_\theta =P(y,z_\theta )\in q_1\) and thus \(y\) would not be unbound in \(q_1\). The only possible case is that \(\alpha _2\) is of the form \(P(z,v)\) with \(z\mapsto x\in \theta \) (again if \(z\) is mapped to a different variable than \(x\), this would imply that \(q_1\) has two role atoms both having \(y\) as a second argument and \(y\) would not be unbound in \(q_1\)). Consequently, we have \(\alpha _0{_\theta }=P(u,v)_\theta =P(z,v)_\theta =a_2{_\theta }\), which implies that the two atoms unify. Now, let the substitution \(\sigma _1=\{z\mapsto u\}\). As mentioned before, \(\theta \) maps both \(z\) and \(u\) to \(x\); hence, for the defined \(\sigma _1\) we have \(q_2{_{\sigma _1\circ \theta }}=q_2{_\theta }\) and hence \(q_2{_{\sigma _1}}\) also subsumes \(q_1\). Consequently, all previous conditions apply to \(q_2{_{\sigma _1}}\)—that is, either \(q_2{_{\sigma _1}}\) subsumes \(q^{\prime }_1\), or \(I\) is applicable to \(q_2{_{\sigma _1}}\) and the result subsumes \(q^{\prime }_1\). If neither of these is the case then again an atom \(P(z^{\prime },v)\) with \(z^{\prime }\ne z\) must exist in \(q_2{_{\sigma _1}}\), such that it unifies with \(P(u,v)\) and a \(\sigma _2\) can be constructed such that \(q_2{_{\sigma _1\circ \sigma _2}}\) subsumes \(q_1\). Since, there is only a finite number of atoms in a query, at some point some \(\lambda =\{z_i\mapsto u\mid i\ge 1\}\) exists such that \(I\) is applicable to \(q_2{_\lambda }\) and the result subsumes \(q^{\prime }_1\). Note also that each \(\sigma _i\) is independent from the other and hence they can be applied in an arbitrary order over \(q_2\).

  4. 4.

    If \(\alpha =P(y,x)\), \(y\) is unbound in \(q_1\), and \(I\) is of the form \(C\sqsubseteq \exists P^-\), then \(\beta =C(x)\) and \(\alpha _0=P(v,u)\) with \(\{v\mapsto y, u\mapsto x\}\subseteq \theta \). Following a similar reasoning as in the previous case we can deduce that, either \(v\) is also unbound in \(q_2\) so \(I\) is applicable to \(q_2\) and the result subsumes \(q^{\prime }_1\), or it is not and in this case a list of atoms \(P(v,z_i)\) exists such that for \(\lambda =\{z_i\mapsto u\}\), \(I\) is applicable to \(q_2{_\lambda }\) and the result subsumes \(q^{\prime }_1\).\(\square \)

 

Lemma 2

Let \(q\) be a CQ that contains only one body atom and let \(\kappa \) be a substitution such that some axiom \(I\) is applicable to \(q_\kappa \) producing \(q^{\prime }\). Then \(I\) is also applicable to \(q\) and for \(q^{\prime \prime }\) the result we have \(q^{\prime \prime }_\kappa =q^{\prime }\) (modulo renaming of fresh variables).

Proof

If \(\kappa \) does not change any variables of \(q\) then the property follows trivially. If it does, then we show the property by performing a case analysis on the form of \(q\).

  1. 1.

    \(q\) is of the form \(\{{x}\mid {A(x)}\}\). Then, \(\kappa \) can be of the form \(\{x\mapsto y\}\) and \(I\) is of the form \(C\sqsubseteq A\), with \(C\) a concept. In this case, \(q^{\prime }=\{{y}\mid {C(y)}\}\), while \(I\) is also applicable to \(q\) and the result is \(q^{\prime \prime }=\{{x}\mid {C(x)}\}\). If \(C\) is an atomic concept then clearly \(q^{\prime \prime }_\kappa =q^{\prime }\). If \(C\) is of the form \(\exists R\) for \(R\) a role, then \(q^{\prime }=\{{y}\mid {R(y,z_1)}\}\) and \(q^{\prime \prime }=\{{x}\mid {R(x,z_2)}\}\), for \(z_1,z_2\) fresh variables and again (modulo renaming of fresh variables) \(q^{\prime \prime }_\kappa =q^{\prime }\).

  2. 2.

    \(q\) is of the form \(\{{x}\mid {R(x,y)}\}\). Then we have two cases depending on \(I\).

    1. (a)

      If \(I\) is of the form \(C\sqsubseteq \exists R\), then \(\kappa \) cannot map \(y\) to \(x\) (and vice versa), as this would make \(x\) (\(y\)) bound in \(q_\kappa \). Hence, \(\kappa \) (possibly) maps \(x\) and/or \(y\) to different variables. In any case \(q^{\prime }=\{x_\kappa \mid C(x_\kappa )\}\). Clearly, \(I\) is applicable to \(q\) and again as in case 1. we can deduce that \(q^{\prime \prime }_\kappa =q^{\prime }\).

    2. (b)

      If \(I\) is of the form \(P\sqsubseteq R\) and \(\kappa \) is as in the previous case, then the claim follows by a similar argument. However, \(\kappa \) can be of the form \(\{y\mapsto x\}\) (or \(\{x\mapsto y\}\)). Then, \(q^{\prime }=\{x\mid P(x,x)\}\) (or \(q^{\prime }=\{y\mid P(y,y)\}\)). Clearly, \(I\) is also applicable to \(q\) and the result is \(q^{\prime \prime }=\{x\mid P(x,y)\}\) for which \(q^{\prime \prime }_\kappa =\{x\mid P(x,x)\}\) (or \(q^{\prime \prime }_\kappa =\{y\mid P(y,y)\}\)). In either case \(q^{\prime \prime }_\kappa =q^{\prime }\).

  3. 3.

    \(q\) is of the form \( \{ x,y \mid R(x,y) \}\) and \(I\) is of the form \(P\sqsubseteq R\). This case is similar to case 2(b).

 

Theorem 1

Let \(q\) be a CQ, let \(\mathcal T \) be a TBox, let \(\alpha \) be an atom such that \(\mathsf{var }(\alpha )\cap \mathsf{var }(q)\ne \emptyset \) and let \(\mathcal G \) be a reformulation-closed rewriting graph for \(q,\mathcal T \). Let \(\mathcal G ^{\prime }\) be the graph returned by Algorithm 1 when applied to \(\mathcal G , \alpha \) and \(\mathcal T \); then \(\mathcal G ^{\prime }\) is a reformulation-closed rewriting graph for \(q\cup \{\alpha \},\mathcal T \).

Proof

First, note that \(\mathsf{ex\text{-}PerfectRef }\) extends \(\mathsf{PerfectRef }\), hence for a given query \(q\) and TBox \(\mathcal T \) it computes a rewriting graph for \(q,\mathcal T \). Moreover, since \(\mathsf{PerfectRef }\) applies exhaustively reformulation and reduction and does not prune computed queries, the output of the extended algorithm is reformulation-closed.

Let \(\mathcal G =\langle u , \mathcal H , m \rangle \) be the input of Algorithm 1 and let \(\mathcal G ^{\prime }=\langle u^{\prime } , \mathcal H ^{\prime }, m^{\prime } \rangle \) be its output. Moreover, for the following of the proof, let \(jv = \mathsf{var }(\alpha )\cap \mathsf{avar }(q)\), let \(\mathcal G _\alpha = \langle u_\alpha , \mathcal H _\alpha , m _\alpha \rangle \) be the rewriting graph computed by Algorithm 1 in line 1, and let \(u_i\) be a UCQ rewriting computed after \(i\) steps of the \(\mathsf{PerfectRef }\) algorithm when applied to \(q\cup \{\alpha \},\mathcal T \)—that is, after generating \(i\) queries by an application of the reformulation or the reduction step.

Correctness of the claim is strongly based of the following property:

(\(\star \)): For all \(i\ge 0\) and for all \(q_j\) in \(u_i\) a vertex \(q_{h}\) in \(\mathcal G \) and a vertex \(q_\alpha \) in \(\mathcal G _\alpha \) exist such that, for \(\kappa =m(q_{h}) \) and \(nv=\mathsf{avar } (q_h)\cup (\mathsf{avar } (q)\cap \mathsf{var }((q_\alpha )_\kappa ))\) we have \(\mathsf{canBeJoined } ({q_h},{\kappa },{jv}) =\mathsf{true }\), and one of the following conditions hold:

  1. 1.

    \(\{{nv}\mid {q_{h}\cup (q_{\alpha })_\kappa }\}\) subsumes \(q_j\), or

  2. 2.

    for some \(\sigma \in \mathsf{mergeCQs } ({(q_\alpha )_\kappa },{q_{h}}) \) some CQ \(q^{\prime }\) exists such that \(q_{h}\rightsquigarrow _\mathcal G q^{\prime }\) and \(\{{nv}\mid {q^{\prime }}\}_{\mu ^{\prime }}\), where \(\mu ^{\prime }=\mathsf{buildSubst } ({\sigma },{m(q^{\prime })}) \) subsumes \(q_j\).

Assume for now that Property \((\star )\) holds. We will show that \(\mathcal G ^{\prime }=\langle u^{\prime } , \mathcal H ^{\prime }, m^{\prime } \rangle \) is a reformulation-closed rewriting graph for \(q\cup \{\alpha \},\mathcal T \).

First, we show that \(u^{\prime }\) is a UCQ rewriting for \(q\cup \{\alpha \},\mathcal T \). Assume that when applied to \(q\cup \{\alpha \}\) and \(\mathcal T \) the \(\mathsf{PerfectRef }\) algorithm terminates after \(n\) steps and that \(u_n\) is the computed UCQ rewriting. But then, by Property \((\star )\), we know that upon termination of Algorithm 1, for each CQ \(q_n\in u_n\) either a CQ of the form \(\{{nv}\mid {q_h\cup (q_\alpha )_\kappa }\}\) or a CQ of the form \(\{{nv}\mid {q^{\prime }}\}_{\mu ^{\prime }}\) that subsumes \(q_n\) has been added to \(u^{\prime }\). Moreover, functions \(\mathsf{canBeJoined } \), \(\mathsf{buildSubst } \), and the condition \(\mathsf{dom }(\sigma )\subseteq \mathsf{var }(q^{\prime })\cup \mathsf{dom }(m(q^{\prime }))\) of the respective algorithms ensure that every CQ produced by our algorithm can also be produced by the \(\mathsf{PerfectRef }\) algorithm. Consequently, \(u^{\prime }\) is both sound and complete, thus it is indeed a UCQ rewriting for \(q\cup \{\alpha \},\mathcal T \).

Now we show that \(\mathcal G ^{\prime }\) is reformulation-closed. First, by definition of the mappings \(m^{\prime }(q^{\prime }_n)\) for each CQ added to \(\mathcal G ^{\prime }\) it follows that \(m^{\prime }\) satisfies the conditions in Definition 3. Furthermore, upon termination of the algorithm also the relation \(\mathcal H ^{\prime }\) satisfies the property of Definition 3. Moreover, again it can be easily seen that the algorithm will create and set as a top element of \(\mathcal G ^{\prime }\) the CQ \(q\cup \{\alpha \}\) with \(m^{\prime }(q\cup \{\alpha \})=\emptyset \), while for all top elements \(q_i\) in \(\mathcal G ^{\prime }\) we will also have \(m(q_i) =\emptyset \) as they inherit the mapping of \(q\) (we elaborate more on this in the proof of Property \((\star )\) later on). In addition, \(\mathcal H ^{\prime }\) is closed under restricted reduction; if for some \(q_h\in u, \kappa =m(q_h) \) and \(q_\alpha \in u_\alpha \) we have some \(\sigma \in \mathsf{mergeCQs } ({(q_\alpha )_\kappa },{q_h}) \), then the algorithm first adds \(q^+=\{{nv}\mid {q_h\cup (q_\alpha )_\kappa }\}\) to \(\mathcal G ^{\prime }\) (line 13) and then adds \(\langle q^+ , \{{nv}\mid {(q_h)}\}_\sigma \rangle \) to \(\mathcal G ^{\prime }\) (line 15). Then, it copies the sub-graph of \(\mathcal H \) below \(q_h\), but \(\mathcal H \) is also reformulation-closed. The only interesting case is if for some \(q^{\prime }\) such that \(q_h\rightsquigarrow _\mathcal G q^{\prime }\) we have \(z\mapsto x\in \sigma \) and \(z\mapsto x^{\prime }\in m(q^{\prime }) \). The latter implies that there exists \(q^{\prime \prime }\) such that \(\langle q^{\prime \prime } , q^{\prime } \rangle \in \mathcal H \) and \(R(x^{\prime },y),R(z,y)\) are atoms in \(q^{\prime \prime }\) while \(q^{\prime }=q^{\prime \prime }_{z\mapsto x^{\prime }}\), i.e., every occurence of \(z\) in \(q^{\prime \prime }\) has been mapped to \(x^{\prime }\). In the new graph \(\mathcal H ^{\prime }\), the algorithm will rather contain the query \(q^{\prime \prime }_\sigma \), i.e., \(q^{\prime \prime }_\sigma \) will now contain atoms \(R(x^{\prime },y),R(x,y)\) instead of \(R(x,y),R(z,y)\), i.e., occurences of \(z\) have been mapped to \(x\). Subsequently, a child of \(q^{\prime \prime }_\sigma \) needs to be created. For \(\mathcal H ^{\prime }\) to be reformulation-closed the child needs to be a query where now \(x\), rather than \(z\), is mapped to \(x^{\prime }\). This is accomplished by function \(\mathsf{buildSubst } \). More precisely, since \(z\mapsto x\in \sigma \) and \(z\mapsto x^{\prime }\in m(q^{\prime }) \), the function returns a mapping \(\mu \) that contains \(z\mapsto x\) and \(x\mapsto x^{\prime }\) which is applied to \(q^{\prime }\) creating the appropriate query. Consequently, \(\mathcal G ^{\prime }\) is reformulation-closed for \(q\cup \{\alpha \},\mathcal T \).

Now, we give the omitted proof of Property (\(\star \)).

To show this property we use induction over the number of steps \(i\) that algorithm \(\mathsf{ex\text{-}PerfectRef }\) has completed when applied to \(q\cup \{\alpha \},\mathcal T \). For a CQ \(q\) we will use the notation \(m _q\) to denote the substitution \(m(q) \).

Base Case (\(i=0\)): On the one hand, when algorithm \(\mathsf{ex\text{-}PerfectRef } \) is applied to \(q\cup \{\alpha \},\mathcal T \), at step \(0\) it initialises a UCQ \(u_0\) to contain the vertex \(q\cup \{\alpha \}\). On the other hand, in line 1 Algorithm 1 computes \(\mathcal G _\alpha \) for \(q_\alpha =\{ \mathsf{var }(\alpha )\cap \mathsf{var }(q) \mid {\alpha }\}\) and \(\mathcal T \) which uses \(\mathsf{ex\text{-}PerfectRef }\) and hence at least contains \(q_\alpha \) as a vertex. Moreover, since \(\mathcal G \) is reformulation-closed for \(q,\mathcal T \), then \(q\) appears as a top element in \(\mathcal G \) with \(m _q=\emptyset \). Hence, by construction of \(q_\alpha \) and \(jv \) we have \(\mathsf{canBeJoined } ({q},{m _{q}},{jv}) =\mathsf{true }\) and also \(\{{nv}\mid {q\cup (q_{\alpha })_{m _q}}\}\) is exactly \(q\cup \{\alpha \}\). Consequently, condition 1 is satisfied and hence also Property (\(\star \)) is satisfied at step \(i=0\).

Induction Step: Assume that Property (\(\star \)) holds at step \(i\) for each \(q_j\in u_i\). Subsequently, suppose that at step \(i+1\) the algorithm produces the UCQ \(u_{i+1}\) by applying a reformulation or a reduction step on some query \(q_j\) in \(u_i\) producing a query \(q_{i+1}\). Moreover, by induction hypothesis, vertices \(q_h\) in \(\mathcal G \) and \(q_\alpha \) in \(\mathcal G _\alpha \) exist such that Property (\(\star \)) is satisfied—that is, for \(\kappa =m _{q_h}\), we have \(\mathsf{canBeJoined } ({q_h},{\kappa },{jv}) =\mathsf{true }\) and either the query \(\{{nv}\mid {q_h\cup (q_{\alpha })_{\kappa }}\}\) (called \(q^{+}\) in the following) subsumes \(q_j\), or for some \(\sigma \in \mathsf{mergeCQs } ({(q_\alpha )_\kappa },{q_h}) \) and some \(q^{\prime }\) such that \(q_h\rightsquigarrow _\mathcal G q^{\prime }\), we have that \(\{{nv}\mid {q^{\prime }}\}_{\mu ^{\prime }}\) (called \(q^m\) in the following) subsumes \(q_j\). We now distinguish between two cases according to whether \(q_{i+1}\) was produced by a reformulation or a reduction step.

If a reduction step was applied to \(q_j\) to produce \(q_{i+1}\), then it is well-known by the properties of reduction that \(q_j\) subsumes \(q_{i+1}\). Hence, by the transitivity of the subsumes relation and the induction hypothesis \(q_{i+1}\) is also subsumed by either \(q^+\) or \(q^m\). Consequently, Property (\(\star \)) is still satisfied.

Otherwise, assume that a reformulation step was applied to \(q_j\) to produce \(q_{i+1}\). This implies that some axiom \(I\) is applied to some body atom of \(q_j\) producing \(q_{i+1}\). By induction hypothesis, either \(q^+\) or \(q^m\) subsume \(q_j\). If either of these queries subsumes \(q_{i+1}\), then Property (\(\star \)) is satisfied. If neither query subsumes \(q_{i+1}\), then by Lemma 1, either (i) \(I\) is applicable to them and the result subsumes \(q_{i+1}\) or (ii) for \(n\ge 1\) atoms of the form \(P(u,v),P(z_i,v)\) or \(P(v,u),P(v,z_i)\) exist in \(q^+\) or in \(q^m\) such that for \(\lambda =\{z_i\mapsto u\mid 1\le i\le n\}\), \(q^+_\lambda \) or \(q^m_\lambda \) subsumes \(q_j\), \(I\) is applicable to \(q^+_\lambda \) or \(q^m_{\lambda }\) and the result subsumes \(q_{i+1}\). We now examine separately the cases that \(q^+\) or \(q^m\) subsume \(q_j\).

  1. 1.

    Assume that \(q^+\) subsumes \(q_j\) and also that we have case (i) from above—that is, \(I\) is applicable to \(q^+=\{{nv}\mid {q_h\cup (q_\alpha )_{\kappa }}\}\). Since reformulation applies an axiom to a single body atom of a query at each time, this implies that \(I\) is either applicable to some body atom of \(q_h\) and the application creates a CQ of the form \(\{{nv}\mid {q^{\prime }_h\cup (q_{\alpha })_\kappa }\}\), or it is applicable to some body atom of \((q_{\alpha })_\kappa \) and the application creates a CQ of the form \(\{{nv}\mid {q_h\cup q^{\prime }_{\alpha }}\}\). (Note that reformulation does not change the distinguished variables of the query) In the former case, since \(I\) is applicable to \(q_h\) producing \(q^{\prime }_h\), \(q_h\) is a vertex in \(\mathcal G \) and \(\mathcal G \) is reformulation-closed, then \(\langle q_h,q^{\prime }_h\rangle \in \mathcal H \) with \(m _{q^{\prime }_h}=\kappa \) and \(\mathsf{avar } (q_h)=\mathsf{avar } (q^{\prime }_h)\). Moreover, \(\mathsf{canBeJoined } ({q^{\prime }_h},{m _{q^{\prime }_h}},{jv}) =\mathsf{true }\); this is because \(I\) is applicable to \(\{{nv}\mid {q_h\cup (q_\alpha )_\kappa }\}\), hence its application can only remove variables that do not appear in \((q_\alpha )_\kappa \). Consequently, condition 1 is satisfied and thus also Property (\(\star \)). Now we study the case when \(I\) is applicable to \((q_\alpha )_\kappa \): First, note that \(q_\alpha \) contains exactly one body atom; this follows straightforwardly by the fact that the query for which \(\mathcal G _\alpha \) is computed contains exactly one atom and by the fact that the \(\mathsf{PerfectRef }\) calculus always produces a new query that contains at most the same number of atoms as one from which it is produced. Hence, by Lemma 2, \(I\) is also applicable to \(q_\alpha \) and for the result \(q^{\prime \prime }_\alpha \) we have \((q^{\prime \prime }_\alpha )_\kappa =q^{\prime }_\alpha \). But since \(q_\alpha \in u_\alpha \) and \(\mathcal G _\alpha \) is reformulation-closed, then \(q^{\prime \prime }_\alpha \in u_\alpha \). Consequently, again condition 2. is satisfied thus also Property (\(\star \)). Assume now that we have case (ii) from above—that is, for \(n\ge 1\) there are atoms of the form \(P(u,v),P(z_i,v)\) or of the form \(P(u,v),P(z_i,v)\) in \(q^+\) such that for \(\lambda =\{z_i\mapsto u\mid 1\le i\le n\}\), \(I\) is applicable to \(q^+_\lambda =\{{nv_{\lambda }}\mid {(q_h){_\lambda }\cup (q_\alpha )_{\kappa \circ \lambda }}\}\) and the new CQ produced by applying \(I\) on \(q^+_\lambda \), called \(q_f\), subsumes \(q_{i+1}\). We will show that our algorithm can compute queries \(q^+_{\lambda }\) and \(q_f\). First note that the existence of atoms of the above form in \(q^+\) implies that several restricted reduction steps are applicable between body atoms \(P(z_i,v)\) and the atom \(P(u,v)\) in \(q^{\prime }_j\). Moreover, since \((q_\alpha )_\kappa \) contains a single atom, then these reductions are either applicable over two atoms from \(q_h\) or between an atom from \(q_h\) and the atom in \((q_\alpha )_\kappa \). In the former case, an application of one of these reductions would produce the CQ \((q_h)_{\lambda _i}\cup (q_\alpha )_{\kappa \circ \lambda _i}\). Since graph \(\mathcal G \) is reformulation-closed and by the form of these reductions, also \(\langle q_h , q^{\prime }_h \rangle \in \mathcal G \), with \(q^{\prime }_h=(q_h)_{\lambda _i}\) and \(m _{q^{\prime }_h}=\kappa \circ \lambda _i\); hence, \(\mathsf{canBeJoined } ({q^{\prime }_h},{m _{q^{\prime }_h}},{jv}) =\mathsf{true }\). If none of these reductions is performed between \((q_\alpha )_\kappa \) and \(q_h\), then for \(\lambda \) as defined before we will have \(q_h\rightsquigarrow _\mathcal{G } (q_h)_\lambda \) with \(m _{(q_h)_\lambda }=\kappa \circ \lambda \) and hence also \(\mathsf{canBeJoined } ({(q_h)_\lambda },{m _{(q_h)_\lambda }},{jv}) =\mathsf{true }\). Then, axiom \(I\) is applicable to \((q_h)_\lambda \) and since \(\mathcal G \) is reformulation-closed we also have \(\langle (q_h)_\lambda , q^{\prime \prime } \rangle \in \mathcal H \) and \(m _{q^{\prime \prime }}=m _{q_{h\lambda }}\). Finally, \(\{{nv^{\prime }}\mid {q^{\prime \prime }\cup (q_\alpha )_{m _{q^{\prime \prime }}}}\}\) for \(nv^{\prime }=\mathsf{avar } (q^{\prime \prime })\cup (\mathsf{avar } (q)\cap \mathsf{var }((q_\alpha )_{m _{q^{\prime \prime }}}))\) is \(q_f\) and it subsumes \(q_{i+1}\), hence Property (\(\star \)) is satisfied. Assume now that for some \(k\le n\), \((q_\alpha )_\kappa \) contains atom \(P(z_k,u)\) and one reduction step involves \((q_\alpha )_\kappa \) and atoms from \(q_h\). In this case since \((q_\alpha )_\kappa \) contains one atom then this reduction actually eliminates this atom from \(q^+\) and hence \(q^+_{\lambda _k}\) is of the form \(\{ \mathsf{avar }(q)_{\lambda _k} \mid {(q_h)_{\lambda _k}}\}\). Consequently, applying the rest of reductions the final CQ \(q^+_\lambda \) would be of the form \(\{ \mathsf{avar }(q)_{\lambda } \mid {(q_h)_{\lambda }}\}\) and \(q_f\) can be produced by applying \(I\) on this CQ. Now, since \(\mathcal G \) is reformulation-closed all reductions but \(\lambda _k\) have been applied on queries in \(\mathcal G \) starting from \(q_h\), hence a CQ \((q_h)_\nu \), with \(\nu =\lambda \setminus \lambda _k\) exists in \(\mathcal G \) such that \(q_h\rightsquigarrow _\mathcal G (q_h)_\nu \). Moreover, since \((q_h)_\nu \) does not contain the atom that is in \((q_\alpha )_\kappa I\) is applicable to it and hence \(\langle (q_h)_\nu , q^{\prime \prime } \rangle \in \mathcal H \). Then, by definition of function \(\mathsf{mergeCQs }\), we have that \(\mathsf{mergeCQs } ({(q_\alpha )_\nu },{(q_h){_\nu }}) \) contains \(\{\lambda _k\}\). Hence, the CQ \(q^{\prime \prime }_{\lambda _k}\) is actually \(q_f\) that subsumes \(q_{i+1}\) and Property (\(\star \)) is satisfied again.

  2. 2.

    Assume now that \(q^m\), i.e., \(\{{nv}\!\mid \!{q^{\prime }}\}_{\mu ^{\prime }}\) where \(q_h\!\rightsquigarrow _\mathcal G \! q^{\prime }\), \(\mu ^{\prime }\!=\mathsf{buildSubst } ({\sigma },{m(q^{\prime })}) \) and \(\sigma \!\in \!\mathsf{mergeCQs } ({(q_\alpha )_\kappa },{q_h}) \) subsumes \(q_j\). Again by Lemma 1 either \(I\) is applicable to \(q^m\) and the result (call it \(q_f\)) subsumes \(q_{i+1}\) or further restricted reduction steps are applicable to \(q^m\) producing a CQ over which \(I\) is applicable and the result (call it again \(q_f\)) subsumes \(q_{i+1}\). Since \(q^{\prime }_{m (q^{\prime })}=q^{\prime }\) and since \(\mu ^{\prime }\) is constructed from \(\sigma \) and \(m (q^{\prime })\), then \(\{{nv}\mid {q^{\prime }}\}_{\mu ^{\prime }}\) is like \(q^{\prime }\) but perhaps with some variable \(z\in \mathsf{var }(q^{\prime })\) renamed due to a mapping \(z\mapsto y\in \sigma \). Moreover, since \(\{{nv}\mid {q^{\prime }}\}_{\mu ^{\prime }}\) does not mention \(z\) (it has been renamed by \(\mu ^{\prime }\)), then neither of the previous steps (application of \(I\) or restricted reductions) does involve \(z\). Now, due to \(\mu ^{\prime }\) either \(q^{\prime }\) has fewer bound variables than \(\{{nv}\mid {q^{\prime }}\}_{\mu ^{\prime }}\) or \(\mu ^{\prime }\) frees a bound variable that is not free in \(q^{\prime }\) after which some axiom might be applicable. In the former case (\(q^{\prime }\) has fewer bound variables), at least the same sequence of reformulation or restricted reduction steps as to \(q^{m}\) are applicable to \(q^{\prime }\). Since these do not involve variable \(z\), after applying them, a CQ \(q^{\prime \prime }\) such that \(\{{nv}\mid {q^{\prime \prime }}\}_{\mu ^{\prime \prime }}=q_f\), where \(\mu ^{\prime \prime }=\mathsf{buildSubst } ({\sigma },{m(q^{\prime \prime })}) \) is generated, as \(\mu ^{\prime \prime }\) built from \(\sigma \) will perform the same variable renaming on \(z\). In addition, since \(\mathcal G \) is reformulation-closed \(q^{\prime \prime }\) is in \(\mathcal G \). Now consider the latter case, i.e., \(\mu ^{\prime }\) frees a bound variable in \(q^{\prime }\). This implies that \(\mu ^{\prime }\) induces a mapping \(\{z\mapsto x\}\) that frees some bound variable in \(q^{\prime }\). Consequently, a restricted reduction with unifier \(\sigma ^{\prime }=\{z\mapsto x\}\) is applicable and since \(\mathcal G \) is reformulation-closed we have that \(\langle q^{\prime } , q^{\prime }_{\sigma ^{\prime }} \rangle \in \mathcal H \). Subsequently, the same sequence of reformulation and restricted reduction steps as to \(q^m\) are applicable to \(q^{\prime }_{\sigma ^{\prime }}\). Hence again, we will have a query \(q^{\prime \prime }\) such that \(\{{nv}\mid {q^{\prime \prime }}\}_{\mu ^{\prime \prime }}=q_f\), where \(\mu ^{\prime \prime }=\mathsf{buildSubst } ({\sigma },{m(q^{\prime \prime })}) \) is produced in \(\mathcal G \). In any case Property (\(\star \)) is satisfied.\(\square \)

 

Rights and permissions

Reprints and Permissions

About this article

Cite this article

Venetis, T., Stoilos, G. & Stamou, G. Query Extensions and Incremental Query Rewriting for OWL 2 QL Ontologies. J Data Semant 3, 1–23 (2014). https://doi.org/10.1007/s13740-012-0017-6

Download citation

  • Received:

  • Revised:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s13740-012-0017-6

Keywords

  • Query rewriting
  • DL-Lite
  • Incremental query rewriting
  • Query extension