Computing Datalog Rewritings beyond Horn Ontologies
Bernardo Cuenca Grau, Boris Motik, Giorgos Stoilos, Ian Horrocks
aa r X i v : . [ c s . A I] A p r Computing Datalog Rewritings Beyond Horn Ontologies ∗ Bernardo Cuenca Grau and Boris Motik and Giorgos Stoilos and Ian Horrocks University of Oxford, UK NTU Athens, Greece
Abstract
Rewriting-based approaches for answering queriesover an OWL 2 DL ontology have so far been de-veloped mainly for Horn fragments of OWL 2 DL.In this paper, we study the possibilities of answer-ing queries over non-Horn ontologies using dat-alog rewritings. We prove that this is impossi-ble in general even for very simple ontology lan-guages, and even if P
TIME = NP. Furthermore, wepresent a resolution-based procedure for
SHI on-tologies that, in case it terminates, produces a data-log rewriting of the ontology. We also show that ourprocedure necessarily terminates on DL-Lite H , + bool ontologies—an extension of OWL 2 QL with tran-sitive roles and Boolean connectives. Answering conjunctive queries (CQs) over OWL 2 DL on-tologies is a computationally hard [Glimm et al. , 2008; Lutz,2008], but key problem in many applications. Thus, consid-erable effort has been devoted to the development of OWL 2DL fragments for which query answering is tractable in datacomplexity , which is measured in the size of the data only.Most languages obtained in this way are
Horn : ontologies insuch languages can always be translated into first-order Hornclauses. This includes the families of ‘lightweight’ languagessuch as DL-Lite [Calvanese et al. , 2007], EL [Baader et al. ,2005], and DLP [Grosof et al. , 2003] that underpin the QL,EL, and RL profiles of OWL 2, respectively, as well as moreexpressive languages, such as Horn- SHIQ [Hustadt et al. ,2005] and Horn-
SROIQ [Ortiz et al. , 2011].Query answering can sometimes be implemented via queryrewriting: a rewriting of a query Q w.r.t. an ontology T isanother query Q ′ that captures all information from T nec-essary to answer Q over an arbitrary data set. Unions ofconjunctive queries (UCQs) and datalog are common targetlanguages for query rewriting. They ensure tractability w.r.t.data complexity, while enabling the reuse of optimised datamanagement systems: UCQs can be answered using rela-tional databases [Calvanese et al. , 2007], and datalog queries ∗ This work was supported by the Royal Society, the EPSRCprojects Score!, Exoda, and MaSI , and the FP7 project OPTIQUE. can be answered using rule-based systems such as OWLim[Bishop et al. , 2011] and Oracle’s Semantic Data Store [Wu et al. , 2008]. Query rewriting algorithms have so far been de-veloped mainly for Horn fragments of OWL 2 DL, and theyhave been implemented in systems such as QuOnto [Accia-rri et al. , 2005], Rapid [Chortaras et al. , 2011], Presto [Rosatiand Almatelli, 2010], Quest [Rodriguez-Muro and Calvanese,2012], Clipper [Eiter et al. , 2012], Owlgres [Stocker andSmith, 2008], and Requiem [P´erez-Urbina et al. , 2010].Horn fragments of OWL 2 DL cannot capture disjunctiveknowledge , such as ‘every student is either an undergraduateor a graduate’. Such knowledge occurs in practice in ontolo-gies such as the NCI Thesaurus and the Foundational Modelof Anatomy, so these ontologies cannot be processed usingknown rewriting techniques; furthermore, no query answer-ing technique we are aware of is tractable w.r.t. data com-plexity when applied to such ontologies. These limitationscannot be easily overcome: query answering in even the basicnon-Horn language ELU is co-NP-hard w.r.t. data complex-ity [Krisnadhi and Lutz, 2007], and since answering datalogqueries is P
TIME -complete, it may not be possible to rewritean arbitrary
ELU ontology into datalog unless P
TIME = NP.Furthermore, Lutz and Wolter [2012] showed that tractabilityw.r.t. data complexity cannot be achieved for an arbitrary non-Horn ontology T with ‘real’ disjunctions: for each such T , aquery Q exists such that answering Q w.r.t. T is co-NP-hard.The result by Lutz and Wolter [2012], however, dependson an interaction between existentially quantified variablesin Q and disjunctions in T . Motivated by this observation,we consider the problem of computing datalog rewritings of ground queries (i.e., queries whose answers must map all thevariables in Q to constants) over non-Horn ontologies. Apartfrom allowing us to overcome the negative result by Lutz andWolter [2012], this also allows us to compute a rewriting of T that can be used to answer an arbitrary ground query. Suchqueries form the basis of SPARQL, which makes our resultspractically relevant. We summarise our results as follows.In Section 3, we revisit the limits of datalog rewritabilityfor a language as a whole and show that non-rewritabilityof ELU ontologies is independent from any complexity-theoretic assumptions. More precisely, we present an
ELU ontology T for which query answering cannot be decided bya family of monotone circuits of polynomial size, which con-tradicts the results by Afrati et al. [1995], who proved thatact entailment in a fixed datalog program can be decided us-ing monotone circuits of polynomial size. Thus, instead ofrelying on complexity arguments, we compare the lengths ofproofs in ELU and datalog and show that the proofs in
ELU may be considerably longer than the proofs in datalog.In Section 4, we present a three-step procedure that takesa
SHI -ontology T and attempts to rewrite T into a datalogprogram. First, we use a novel technique to rewrite T into aTBox Ω T without transitivity axioms while preserving entail-ment of all ground atoms; this is in contrast to the standardtechniques (see, e.g., [Hustadt et al. , 2007]), which preserveentailments only of unary facts and binary facts with roles nothaving transitive subroles. Second, we use the algorithm byHustadt et al. [2007] to rewrite Ω T into a disjunctive data-log program DD (Ω T ) . Third, we adapt the knowledge com-pilation technique by del Val [2005] and Selman and Kautz[1996] to transform DD (Ω T ) into a datalog program. The fi-nal step is not guaranteed to terminate in general; however, ifit terminates, the resulting program is a rewriting of T .In Section 4.4, we show that our procedure always termi-nates if T is a DL-Lite H , + bool -ontology—a practically-relevantlanguage that extends OWL 2 QL with transitive roles andBoolean connectives. Artale et al. [2009] proved that the datacomplexity of concept queries in this language is tractable(i.e., NL OG S PACE -complete). We extend this result to allground queries and thus obtain a goal-oriented rewriting al-gorithm that may be suitable for practical use.Our technique, as well as most rewriting techniques knownin the literature, is based on a sound inference system and thusproduces only strong rewritings —that is, rewritings entailedby the original ontology. In Section 5 we show that non-Hornontologies exist that can be rewritten into datalog, but thathave no strong rewritings. This highlights the limits of tech-niques based on sound inferences. It is also surprising sinceall known rewriting techniques for Horn fragments of OWL2 DL known to us produce only strong rewritings.The proofs of all of our technical results are given in ap-pendices A–F.
We consider first-order logic without equality and functionsymbols. Variables, terms, (ground) atoms, literals, formu-lae, sentences, interpretations I = (∆ I , · I ) , models, and en-tailment ( | = ) are defined as usual. We call a finite set of facts(i.e., ground atoms) an ABox . We write ϕ ( ~x ) to stress that afirst-order formula ϕ has free variables ~x = x , . . . , x n . Resolution Theorem Proving
We use the standard notions of (Horn) clauses, substitutions(i.e., mappings of variables to terms), and most general uni-fiers (MGUs). We often identify a clause with the set of itsliterals.
Positive factoring (PF) and binary resolution (BR)are as follows, where σ is the MGU of atoms A and B :PF: C ∨ A ∨ BCσ ∨ Aσ BR: C ∨ A D ∨ ¬ B ( C ∨ D ) σ A clause C is a tautology if it contains literals A and ¬ A .A clause C subsumes a clause D if a substitution σ existssuch that each literal in Cσ occurs in D . Furthermore, C θ -subsumes D if C subsumes D and C has no more literalsthan D . Finally, C is redundant in a set of clauses S if C is atautology or if C is θ -subsumed by another clause in S . Datalog and Disjunctive Datalog A disjunctive rule r is a function-free first-order sentence ofthe form ∀ ~x ∀ ~z. [ ϕ ( ~x, ~z ) → ψ ( ~x )] , where tuples of variables ~x and ~z are disjoint, ϕ ( ~x, ~z ) is a conjunction of atoms, and ψ ( ~x ) is a disjunction of atoms. Formula ϕ is the body of r ,and formula ψ is the head of r . For brevity, we often omitthe quantifiers in a rule. A datalog rule is a disjunctive rulewhere ψ ( ~x ) is a single atom. A (disjunctive) datalog program P is a finite set of (disjunctive) datalog rules. Rules obviouslycorrespond to clauses, so we sometimes abuse our definitionsand use these two notions as synonyms. The evaluation of P over an ABox A is the set P ( A ) of facts entailed by P ∪ A . Ontologies and Description Logics
A DL signature is a disjoint union of sets of atomic concepts , atomic roles , and individuals . A role is an atomic role oran inverse role R − for R an atomic role; furthermore, let inv ( R ) = R − and inv ( R − ) = R . A concept is an expressionof the form ⊤ , ⊥ , A , ¬ C , C ⊓ C , C ⊔ C , ∃ R.C , ∀ R.C ,or ∃ R. self , where A is an atomic concept, C ( i ) are con-cepts, and R is a role. Concepts ∃ R. self correspond to atoms R ( x, x ) and are typically not included in SHI ; however, weuse this minor extension in Section 4.1. A
SHI -TBox T ,often called an ontology , is a finite set of axioms of the form R ⊑ R ( role inclusion axioms or RIAs), Tra ( R ) ( transi-tivity axioms ), and C ⊑ C ( general concept inclusions orGCIs), where R ( i ) are roles and C ( i ) are concepts. Axiom C ≡ C abbreviates C ⊑ C and C ⊑ C . Relation ⊑ ∗T isthe smallest reflexively–transitively closed relation such that R ⊑ ∗T S and inv ( R ) ⊑ ∗T inv ( S ) for each R ⊑ S ∈ T . A role R is transitive in T if Tra ( R ) ∈ T or Tra ( inv ( R )) ∈ T . Sat-isfaction of a SHI -TBox T in an interpretation I = (∆ I , · I ) ,written I | = T , is defined as usual [Baader et al. , 2003].An ALCHI -TBox is a
SHI -TBox with no transitivity ax-ioms. An
ELU -TBox is an
ALCHI -TBox with no role in-clusion axioms, inverse roles, concepts ∃ R. self , or symbols ⊥ , ∀ , and ¬ . A DL-Lite H , + bool -TBox is a SHI -TBox that doesnot contain concepts of the form ∀ R.C , and where C = ⊤ for each concept of the form ∃ R.C . The notion of acyclic
TBoxes is defined as usual [Baader et al. , 2003].A
SHI -TBox T is normalised if ∀ does not occur in T ,and ∃ occurs in T only in axioms of the form ∃ R.C ⊑ A , ∃ R. self ⊑ A , A ⊑ ∃ R.C , or A ⊑ ∃ R. self . Each SHI -TBox T can be transformed in polynomial time into a normalised SHI -TBox that is a model-conservative extension of T . Queries and Datalog Rewritings A ground query (or just a query ) Q ( ~x ) is a conjunction offunction-free atoms. A substitution σ mapping ~x to constantsis an answer to Q ( ~x ) w.r.t. a set F of first-order sentences andan ABox A if F ∪ A | = Q ( ~x ) σ ; furthermore, cert ( Q, F , A ) is the set of all answers to Q ( ~x ) w.r.t. F and A .Let Q be a query. A datalog program P is a Q -rewriting ofa finite set of sentences F if cert ( Q, F , A ) = cert ( Q, P , A ) for each ABox A . The program P is a rewriting of F if P s a Q -rewriting of F for each query Q . Such rewritings are strong if, in addition, we also have F | = P . Datalog programs can be evaluated over an ABox A in poly-nomial time in the size of A ; hence, a co-NP-hard propertyof A cannot be decided by evaluating a fixed datalog pro-gram over A unless P TIME = NP. Krisnadhi and Lutz [2007]showed that answering ground queries is co-NP-hard in datacomplexity even for acyclic TBoxes expressed in
ELU —thesimplest non-Horn extension of the basic description logic EL . Thus, under standard complexity-theoretic assumptions,an acyclic ELU -TBox and a ground query Q exist for whichthere is no Q -rewriting of T . In this section, we show thatthis holds even if P TIME = NP.
Theorem 1.
An acyclic
ELU -TBox T and a ground CQ Q exist such that T is not Q -rewritable. Our proof uses several notions from circuit complexity[Wegener, 1987], and results of this flavour compare the sizesof proofs in different formalisms; thus, our result essentiallysays that proofs in
ELU can be significantly longer thanproofs in datalog. Let < be the ordering on Boolean valuesdefined by f < t ; then, a Boolean function f with n inputsis monotone if f ( x , . . . , x n ) ≤ f ( y , . . . , y n ) holds for all n -tuples of Boolean values x , . . . , x n and y , . . . , y n suchthat x i ≤ y i for each ≤ i ≤ n . A decision problem can beseen as a family of Boolean functions { f n } , where f n decidesmembership of each n -bit input. If each function f n is mono-tone, then f n can be realised by a monotone Boolean circuit C n (i.e., a circuit with n input gates where all internal gatesare AND- or OR-gates with unrestricted fan-in); the size of C n is the number of its edges. The family of circuits { C n } corresponding to { f n } has polynomial size if a polynomial p ( x ) exists such that the size of each C n is bounded by p ( n ) .We recall how non-3-colorability of an undirected graph G with s vertices corresponds to monotone Boolean functions.The maximum number of edges in G is m ( s ) = s ( s − / ,so graph G is encoded as a string ~x of m ( s ) bits, where bit x i,j , ≤ i < j ≤ s , is t if and only if G contains an edge be-tween vertices i and j . The non-3-colorability problem canthen be seen as a family of Boolean functions { f m ( s ) } , wherefunction f m ( s ) handles all graphs with s vertices and it eval-uates to t on an input ~x iff the graph corresponding to ~x isnon-3-colourable. Functions f n such that n = m ( s ) for all s are irrelevant since no graph is encoded using that many bits.We prove our claim using a result by Afrati et al. [1995]: ifa decision problem cannot be solved using a family of mono-tone circuits of polynomial size, then the problem also cannotbe solved by evaluating a fixed datalog program, regardless ofthe problem’s complexity. We restate the result as follows. Theorem 2. [Adapted from Afrati et al. P be a fixed datalog program, and let α be a fixedfact. Then, for an ABox A , deciding P ∪ A | = α can besolved by monotone circuits of polynomial size.2. The non-3-colorability problem cannot be solved bymonotone circuits of polynomial size. Table 1: Example TBox T ex γ Student ⊑ GrSt ⊔ UnGrSt γ Course ⊑ GrCo ⊔ UnGrCo γ PhDSt ⊑ ∃ takes . PhDCo γ PhDCo ⊑ GrCo γ ∃ takes . GrCo ⊑ GrSt γ UnGrSt ⊓ ∃ takes . GrCo ⊑ ⊥
To prove Theorem 1, we present a TBox T and a groundCQ Q that decide non-3-colorability of a graph encoded as anABox. Next, we present a family of monotone Boolean func-tions { g n ( u ) } that decide answering Q w.r.t. T an arbitraryABox A . Next, we show that a monotone circuit for arbi-trary f m ( s ) can be obtained by a size-preserving transforma-tion from a circuit for some g n ( u ) ; thus, by Item 2 of Theorem2, answering Q w.r.t. T cannot be solved using monotone cir-cuits of polynomial size. Finally, we show that existence of arewriting for Q and T contradicts Item 1 of Theorem 2. Theorem 1 is rather discouraging since it applies to one of thesimplest non-Horn languages. The theorem’s proof, however,relies on a specific TBox T that encodes a hard problem (i.e.,non-3-colorability) that is not solvable by monotone circuitsof polynomial size. One can expect that non-Horn TBoxesused in practice do not encode such hard problems, and so itmight be possible to rewrite such TBoxes into datalog.We illustrate this intuition using the TBox T ex shown inTable 1. Axioms γ – γ correspond to datalog rules, whereasaxioms γ – γ represent disjunctive and existentially quanti-fied knowledge and thus do not correspond to datalog rules.We will show that T ex can, in fact, be rewritten into data-log using a generic three-step method that takes a normalised SHI -TBox T and proceeds as follows. S1 Eliminate the transitivity axioms from T by transform-ing T into an ALCHI -TBox Ω T and a set of data-log rules Ξ T such that facts entailed by T ∪ A and Ω T ∪ Ξ T ( A ) coincide for each ABox A . This step ex-tends the known technique to make it complete for factswith roles that have transitive subroles in T . S2 Apply the algorithm by Hustadt et al. [2007] to trans-form Ω T into a disjunctive datalog program DD (Ω T ) . S3 Transform DD (Ω T ) into a set of datalog rules P H usinga variant of the knowledge compilation techniques bySelman and Kautz [1996] and del Val [2005].Step S3 may not terminate for an arbitrary SHI -TBox T ;however, if it terminates (i.e., if P H is finite), then P H ∪ Ξ T is a rewriting of T . Furthermore, in Section 4.4 we show thatstep S3 always terminates if T is a DL-Lite H , + bool -TBox. Wethus obtain what is, to the best of our knowledge, the firstgoal-oriented rewriting algorithm for a practically-relevantnon-Horn fragment of OWL 2 DL. We first recapitulate the standard technique for eliminatingtransitivity axioms from
SHI -TBoxes. efinition 3.
Let T be a normalised SHI -TBox, and let Θ T be obtained from T by removing all transitivity axioms. If T is a DL-Lite H , + bool -TBox, then let Υ T = Θ T ; otherwise, let Υ T be the extension of Θ T with axioms ∃ R.A ⊑ C B,R ∃ R.C
B,R ⊑ C B,R C B,R ⊑ B for each axiom ∃ S.A ⊑ B ∈ T and each transitive role R in T such that R ⊑ ∗T S , where C B,R is a fresh atomic conceptunique for B and R . This encoding preserves entailment of all facts of the form C ( c ) and U ( c, d ) if U has no transitive subroles: this wasproved by Artale et al. [2009] for DL-Lite H , + bool , and by Siman-cik [2012] for SHI . Example 4, however, shows that theencoding is incomplete if U has transitive subroles. Example 4.
Let T be the TBox below, and let A = { A ( a ) } . A ⊑ ∃ S.B S ⊑ R S ⊑ R − Tra ( R ) Then, Υ T = T \ {
Tra ( R ) } , and one can easily verify that T ∪ A | = R ( a, a ) , but Υ T ∪ A 6| = R ( a, a ) . Note, however,that the missing inference can be recovered by extending Υ T with the axiom A ⊑ ∃ R. self , which is a consequence of T . The intuitions from Example 4 are formalised in Defini-tion 5. Roughly speaking, we transform the transitivity androle inclusion axioms in T into a datalog program Ξ T , whichwe apply to A ‘first’—that is, we compute Ξ T ( A ) indepen-dently from any GCIs. To recoup the remaining consequencesof the form R ( a, a ) , we extend Υ T with sufficiently many ax-ioms of the form A ⊑ ∃ R. self that are entailed by T ; this ispossible since we assume that T is normalised. Definition 5.
Let T be a normalised SHI -TBox. Then, Ω T is the TBox obtained by extending Υ T with an axiom A ⊑ ∃ R. self for each atomic concept A and each atomic role R such that R is transitive in T , and A ⊑ ∃ S.B ∈ T for someconcept B and role S with S ⊑ ∗T R and S ⊑ ∗T R − . Further-more, Ξ T is the set of datalog rules corresponding to the roleinclusion and transitivity axioms in T . Theorem 6.
Let T be a normalised SHI -TBox, let A be anABox, and let α be a fact. Then, T ∪ A | = α if and only if Ω T ∪ Ξ T ( A ) | = α . Note that, if T is normalised, so is Ω T . Furthermore, toensure decidability, roles involving transitive subroles are notallowed occur in T in number restrictions, and so Theorem 6holds even if T is a SHOIQ -TBox.
Step S2 of our rewriting algorithm uses the technique by Hus-tadt et al. [2007] for transforming an ALCHI -TBox T into adisjunctive datalog program DD ( T ) such that, for each ABox A , the facts entailed by T ∪ A and DD ( T ) ∪ A coincide.By eliminating the existential quantifiers in T , one thus re-duces a reasoning problem in T ∪ A to a reasoning prob-lem in DD ( T ) ∪ A . The following definition summarises theproperties of the programs produced by the transformation. Definition 7.
A disjunctive datalog program P is nearly-monadic if its rules can be partitioned into two disjoint sets, P m and P r , such that Table 2: Example Disjunctive Program DD ( T ex ) C ¬ Student ( x ) ∨ GrSt ( x ) ∨ UnGrSt ( x ) C ¬ Course ( x ) ∨ GrCo ( x ) ∨ UnGrCo ( x ) C ¬ PhDSt ( x ) ∨ GrSt ( x ) C ¬ PhDCo ( x ) ∨ GrCo ( x ) C ¬ takes ( x, y ) ∨ ¬ GrCo ( y ) ∨ GrSt ( x ) C ¬ UnGrSt ( x ) ∨ ¬ takes ( x, y ) ∨ ¬ GrCo ( y )
1. each rule r ∈ P m mentions only unary and binary pred-icates and each atom in the head of r is of the form A ( z ) or R ( z, z ) for some variable z , and2. each rule r ∈ P r is of the form R ( x, y ) → S ( x, y ) or R ( x, y ) → S ( y, x ) .A disjunctive rule r is simple if there exists a variable x such that each atom in the body of r is of the form A i ( x ) , R i ( x, x ) , S i ( x, y i ) , or T i ( y i , x ) , each atom in the head of r is of the form U i ( x, x ) or B i ( x ) , and each variable y i occursin r at most once. Furthermore, a nearly-monadic program P is simple if each rule in P m is simple. Theorem 8 follows mainly from the results by Hustadt etal. [2007]; we just argue that concepts ∃ R. self do not affectthe algorithm, and that DD ( T ) satisfies property 1. Theorem 8.
For T a normalised ALCHI -TBox, DD ( T ) sat-isfies the following:1. program DD ( T ) is nearly-monadic; furthermore, if T isa DL-Lite H , + bool -TBox, then DD ( T ) is also simple;2. T | = DD ( T ) ; and3. cert ( Q, T , A ) = cert ( Q, DD ( T ) , A ) for each ABox A and each ground query Q . Example 9.
When applied to the TBox T ex in Table 1, thisalgorithm produces the disjunctive program DD ( T ex ) shown(as clauses) in Table 2. In particular, axiom γ is eliminatedsince it contains an existential quantifier, but its effects arecompensated by clause C . Clauses C – C and C – C areobtained from axioms γ – γ and γ – γ , respectively. Step S3 of our rewriting algorithm attempts to transform thedisjunctive program obtained in Step S2 into a datalog pro-gram such that, for each ABox A , the two programs entail thesame facts. This is achieved using known knowledge compi-lation techniques, which we survey next. Resolution-Based Knowledge Compilation
In their seminal paper, Selman and Kautz [1996] proposed analgorithm for compiling a set of propositional clauses S intoa set of Horn clauses S H such that the Horn consequencesof S and S H coincide. Subsequently, del Val [2005] gener-alised this algorithm to the case when S contains first-orderclauses, but without any termination guarantees; Procedure 1paraphrases this algorithm. The algorithm applies to S bi-nary resolution and positive factoring from resolution theo-rem proving, and it keeps only the consequences that are notredundant according to Definition 10. Unlike standard reso-lution, the algorithm maintains two sets S H and S H of Horn rocedure 1 Compile - Horn
Input: S : set of clauses Output: S H : set of Horn clauses1: S H := { C ∈ S | C is a Horn clause and not a tautology } S H := { C ∈ S | C is a non-Horn clause and not a tautology } repeat
4: Compute all relevant consequences of hS H , S H i for each relevant consequence C of hS H , S H i do
6: Delete from S H and S H all clauses θ -subsumed by C if C is Horn then S H := S H ∪ { C } else S H := S H ∪ { C } until there is no relevant consequence of hS H , S H i return S H and non-Horn clauses, respectively; furthermore, the algo-rithm never resolves two Horn clauses. Definition 10.
Let S H and S H be sets of Horn and non-Hornclauses, respectively. A clause C is a relevant consequence of hS H , S H i if • C is not redundant in S H ∪ S H , and • C is a factor of a clause C ∈ S H , or a resolvent ofclauses C ∈ S H and C ∈ S H ∪ S H . Theorem 11 recapitulates the algorithm’s properties. It es-sentially shows that, even if the algorithm never terminates,each Horn consequence of S will at some point during algo-rithm’s execution become entailed by the set of Horn clauses S H computed by the algorithm. The theorem was proved byshowing that each resolution proof of a consequence of S canbe transformed to ‘postpone’ all resolution steps between twoHorn clauses until the end; thus, one can ‘precompute’ set S H of all consequences of S derivable using a non-Horn clause. Theorem 11. ([del Val, 2005]) Let S be a set of clauses, andlet C be a Horn clause such that S | = C , and assume thatProcedure 1 is applied to S . Then, after some finite numberof iterations of the loop in lines 3–9, we have S H | = C . ABox-Independent Compilation
Compiling knowledge into Horn clauses and computing data-log rewritings are similar in spirit: both transform one theoryinto another while ensuring that the two theories are indistin-guishable w.r.t. a certain class of queries. There is, however,an important difference: given a disjunctive program P and afixed ABox A , one could apply Procedure 1 to S = P ∪ A toobtain a datalog program S H , but such S H would not neces-sarily be independent from the specific ABox A . In contrast,a rewriting of P is a datalog program P H that can be freelycombined with an arbitrary ABox A . We next show that aprogram P H satisfying the latter requirement can be obtainedby applying Procedure 1 to P only.Towards this goal, we generalise Theorem 11 and showthat, when applied to an arbitrary set of first-order clauses N ,Procedure 1 computes a set of Horn clauses N H such that theHorn consequences of N ∪ A and N H ∪ A coincide for anarbitrary ABox A . Intuitively, this shows that, when Proce-dure 1 is applied to S = N ∪ A , all inferences involving factsin A can be ‘moved’ to end of derivations. Theorem 12.
Let N be a set of clauses, let A be an ABox, let C be a Horn clause such that N ∪ A | = C , and assume thatProcedure 1 is applied to N . Then, after some finite numberof iterations of the loop in lines 3–9, we have N H ∪ A | = C . Rewriting Nearly-Monadic Disjunctive Programs
The final obstacle to obtaining a datalog rewriting of a
SHI -TBox T is due to Theorem 6: the rules in Ξ T should be ap-plied ‘before’ Ω T . While this allows us to transform Ω T into P = DD (Ω T ) and P H without taking Ξ T into account, thisalso means that Theorems 6, 8, and 12 only imply that thefacts entailed by T ∪ A and P H ∪ Ξ T ( A ) coincide. To ob-tain a ‘true’ rewriting, we show in Lemma 13 that program P H is nearly-monadic. We use this observation in Theorem14 to show that each binary fact obtained by applying P H to Ξ T ( A ) is of the form R ( c, c ) , and so it cannot ‘fire’ the rulesin Ξ T ; hence, P H ∪ Ξ T is a rewriting of T . Lemma 13.
Let P be a nearly-monadic program, and as-sume that Procedure 1 terminates when applied to P and re-turns P H . Then, P H is a nearly-monadic datalog program. Theorem 14.
Let P = DD (Ω T ) for T an SHI -TBox. If,when applied to P , Procedure 1 terminates and returns P H ,then P H ∪ Ξ T is a rewriting of T . Please note that our algorithm (just like all rewriting algo-rithms we are aware of) computes rewritings using a soundinference system and thus always produces strong rewritings.
Example 15.
When applied to the program P = DD ( T ex ) from Table 2, Procedure 1 resolves C and C to derive (1) , C and C to derive (2) , and C and C to derive (3) . ¬ takes ( x, y ) ∨ ¬ Course ( y ) ∨ GrSt ( x ) ∨ UnGrCo ( y ) (1) ¬ takes ( x, y ) ∨ ¬ UnGrSt ( x ) ∨ ¬ Course ( y ) ∨ UnGrCo ( y ) (2) ¬ takes ( x, y ) ∨ ¬ Student ( x ) ∨ ¬ GrCo ( y ) ∨ GrSt ( x ) (3) Resolving (2) and C , and (3) and C produces redundantclauses, after which the procedure terminates and returns theset P H consisting of clauses C – C , (2) , and (3) . By Theorem14, P H is a strong rewriting of T ex . Procedure 1 is not a semi-decision procedure for either strongnon-rewritability (cf. Example 16) or strong rewritability (cf.Example 17) of nearly-monadic programs.
Example 16.
Let P be defined as follows. G ( x ) ∨ B ( x ) (4) B ( x ) ∨ ¬ E ( x , x ) ∨ ¬ G ( x ) (5) G ( x ) ∨ ¬ E ( x , x ) ∨ ¬ B ( x ) (6) Clauses (5) and (6) are mutually recursive, but they are alsoHorn, so Procedure 1 never resolves them directly.Clauses (5) and (6) , however, can interact through clause (4) . Resolving (4) and (5) on ¬ G ( x ) produces (7) ; and re-solving (6) and (7) on B ( x ) produces (8) . By further resolv-ing (8) alternatively with (5) and (6) , we obtain (9) for eacheven n . By resolving (6) and (9) on B ( x ) , we obtain (10) .Finally, by factoring (10) , we obtain (11) for each even n . B ( x ) ∨ ¬ E ( x , x ) ∨ B ( x ) (7) ( x ) ∨ ¬ E ( x , x ) ∨ ¬ E ( x , x ) ∨ B ( x ) (8) G ( x n ) ∨ [ n _ i =1 ¬ E ( x i , x i − )] ∨ B ( x ) (9) G ( x n ) ∨ [ n _ i =1 ¬ E ( x i , x i − )] ∨ G ( x ′ ) ∨ ¬ E ( x ′ , x ) (10) G ( x n ) ∨ ¬ E ( x n , x ) ∨ [ n _ i =1 ¬ E ( x i , x i − )] (11) Procedure 1 thus derives on P an infinite set of Horn clauses,and Theorem 22 shows that no strong rewriting of P exists. Example 17.
Let P be defined as follows. B ( x ) ∨ B ( x ) ∨ ¬ A ( x ) (12) A ( x ) ∨ ¬ E ( x , x ) ∨ ¬ B ( x ) (13) A ( x ) ∨ ¬ E ( x , x ) ∨ ¬ B ( x ) (14) When applied to P , Procedure 1 will eventually compute in-finitely many clauses C n of the following form: C n = A ( x n ) ∨ [ n _ i =1 ¬ E ( x i , x i − )] ∨ ¬ A ( x ) However, for each n > , clause C n is a logical consequenceof clause C , so the program consisting of clauses (12) , (13) ,and C is a strong rewriting of P . Example 18 demonstrates another problem that can ariseeven if P is nearly-monadic and simple. Example 18.
Let P be the following program: ¬ R ( x, y ) ∨ A ( x ) (15) ¬ R ( x, y ) ∨ B ( x ) (16) ¬ A ( x ) ∨ ¬ B ( x ) ∨ C ( x ) ∨ D ( x ) (17) Now resolving (15) and (17) produces (18) ; and resolving (16) and (18) produces (19) . ¬ R ( x, y ) ∨ ¬ B ( x ) ∨ C ( x ) ∨ D ( x ) (18) ¬ R ( x, y ) ∨ ¬ R ( x, y ) ∨ C ( x ) ∨ D ( x ) (19) Clause (19) contains more variables than clauses (15) and (16) , which makes bounding the clause size difficult.
Notwithstanding Example 18, we believe one can provethat Procedure 1 terminates if P is nearly-monadic and sim-ple. However, apart from making the termination proof moreinvolved, deriving clauses such as (19) is clearly inefficient.We therefore extend Procedure 1 with the condensation sim-plification rule, which eliminates redundant literals in clausessuch as (19). A condensation of a clause C is a clause D withthe least number of literals such that D ⊆ C and C subsumes D . A condensation of C is unique up to variable renaming,so we usually speak of the condensation of C . We next showthat Theorems 11 and 12 hold even with condensation. Lemma 19.
Theorems 11 and 12 hold if Procedure 1 is mod-ified so that, after line 5, C is replaced with its condensation. One can prove that all relevant consequences of nearly-monadic and simple clauses are also nearly-monadic and sim-ple, so by using condensation to remove redundant literals,we obtain Lemma 20, which clearly implies Theorem 21.
Lemma 20.
If used with condensation, Procedure 1 termi-nates when applied to a simple nearly-monadic program P . Theorem 21.
Let P = DD (Ω T ) for T a DL-Lite H , + bool -TBox.Procedure 1 with condensation terminates when applied to P and returns P H ; furthermore, P H ∪ Ξ T is a rewriting of T . We thus obtain a tractable (w.r.t. data complexity) proce-dure for answering queries over DL-Lite H , + bool -TBoxes. Fur-thermore, given a ground query Q and a nearly-monadic andsimple program P H obtained by Theorem 21, it should bepossible to match the NL OG S PACE lower complexity boundby Artale et al. [2009] as follows. First, one should ap-ply backward chaining to Q and P H to compute a UCQ Q ′ such that cert ( Q, P H , Ξ T ( A )) = cert ( Q ′ , ∅ , Ξ T ( A )) ; sinceall nearly-monadic rules in P H are simple, it should be possi-ble to show that such ‘unfolding’ always terminates. Second,one should transform Ξ T into an equivalent piecewise-lineardatalog program Ξ ′T . Although these transformations shouldbe relatively straightforward, a formal proof would requireadditional machinery and is thus left for future work. We next show that strong rewritings may not exist for rathersimple non-Horn
ELU -TBoxes that are rewritable in general.This is interesting because it shows that an algorithm capableof rewriting a larger class of TBoxes necessarily must departfrom the common approaches based on sound inferences.
Theorem 22.
The
ELU -TBox T corresponding to the pro-gram P from Example 16 and the ground CQ Q = G ( x ) are Q -rewritable, but not strongly Q -rewritable. The proof of Theorem 22 proceeds as follows. First, weshow that, for each ABox A encoding a directed graph, wehave cert ( Q, T , A ) = ∅ iff the graph contains a pair of ver-tices reachable by both an even and an odd number of edges.Second, we show that latter property can be decided using adatalog program that uses new relations not occurring in T .Third, we construct an infinite set of rules R entailed by eachstrong rewriting of T . Fourth, we show that R ′ = R holdsfor each finite datalog program R ′ such that T | = R ′ .Since our procedure from Section 4 produces only strongrewritings, it cannot terminate on a TBox that has no strongrewritings. This is illustrated in Example 16, which showsthat Procedure 1 does not terminate when applied to (theclausification of) the TBox from Theorem 22. Our work opens many possibilities for future research. Onthe theoretical side, we will investigate whether one can de-cide existence of a strong rewriting for a given
SHI -TBox T , and to modify Procedure 1 so that termination is guaran-teed. Bienvenue et al. [2013] recently showed that rewritabil-ity of unary ground queries over ALC -TBoxes is decidable;however, their result does not consider strong rewritability orbinary ground queries. On the practical side, we will inves-tigate whether Procedure 1 can be modified to use orderedresolution instead of unrestricted resolution. We will also im-plement our technique and evaluate its applicability. eferences []Acciarri et al. , 2005 Andrea Acciarri, Diego Calvanese,Giuseppe De Giacomo, Domenico Lembo, MaurizioLenzerini, Mattia Palmieri, and Riccardo Rosati. Quonto:Querying ontologies. In
AAAI , pages 1670–1671, 2005.[]Afrati et al. , 1995 Foto Afrati, Stavros S Cosmadakis, andMihalis Yannakakis. On Datalog vs. polynomial time.
J.of Computer and System Sciences , 51(2), 1995.[]Artale et al. , 2009 Alessandro Artale, Diego Calvanese,Roman Kontchakov, and Michael Zakharyaschev. TheDL-Lite family and relations.
Journal of Artificial Intel-ligence Research , 36:1–69, 2009.[]Baader et al. , 2003 Franz Baader, Diego Calvanese, Deb-orah L. McGuinness, Daniele Nardi, and Peter F. Patel-Schneider.
The Description Logic Handbook: Theory, Im-plementation, and Applications . Cambridge Univ. Press,2003.[]Baader et al. , 2005 Franz Baader, Sebastian Brandt, andCarsten Lutz. Pushing the el envelope. In
IJCAI , pages364–369, 2005.[]Bienvenue et al. , 2013 M. Bienvenue, B. Ten Cate,C. Lutz, and F. Wolter. Ontology-based Data Access: AStudy through Disjunctive Datalog, CSP, and MMSNP. In
ACM PODS , 2013.[]Bishop et al. , 2011 Barry Bishop, Atanas Kiryakov,Damyan Ognyanoff, Ivan Peikov, Zdravko Tashev, andRuslan Velkov. OWLim: A family of scalable semanticrepositories.
Semantic Web J. , 2(1):33–42, 2011.[]Calvanese et al. , 2007 Diego Calvanese, Giuseppe De Gi-acomo, Domenico Lembo, Maurizio Lenzerini, and Ric-cardo Rosati. Tractable reasoning and efficient query an-swering in description logics: The DL-Lite family.
J. ofAutomated Reasoning (JAR) , 39(3):385–429, 2007.[]Chortaras et al. , 2011 A. Chortaras, D. Trivela, and G. Sta-mou. Optimized query rewriting in OWL 2 QL. In
CADE ,pages 192–206, 2011.[]Cuenca Grau et al. , 2012 Bernardo Cuenca Grau, BorisMotik, Giorgos Stoilos, and Ian Horrocks. CompletenessGuarantees for Incomplete Ontology Reasoners: Theoryand Practice.
Journal of Artificial Intelligence Research ,43:419–476, 2012.[]del Val, 2005 Alvaro del Val. First order lub approxima-tions: characterization and algorithms.
Artif. Intell. , 162(1-2):7–48, 2005.[]Eiter et al. , 2012 Thomas Eiter, Magdalena Ortiz, Man-tas Simkus, Trung-Kien Tran, and Guohui Xiao. Queryrewriting for horn-shiq plus rules. In
AAAI , 2012.[]Glimm et al. , 2008 B. Glimm, I. Horrocks, C. Lutz, andU. Sattler. Conjunctive Query Answering for the Descrip-tion Logic
SHIQ . Journal of Artificial Intelligence Re-search , 31:151–198, 2008.[]Grosof et al. , 2003 Benjamin N. Grosof, Ian Horrocks,Raphael Volz, and Stefan Decker. Description logic pro-grams: combining logic programs with description logic.In
WWW , pages 48–57, 2003. []Hustadt et al. , 2005 Ullrich Hustadt, Boris Motik, and Ul-rike Sattler. Data complexity of reasoning in very expres-sive description logics. In
IJCAI , pages 466–471, 2005.[]Hustadt et al. , 2007 Ullrich Hustadt, Boris Motik, and Ul-rike Sattler. Reasoning in Description Logics by a Reduc-tion to Disjunctive Datalog.
Journal of Automated Rea-soning , 39(3):351–384, 2007.[]Krisnadhi and Lutz, 2007 Adila Krisnadhi and CarstenLutz. Data complexity in the EL family of descriptionlogics. In LPAR , 2007.[]Lutz and Wolter, 2012 Carsten Lutz and Frank Wolter.Non-Uniform Data Complexity of Query Answering inDescription Logics. In KR , 2012.[]Lutz, 2008 C. Lutz. The Complexity of Conjunctive QueryAnswering in Expressive Description Logics. In IJCAR ,2008.[]Motik et al. , 2009 Boris Motik, Rob Shearer, and Ian Hor-rocks. Hypertableau Reasoning for Description Logics.
Journal of Artificial Intelligence Research , 36:165–228,2009.[]Ortiz et al. , 2011 Magdalena Ortiz, Sebastian Rudolph,and Mantas Simkus. Query answering in the horn frag-ments of the description logics
SHOIQ and
SROIQ . In
IJCAI , pages 1039–1044, 2011.[]P´erez-Urbina et al. , 2010 H´ector P´erez-Urbina, BorisMotik, and Ian Horrocks. Tractable query answering andrewriting under description logic constraints.
Journal ofApplied Logic (JAL) , 8(2):186–209, 2010.[]Rodriguez-Muro and Calvanese, 2012 MarianoRodriguez-Muro and Diego Calvanese. High perfor-mance query answering over DL-Lite ontologies. In KR ,2012.[]Rosati and Almatelli, 2010 Riccardo Rosati and Alessan-dro Almatelli. Improving query answering over DL-Liteontologies. In KR , 2010.[]Selman and Kautz, 1996 B. Selman and H. Kautz. Knowl-edge compilation and theory approximation. J. of the ACM(JACM) , 43(2):193–224, 1996.[]Simancik, 2012 F. Simancik. Elimination of ComplexRIAs without Automata. In Y. Kazakov, D. Lembo, andF. Wolter, editors,
Proc. of the 2012. Int. Workshop on De-scription Logics (DL 2012) , volume 846 of
CEUR Work-shop Proceedings , Rome, Italy, June 7–10 2012.[]Stocker and Smith, 2008 Markus Stocker and MichaelSmith. Owlgres: A scalable owl reasoner. In
OWLED ,2008.[]Wegener, 1987 I. Wegener.
The Complexity of BooleanFunctions . John Wiley and Sons, 1987.[]Wu et al. , 2008 Zhe Wu, George Eadon, Souripriya Das,Eugene Inseok Chong, Vladimir Kolovski, Melliyal Anna-malai, and Jagannathan Srinivasan. Implementing an infer-ence engine for RDFS/OWL constructs and user-definedrules in Oracle. In
ICDE , pages 1239–1248, 2008.
Proofs for Section 3
Before presenting the proof of Theorem 1, we recapitulate the definition of monotone polynomial projections , which are fre-quently used to transfer bounds on the circuit size from one family of monotone Boolean functions to another. Let f be amonotone Boolean function with inputs ~x , and let g be a monotone Boolean function with inputs ~y . Then, f is a monotoneprojection of g if a mapping ρ : ~y → { f , t } ∪ ~x exists such that f ( ~x ) = g ( ρ ( ~y )) for each value of ~x . Given such a mapping ρ ,a monotone circuit that computes g ( ~y ) can be transformed to a monotone circuit that computes f ( ~x ) by replacing each input y i ∈ ~y with ρ ( y i ) . Furthermore, a family of Boolean functions { f n } is a polynomial monotone projection of a family { g k } if apolynomial p ( n ) exists such that each f n is a monotone projection of some g k with k ≤ p ( n ) ; if that is the case and the familyof functions { g k } can be realised by a family of monotone circuits of polynomial size, then so can { f n } . Theorem 1.
An acyclic
ELU -TBox T and a ground CQ Q exist such that T is not Q -rewritable.Proof. Let T be the following acyclic ELU -TBox: F R ≡ R ⊓ ∃ edge .R F B ≡ B ⊓ ∃ edge .BF G ≡ G ⊓ ∃ edge .G F ≡ F R ⊔ F B ⊔ F G V ⊑ R ⊔ G ⊔ B NC ≡ ∃ vertex .F Furthermore, let v be a fixed individual, and let Q = NC ( v ) . We next represent the problem of answering Q over T and anarbitrary input ABox A using a family of monotone functions { g n ( u ) } . The input size of A is the number u of individualsoccurring in A different from the fixed individual v ; we assume that these individuals are labelled a , . . . , a u . Furthermore,to unify the notation, let a u +1 = v . Using the signature of T , one can then construct at most n ( u ) = 2( u + 1) + 9( u + 1) assertions; hence, we encode A using n ( u ) bits y edge i,j , y vertex i,j , and y Ai as follows: • for each R ∈ { edge , vertex } and ≤ i, j ≤ u , bit y Ri,j is t if and only if R ( a i , a j ) ∈ A ; and • for each A ∈ { R, G, B, F R , F B , F G , F, V, NC } , bit y Ai is t if and only if A ( a i ) ∈ A .The family of Boolean functions { g n ( u ) } is defined such that, given a vector of bits ~y encoding an ABox A of input size u , wehave g n ( u ) ( ~y ) = t if and only if T ∪ A | = Q . Since first-order logic is monotonic, each g n ( u ) is clearly monotone.Let { f m ( s ) } be the family of monotone Boolean functions associated with non-3-colorability as defined in Section 3. We nextshow that { f m ( s ) } is a monotone polynomial projection of { g n ( u ) } . To this end, we first show that, for each positive integer s ,function f m ( s ) is a monotone projection of g n ( s ) . Let ρ be the following mapping, where A is a placeholder for each conceptfrom the signature of T different from V : ρ ( y edge i,j ) = ρ ( y edge j,i ) = (cid:26) x i,j for ≤ i < j ≤ s f otherwise ρ ( y vertex i,j ) = (cid:26) t for i = s + 1 and ≤ j ≤ s f otherwise ρ ( y i ) V = (cid:26) t for ≤ i ≤ s f for i = s + 1 ρ ( y i ) A = f for ≤ i ≤ s + 1 We now show that f m ( s ) ( ~x ) = g n ( s ) ( ρ ( ~y )) for each vector ~x of m ( s ) bits. To this end, let G be the undirected graph associatedwith ~x containing nodes , . . . , s . It is straightforward to check that ρ ( ~y ) is then a vector of n ( s ) bits that encodes the ABox A G with individuals a , . . . , a s , a s +1 = v containing the following assertions: • edge ( a i , a j ) and edge ( a j , a i ) for all ≤ i < j ≤ s such that G contains an edge between i and j , and • assertions V ( a i ) and vertex ( v, a i ) for each ≤ i ≤ s .Furthermore, it is routine to check that G is non-3-colorable iff T ∪ A G | = Q ; but then, by the definition of f m ( s ) and g n ( s ) ,we have f m ( s ) ( ~x ) = g n ( s ) ( ρ ( ~y )) , as required. Finally, for p ( z ) = z , we clearly have n ( s ) ≤ ( m ( s )) . Thus, the family ofmonotone functions { f m ( s ) } is a monotone polynomial projection of the family of monotone functions { g n ( s ) } .The above observation, Item 2 of Theorem 2, and the properties of monotone polynomial projections imply that the queryanswering problem for Q and T cannot be solved using monotone circuits of polynomial size. Now assume that a datalogprogram P exists that is a Q -rewriting of T . By Item 1 of Theorem 2, answering Q over P , and so the problem of answering Q over T as well, can be solved using monotone circuits of polynomial size, which is a contradiction. Proof of Theorem 6
Theorem 6.
Let T be a normalised SHI -TBox, let A be an ABox, and let α be a fact. Then, T ∪ A | = α if and only if Ω T ∪ Ξ T ( A ) | = α .Proof. We prove the contrapositive: for each fact α , we have T ∪ A 6| = α if and only if Ω T ∪ Ξ T ( A ) = α .( ⇒ ) It is routine to show that Υ T is a model-conservative extension of T [Simancik, 2012]. Furthermore, for all con-cepts A and B , each atomic role R , and each role S such that A ⊑ ∃ S.B ∈ T , S ⊑ ∗T R , and S ⊑ ∗T R − , we clearly have T | = A ⊑ ∃ R. self . By these two properties, Ω T is a model-conservative extension of T . Finally, it is obvious that T | = Ξ T .Now consider an arbitrary fact α such that T ∪ A 6| = α . Then, an interpretation I exists such that I | = T ∪ A and I = α . Since Ω T is a model-conservative extension of T and T | = Ξ T , an interpretation J exists such that J | = Ω T and J | = Ξ T ( A ) ; further-more, since α does not use the symbols occurring in Ω T but not in T , we also have J = α . Thus, we have Ω T ∪ Ξ T ( A ) = α ,as required.( ⇐ ) Consider an arbitrary fact α such that Ω T ∪ Ξ T ( A ) = α . Then, an interpretation I = (∆ I , · I ) exists such that I | = Ω T ∪ Ξ T ( A ) and I = α . Without loss of generality, we can assume that I is of a special tree shape, which we de-scribe next. Let N A be the set of individuals occurring in A , and let N be the smallest set such that N A ⊆ N and, if u ∈ N ,then u.i ∈ N for each nonnegative integer i . Then, we can assume that I satisfies all of the following properties:1. ∆ I ⊆ N ;2. c I = c for each individual c ∈ N A ;3. for each atomic role R , each pair in R I is of the form h s, s.i i , h s.i, s i , or h a, b i for s ∈ N and a, b ∈ N A ;4. for each pair h c, d i ∈ R I such that c, d ∈ N A , we have c = d or R ( c, d ) ∈ Ξ T ( A ) ; and5. for each atomic role R , each individual c ∈ N A and each c.i ∈ N , if {h c, c.i i , h c.i, c i} ⊆ R I , then there exist concepts A and B and a role S such that A ⊑ ∃ S.B ∈ T , S ⊑ ∗T R , S ⊑ ∗T R − , and c ∈ A I .A model I of Ω T satisfying properties (1)–(3) can be obtained, for example, using the hypertableau calculus by Motik et al. [2009]. Furthermore, if translated into first-order logic, all role atoms in the consequent of an axiom in Ω T are of the form R ( x, x ) , or they occur in formulae of the form ∃ y.R ( x, y ) ∧ . . . ; thus, the hypertableau calculus cannot derive an atom of theform R ( a, b ) with a = b , thus ensuring property (4). Finally, since Ω T is normalised, concepts of the form ∃ S.B occur in Ω T only in axioms of the form A ⊑ ∃ S.B ; but then, the hypertableau calculus ensures that h c, c.i i ∈ S I or h c.i, c i ∈ S I only if c ∈ A I ; consequently, the only way for {h c, c.i i , h c.i, c i} ⊆ R I to hold is if property (5) holds.To complete the proof, we next construct an interpretation J and show that J | = T ∪ A and J = α . In particular, let J bethe following interpretation defined inductively on the quasi-ordering corresponding to relation ⊑ ∗T : • ∆ J = ∆ I ; • c J = c I = c for each individual c ∈ N A ; • A J = A I for each atomic concept A ; • R J is the transitive closure of R I for each atomic role R that is transitive in T ; and • R J = R I ∪ S S ⊑ ∗T R and R ∗T S S J for each atomic role R that is not transitive in T .If T does not contain concepts of the form ∃ R. self , then J | = T follows from the standard proofs of transitivity eliminationin SHI [Simancik, 2012] and DL-Lite H , + bool [Artale et al. , 2009]; furthermore, it is easy to see that the presence of atoms ∃ R. self requires only minor changes to these proofs. Furthermore, since A ⊆ Ξ T ( A ) , we clearly have J | = A .We are left to show that J = α . If α is of the form A ( c ) , the claim follows from the proofs by Simancik [2012] and Artale etal. [2009]. Hence, assume that α is of the form α = T ( c, d ) , and assume for the sake of contradiction that J | = T ( c, d ) . Then,by the definition of J , there exist an atomic role R and { u , u , . . . , u n } ⊆ ∆ I such that R is transitive in T , R ⊑ ∗T T , c = u , d = u n , and h u i − , u i i ∈ R I for each ≤ i ≤ n . We consider the following two cases. • Assume that, for each ≤ i ≤ n , if u i ∈ N A , then u i = c . Then, we clearly have c = d . Since I satisfies property (3),some ≤ i < n exists such that u i is of the form c.j for some j and {h c, c.j i , h c.j, c i} ⊆ R I holds. Furthermore, since I satisfies property (5), concepts A and B and a role S exist such that A ⊑ ∃ S.B ∈ T , S ⊑ ∗T R , S ⊑ ∗T R − , and c ∈ A I .By Definition 5, then A ⊑ ∃ R. self ∈ Ω T , which implies h c, c i ∈ R I . Finally, R ⊑ ∗T T implies R ⊑ ∗ Ω T T ; hence, we have h c, c i ∈ T I as well, which contradicts our assumption that I = α . • Assume that some ≤ i ≤ n exists such that u i ∈ N A and u i = c . We eliminate from the sequence u , u , . . . , u n eachsubsequence u i +1 , . . . , u j with ≤ i < j ≤ n such that u i ∈ N A , u j ∈ N A , and u k ∈ N \ N A for each i < k < j ; let v , . . . , v ℓ be the resulting sequence. Since I satisfies property (3), each eliminated subsequence satisfies u i = u j ; hence,for each ≤ i ≤ ℓ , we have h v i − , v i i ∈ R I . Furthermore, since u i exists such that u i ∈ N A and u i = c , we have ℓ ≥ , = c , and v ℓ = d . Finally, note that the above definition eliminates each subsequence u i , u i +1 such that u i = u i +1 (condition u k ∈ N \ N A for each i < k < j is then vacuously satisfied); therefore, sequence v , . . . , v ℓ consists of distinctindividuals in N A . But then, since I satisfies property (4), we have that R ( v i − , v i ) ∈ Ξ T ( A ) for each ≤ i ≤ ℓ . Finally,by the definition of Ξ T , then Ξ T ( A ) contains R ( v , v ℓ ) = R ( c, d ) , and consequently T ( c, d ) ∈ Ξ T ( A ) as well. This,however, contradicts our assumption that I = α . C Proofs for Section 4.2
Theorem 8.
For T a normalised ALCHI -TBox, DD ( T ) satisfies the following:1. program DD ( T ) is nearly-monadic; furthermore, if T is a DL-Lite H , + bool -TBox, then DD ( T ) is also simple;2. T | = DD ( T ) ; and3. cert ( Q, T , A ) = cert ( Q, DD ( T ) , A ) for each ABox A and each ground query Q .Sketch. The algorithm by Hustadt et al. [2007] first translates T into a set of skolemised clauses. An inspection of the algorithmreveals that, without concepts of the form ∃ R. self , each resulting clause is of one of the following forms, where R is an atomicrole, f is a function symbol, and A ( i ) , B ( i ) , C ( i ) , and D ( i ) are atomic concepts, ⊤ , or ⊥ : ¬ A ( x ) ∨ R ( x, f ( x )) (20) ¬ A ( x ) ∨ R ( f ( x ) , x ) (21) ¬ R ( x, y ) ∨ S ( x, y ) (22) ¬ R ( x, y ) ∨ S ( y, x ) (23) ¬ A ( x ) ∨ ¬ R ( x, y ) ∨ ¬ B ( y ) ∨ C ( x ) ∨ D ( y ) (24) _ ¬ A i ( x ) ∨ _ ¬ B i ( f ( x )) ∨ _ C i ( x ) ∨ _ D i ( f ( x )) (25) _ ¬ A i ( x ) ∨ _ C i ( x ) (26)Furthermore, since T is normalised, axioms with concepts of the form ∃ R. self are translated into clauses of the following form: ¬ R ( x, x ) ∨ A ( x ) (27) ¬ A ( x ) ∨ R ( x, x ) (28)The algorithm next saturates the resulting set of clauses by ordered resolution, which is parameterised by a carefully con-structed literal ordering and selection function; these parameters ensures that binary resolution and positive factoring are per-formed only with literals that are underlined in (20)–(28). The selection function can be extended to select atom R ( x, x ) ineach clause of type (27); furthermore, the ordering can be modified so that each atom R ( x, x ) is larger than all atoms A ( x ) ,thus ensuring that only atom R ( x, x ) participates in inferences with clauses of type (28). Hustadt et al. [2007] show that eachbinary resolution or positive factoring inference, when applied to clauses of type (20)–(26), produces a clause of type (20)–(23)or (25)–(26). This is easily extended to clauses of type (27)–(28): • a clause of type (27) cannot be resolved with any other clause; • resolving a clause of type (28) with a clause of type (24) produces a clause of type (26); and • resolving a clause of type (28) with a clause of type (22) or (23) produces a clause of type (28).Hustadt et al. [2007] then show that the disjunctive program DD ( T ) can be obtained as the set of all clauses after saturation oftype (22)–(24) and (26). For the case when T contains atoms of the form ∃ R. self , program DD ( T ) should also include clausesof type (27) and (28), and the proof by Hustadt et al. [2007] applies without any problems. Furthermore, it is straightforwardto verify that DD ( T ) is a nearly-monadic program.Finally, if T is a DL-Lite H , + bool -TBox, the only difference is that, in each clause of type (24), we have either A = ⊤ and C = ⊥ ,or B = ⊤ and D = ⊥ . Since saturation does not introduce clauses of type (24), program DD ( T ) is clearly simple. D Proofs for Section 4.3
Theorem 12.
Let N be a set of clauses, let A be an ABox, let C be a Horn clause such that N ∪ A | = C , and assume thatProcedure 1 is applied to N . Then, after some finite number of iterations of the loop in lines 3–9, we have N H ∪ A | = C .Proof. To prove our claim, we assume that Procedure 1 is applied to S = N ∪ A . Towards this goal, we associate with eachclause C ∈ S H ∪ S H a set of facts F C ; for each such F C , let ¬ F C = W A ∈ F C ¬ A . We define F C inductively on the applicationsof inference rules in Procedure 1; furthermore, we show in parallel that, at any point in time, for each clause C ∈ S H ∪ S H andthe corresponding set F C , the following properties are satisfied:a) N | = ¬ F C ∨ C , and(b) F C ⊆ A .For the base case, consider an arbitrary clause C ∈ S . If C ∈ N , we define F C = ∅ ; otherwise, we have C ∈ A \ N , so C is a fact, and we define F C = { C } . Properties (a) and (b) are clearly satisfied.For the induction step, assume that the two properties are satisfied for each clause C ∈ S H ∪ S H at some point in time. Weconsider the following two ways in which Procedure 1 can extend S H or S H . • Assume that resolution is applied to clauses C = D ∨ A and C = D ∨ ¬ A , deriving clause C = D σ ∨ D σ . Let F C = F C ∪ F C , so property (b) is clearly satisfied. By induction assumption, we have N | = ¬ F C ∨ D ∨ A and N | = ¬ F C ∨ D ∨ ¬ A . By the soundness of binary resolution, we have { D ∨ A , D ∨ ¬ A } | = D σ ∨ D σ . Butthen, since ¬ F C and ¬ F C contain only constants, we have N | = ¬ F C ∨ ¬ F C ∨ D σ ∨ D σ , as required for (a). • Assume that positive factoring is applied to a clause C = D ∨ A ∨ B , deriving clause C = D σ ∨ A σ . Let F C = F C , so property (b) is clearly satisfied. By induction assumption, we have N | = ¬ F C ∨ D ∨ A ∨ B . By thesoundness of positive factoring, we have { D ∨ A ∨ B } | = D σ ∨ A σ . But then, since ¬ F C contains only constants,we have N | = ¬ F C ∨ D σ ∨ A σ , as required for (a).We now show the main claim of this theorem. To this end, consider an arbitrary Horn clause C such that N ∪ A | = C . ByTheorem 11, at some point in time during the application of Procedure 1 to S , we have S H | = C . Note that S H is a finite set.Consider an arbitrary Horn clause D ∈ S H . By property (a), we have N | = ¬ F D ∨ D . Furthermore, ¬ F D ∨ D is a Hornclause, so by Theorem 11, at some point in time time during the application of Procedure 1 to N , we have N DH | = ¬ F D ∨ D .Finally, by property (b), we have F D ⊆ A . These observations now imply that N DH ∪ A | = D .Now let N ′ H = S D ∈S H N DH ; clearly, N ′ H ∪ A | = S H . Note that Procedure 1 is monotonic in the sense that, if N H | = E at some point in time for some clause E , then this also holds at all future points in time. Furthermore, N ′ H is finite, so atsome point in time during the application of Procedure 1 to N , we have N H | = N ′ H . By the observations from the previousparagraph, we then have N H ∪ A | = S H as well, which implies N H ∪ A | = C , as required. Lemma 13.
Let P be a nearly-monadic program, and assume that Procedure 1 terminates when applied to P and returns P H .Then, P H is a nearly-monadic datalog program.Proof. We prove by induction on the application of the inference rules in Procedure 1 that, at any point in time, P H ∪ P H isa nearly-monadic program. The base case is clearly satisfied since P is nearly-monadic. For the induction base, we considerthe possible inferences that can derive a clause in P H ∪ P H . First, note that positive factoring is never applicable to a clauseof type 2 from Definition 7; furthermore, when applied to a clause of type 1, positive factoring always produces a clause of thesame type. Second, since clauses of type 2 are Horn, binary resolution can be applied only if at least one clause is of type 1,and the resolvent is then clearly of type 1 as well. Theorem 14.
Let P = DD (Ω T ) for T an SHI -TBox. If, when applied to P , Procedure 1 terminates and returns P H , then P H ∪ Ξ T is a rewriting of T .Proof. Consider an arbitrary ABox A and an arbitrary fact α . By Theorem 6, we have that T ∪ A | = α if and only if Ω T ∪ Ξ T ( A ) | = α . By Theorem 8, the latter holds if and only if DD (Ω T ) ∪ Ξ T ( A ) | = α . Moreover, since α is a Hornclause, by Theorem 12, the latter holds if and only if P H ∪ Ξ T ( A ) | = α . We now show that the latter holds if and only if P H ∪ Ξ T ∪ A | = α . Clearly, P H ∪ Ξ T ( A ) | = α implies P H ∪ Ξ T ∪ A | = α by monotonicity of first-order logic, so we nextfocus on showing that P H ∪ Ξ T ( A ) = α implies P H ∪ Ξ T ∪ A 6| = α .By Theorem 8, Lemma 13, and the fact that Procedure 1 is sound, program P H is nearly-monadic and Ω T | = P H . Nowlet P mH and P rH be the subsets of P H of the rules of type 1 and 2, respectively. Since Ω T | = P rH , by the definition of Ξ T we have Ξ T | = P rH . Furthermore, if a role atom occurs in the head of a rule in P mH , the atom is of the form R ( z, z ) ; hence,each fact involving a role atom in P H (Ξ T ( A )) \ Ξ T ( A ) is necessarily of the form R ( c, c ) . But then, such facts clearly cannottrigger a transitivity rule in Ξ T to derive a new fact; furthermore, for each rule r ∈ Ξ T of the form R ( x, y ) → S ( x, y ) or R ( x, y ) → S ( y, x ) , we have P rH | = r ; consequently, Ξ T ( P H (Ξ T ( A ))) = P H (Ξ T ( A )) , and the property holds.Thus, T ∪ A | = α if and only if P H ∪ Ξ T ∪ A | = α for arbitrary fact α ; but then, for an arbitrary ground query Q , we alsohave T ∪ A | = Q if and only if P H ∪ Ξ T ∪ A | = Q , as required. E Proofs for Section 4.4
Lemma 19.
Theorems 11 and 12 hold if Procedure 1 is modified so that, after line 5, C is replaced with its condensation.Proof. Assume that Procedure 1 derives a clause C in line 5, and let D be the condensation of C . Since Procedure 1 is sound,we have S H ∪ S H | = C ; furthermore, since C subsumes D , we have { C } | = D ; but then, we have S H ∪ S H | = D as well. Itis therefore safe to add D to S H or S H , so let us assume that Procedure 1 does so; but then, this makes C redundant since D subsumes C by the definition of condensation. emma 20. If used with condensation, Procedure 1 terminates when applied to a simple nearly-monadic program P .Proof. Let P = P m ∪ P r . Since P is simple, each rule in P m is of the form (29) with each variable y i occurring at most oncein the rule, and each rule in P r is of the form (30) or (31). ^ A i ( x ) ∧ ^ R i ( x, x ) ∧ ^ S i ( x, y i ) ∧ ^ T i ( y i , x ) → _ U i ( x, x ) ∨ _ B i ( x ) (29) R ( x, y ) → S ( x, y ) (30) R ( x, y ) → S ( y, x ) (31)It is now straightforward to check that Procedure 1 derives only rules of such form: positive factoring is never applicable to arule of the form (29)–(31), and binary resolution clearly derives only rules of these forms.Now let C be an arbitrary rule derived in line 5 of Procedure 1, and let D be the condensation of C ; furthermore, let n bethe number of binary atoms occurring in P . Since each variable in C occurs at most once in the rule, there can be at most n atoms of the form R ( x, y i ) or R ( y i , x ) different up to variable renaming; therefore, D contains at most n variables y i . Sincethe number of predicates in D is linear in the size of P , the size of each clause is linear in the size of P as well. But then, therecan be at most exponentially many different clauses in P H ∪ P H , which implies termination of Procedure 1 using the standardargument [Hustadt et al. , 2007]. F Proofs for Section 5
We first present a well-known characterisation of the entailment of a datalog rule from a first-order theory. The proof ofProposition 23 is straightforward and can be found, for example, in the work by Cuenca Grau et al. [2012].
Proposition 23.
Let F be a set of first-order sentences, and let r be a datalog rule of the form C ∧ . . . ∧ C n → H . Then, foreach substitution σ mapping each variable in r to a distinct individual not occurring in F or r , we have F | = r if and only if F ∪ { σ ( C ) , . . . , σ ( C n ) } | = σ ( H ) . (32)We are now ready to prove Theorem 22. Theorem 22.
The
ELU -TBox T corresponding to the program P from Example 16 and the ground CQ Q = G ( x ) are Q -rewritable, but not strongly Q -rewritable.Proof. Let Q = G ( x ) be a ground query, and let T be the ELU -TBox corresponding to the program P from Example 16;thus, T consists of axioms (33)–(35), which are translated into disjunctive rules as shown below. ⊤ ⊑ G ⊔ B ⊤ → G ( x ) ∨ B ( x ) (33) ∃ E.G ⊑ B E ( x , x ) ∧ G ( x ) → B ( x ) (34) ∃ E.B ⊑ G E ( x , x ) ∧ B ( x ) → G ( x ) (35)An individual v is reachable from an individual w by a path of length n in an ABox A if individuals u n , u n − , . . . , u existsuch that E ( u i , u i − ) ∈ A for each ≤ i ≤ n , u n = v , and u = w . In this proof, we consider 0 to be an even number. Wenext prove the following property ( ∗ ) , which characterises the answers to Q on T ∪ A :For each ABox A containing only the E predicate and for each individual v , we have v ∈ cert ( Q, T , A ) iff anindividual w exists such that v is reachable from w by a path of positive even length and a path of positive odd length.(Proof of ∗ , direction ⇒ ) Let v and w be arbitrary individuals such that v is reachable from w by a path of even length and apath of odd length; thus, A contains sets of assertions of the following form, where k is a positive even number, ℓ is a positiveodd number, u k = u ′ ℓ = v , and u = u ′ = w : { E ( u k , u k − ) , . . . , E ( u , u ) } ⊆ A (36) { E ( u ′ ℓ , u ′ ℓ − ) , . . . , E ( u ′ , u ′ ) } ⊆ A (37)Let I be an arbitrary model of T ∪ A . Due to axiom (33), we have the following two possibilities. • Assume that w ∈ G I . Then, axioms (34) and (35) and the assertions in (36) ensure that u j ∈ G I for each even number ≤ j ≤ k and u i ∈ B I for each odd number ≤ i ≤ k − ; thus, we have v ∈ G I . Furthermore, axioms (34) and (35)and the assertions in (37) ensure that u ′ i ∈ G I for each even number ≤ i ≤ ℓ − and u ′ j ∈ B I for each odd number ≤ j ≤ ℓ ; thus, we have v ∈ B I . Consequently, we have v ∈ B I ∩ G I . • Assume that w ∈ B I . By a symmetric argument we also conclude that v ∈ B I ∩ G I .Thus, we have v ∈ B I ∩ G I for an arbitrary model I of T ∪ A , so v ∈ cert ( Q, T , A ) , as desired.(Proof of ∗ , direction ⇐ ) Assume that v ∈ cert ( Q, T , A ) ; furthermore, for the sake of contradiction assume that, for eachindividual w occurring in A , each path from w to v in A is of odd length, or each path from w to v in A is of even length. Let I be the interpretation defined as follows: ∆ I contains all individuals in A ; • B I = { w | each path from w to v in A is of even length } ∪ { v } ; • G I = { w | each path from w to v in A is of odd length } ; and • E I = {h c, d i | E ( c, d ) ∈ A} .If there is no path from an individual w to individual v in A , then each path from w to v in A is (vacuously) of both even andodd length, so w ∈ B I ∩ G I ; hence, axioms (33)–(35) are satisfied for such w . Furthermore, if w is an individual such thateach path from w to v in A is of even length, and if w satisfies the same property, then each path from w to w is also ofeven length; hence, axioms (33)–(35) are satisfied for such w and w . Finally, if w is an individual such that each path from w to v in A is of odd length, and if w satisfies the same property, then each path from w to w is also of even length; hence,axioms (33)–(35) are satisfied for such w and w . Thus, have have I | = T ∪ A ; however, v G I , which is a contradiction.This completes the proof of property ( ∗ ). Now let P be the following datalog program, where odd and even are fresh binarypredicates: E ( x , x ) → odd ( x , x ) (38) odd ( x , x ) ∧ E ( x , x ) → even ( x , x ) (39) even ( x , x ) ∧ E ( x , x ) → odd ( x , x ) (40) odd ( x, y ) ∧ even ( x, y ) → G ( x ) (41) E ( x , x ) ∧ G ( x ) → B ( x ) (42) E ( x , x ) ∧ B ( x ) → G ( x ) (43)Furthermore, let A be an arbitrary ABox, and let A ′ be the subset of A containing precisely the assertions involving the E predicate. Due to rules (38)–(41), for each individual v we have P ∪ A ′ | = G ( v ) iff an individual w exists such that v isreachable from w in A ′ via an even and an odd path; by property ( ∗ ), the latter is the case iff T ∪ A ′ | = G ( v ) . Rules (42) and(43) correspond to axioms (34) and (35), and they merely ‘propagate’ G and B from individuals explicitly labelled with G and B in A ; hence, it should be clear that P is a Q -rewriting of T . Note, however, that P is not a strong Q -rewriting of T : itcontains fresh predicates odd and even , so T 6| = P .To complete the proof, we next show that no strong Q -rewriting of T exists. To this end, let R be the infinite set containingrule (44) instantiated for each positive even number n . E ( x n , x ) ∧ E ( x n , x n − ) ∧ . . . ∧ E ( x , x ) → G ( x n ) (44)It is straightforward to see that T | = R : one can derive all such rules using resolution and factoring as shown in Example 16.We next prove that R satisfies the following two properties, which immediately imply the claim of this the theorem.1. P ′ | = R for each strong Q -rewriting P ′ of T .2. For each finite set of datalog rules P ′ such that T | = P ′ , we have P ′ = R .(Property 1) Assume by contradiction that a strong Q -rewriting P ′ of T exists such that P ′ = R ; then, there exist a rule r ∈ R such that P ′ = r . Let C , . . . , C n be the body atoms of r , and note that the head atom of r is Q = G ( x n ) . Since r is a datalog rule and P ′ is a set of first-order formulas, by Proposition 23, for each substitution σ mapping each variable in r to a distinct individual, we have P ′ ∪ { σ ( C ) , . . . σ ( C n ) } 6| = σ ( Q ) . Now let σ be one such arbitrarily chosen substitution,and let A = { σ ( C ) , . . . σ ( C n ) } ; clearly, we have P ′ ∪ A 6| = σ ( Q ) . In contrast, R ∪ A | = σ ( Q ) , and, due to T | = R , we have T ∪ A | = σ ( Q ) . Thus, P ′ is not a strong Q -rewriting of T , which contradicts our assumption.(Property 2) Let P ′ be an arbitrary finite set of datalog rules such that T | = P ′ , let m be the maximal number of body atomsin a rule in P ′ , let n be the smallest even number such that n > m , and let A be the following ABox where each v i is distinct: A = { E ( v n , v ) , E ( v n , v n − ) , E ( v n − , v n − ) , . . . , E ( v , v ) } (45)We next show that, for each fact α , we have P ′ ∪ A | = α iff α ∈ A ; this clearly implies P ′ ∪ A 6| = G ( v n ) , which by Propo-sition 23 implies P ′ = R , as required for Property 2. We proceed by contradiction, so assume that a fact α exists such that P ′ ∪ A | = α and α
6∈ A . Then, a rule r ∈ P ′ of the form r = C ∧ . . . ∧ C k → H and a substitution σ exist such that, for A ′ = { σ ( C ) , . . . , σ ( C k ) } , we have A ′ ⊆ A , α = σ ( H ) , and α
6∈ A ; note that
R ∪ A ′ | = α . We now make the followingobservations. • Since
T | = P ′ , we have T ∪ A ′ | = α . • Since k ≤ m < n , we have A ′ ( A . • Let r ′ ∈ P ′ be an arbitrary non-tautological rule of the form r ′ = C ′ ∧ . . . ∧ C ′ ℓ → H ′ . Since T | = P ′ , we have T | = r ′ .The latter, however, is possible only if H ′ is a unary atom involving the G or the B predicate, and each C ′ i is an atominvolving the G , B , or E predicate. Thus, either α = B ( v i ) or α = G ( v i ) for some integer i . By property ( ∗ ), we have T ∪ A ′ = G ( v j ) and T ∪ A ′ = B ( v j ) for each n > j ≥ since each such individual v j isreachable from other individuals in A ′ by at most one path. Thus, we have i = n in the previous item. • Individual v n is reachable from v via two paths in A ; furthermore, due to A ′ ( A , individual v n is reachable from v in A ′ via at most one path. Therefore, by property ( ∗ ), we have T ∪ A ′ = G ( v n ) and T ∪ A ′ = B ( v n ))