• No results found

Query rewriting under linear EL knowledge bases

N/A
N/A
Protected

Academic year: 2020

Share "Query rewriting under linear EL knowledge bases"

Copied!
16
0
0

Loading.... (view fulltext now)

Full text

(1)

BIROn - Birkbeck Institutional Research Online

Dimartino, Mirko and Calì, Andrea and Poulovassilis, Alexandra and Wood,

Peter (2016) Query rewriting under linear EL knowledge bases. In: Ortiz,

M. and Schlobach, S. (eds.)

Web Reasoning and Rule Systems: 10th

International Conference, RR 2016, Aberdeen, UK, September 9-11, 2016,

Proceedings. Lecture Notes in Computer Science 9898. New York, U.S.:

Springer, pp. 61-76. ISBN 9783319452753.

Downloaded from:

Usage Guidelines:

Please refer to usage guidelines at

or alternatively

(2)

Query Rewriting under

Linear

EL

Knowledge Bases

Mirko M. Dimartino1, Andrea Cal`ı1,2,

Alexandra Poulovassilis1, and Peter T. Wood1

1

Knowledge Lab, Birkbeck, University of London

2

Oxford-Man Institute of Quantitative Finance, University of Oxford.

{mirko,andrea,ap,ptw}@dcs.bbk.ac.uk

Abstract. With the adoption of the recent SPARQL 1.1 standard, RDF databases are capable of directly answering more expressive queries than simple conjunc-tive queries. In this paper we exploit such capabilities to answer conjuncconjunc-tive queries (CQs) under ontologies expressed in the description logic calledlinear

EL`in

, a restricted form of EL. In particular, we show a query answering al-gorithm that rewrites a given CQ into a conjunctive regular path query (CRPQ) which, evaluated on the given instance, returns the correct answer. Our technique is based on the representation of infinite unions of CQs by non-deterministic finite-state automata. Our results achieve optimal data complexity, as well as pro-ducing rewritings straightforwardly implementable in SPARQL 1.1.

1

Introduction

Ontologies have been successfully employed in conceptual modelling of data in several areas, especially Information Integration and the Semantic Web. An ontology is a speci-fication of the domain of interest of an application, and it is usually specified in terms of logical rules which on the one hand restrict the form of the underlying data, and on the other hand allow forinferenceof information that is not explicitly contained in the data. Description Logic (DL) is a common family of knowledge representation formalisms that are able to capture a wide range of ontological constructs [2]; they are based on

(3)

Example 1. Consider the TBoxT constituted by the assertionsCvAandAv ∃S.C. The concept∃S.Cdenotes the objects connected via the roleSto some object belong-ing to the conceptC; in other words, it contains allxsuch thatS(x, y)andC(y)for somey. The first assertion means that every object in the classCis also inA; the sec-ond means that every object in the classAis also in the class represented by∃S.C. Now suppose we have the ABoxA={A(a)}; we canexpandAaccording to the the TBoxT so as to add to it all atoms entailed by(T,A); we therefore addS(a, z0)and

C(z0), wherez0is a so-calledlabelled null, that is, a placeholder for an unknown value of which we know the existence. Given the queryq defined asq(x) ← S(x, y), the answer to it under (T,A)is{a} becauseS(a, z0)is entailed by (T,A); in fact, the certain answers toqare obtained by evaluatingqon the expansion and by considering answers that do not contain nulls. If we consider the queryq1defined asq1(x)←C(x),

the answer is empty becausez0, though known to exist, is not known.

Answers to queries over DL knowledge bases can be computed, in certain cases, by a technique calledquery rewriting. In query rewriting, starting from a given query

q, a new query q0 is computed according to a knowledge base K = (T,A), such that the answers toq onKare obtained by evaluatingq0 onAonly; it is said thatq

is rewritteninto q0 and thatq0 is theperfect rewriting of q with respect to T. The language of q0, called thetarget language, can be more expressive than that ofq. A common rewriting technique for DLs and other knowledge representation formalisms, inspired by resolution in Logic Programming, hasunion of conjunctive queriesas target language.

Example 2. Let us consider again the knowledge base of Example 1. The queryq is rewritten into the queryq0 defined asq(x)←A(x)∪S(x, y); intuitively,q0captures the fact that, to search for objects from which some other object is connected via the roleS, we need also to consider objects inA, because the TBox might infer the former from the latter objects. The evaluation ofq0onAreturns the correct answer.

In this paper we consider a DL which we callEL`in[17]. When executed onEL`in

TBoxes, the above rewriting technique does not guarantee termination. We therefore resort to a more expressive target language for the rewriting, namelyconjunctive regular path queries(CRPQs).

Example 3. Consider the TBoxT ={∃R.AvA}and the queryqdefined asq(x)←

A(x). It is easy to see that the above rewriting technique produces an infinite union of conjunctive queries:q(x)←A(x),q(x)←R(x, y), A(y)and all conjunctive queries of the formq(x)← R(x, y1), . . . , R(yk, yk+1), A(yk+1), withk > 1. Now, in order

to capture this infinite rewriting, we can resort to the CRPQ rewriting q0 defined as

q(x)←R∗(x, y), A(y).

(4)

and the TBox, comes into play only at the last step, when the rewriting is evaluated on it.

Our contributions are as follows.

– For illustrative purposes and technical reasons, we show a rewriting algorithm for conjunctive queries onEL`in knowledge bases, which relies on a resolution-like procedure widely adopted in the literature (see e.g. [10]).

– We present a novel rewriting technique, based on non-deterministic finite-state au-tomata, foratomicqueries onEL`in knowledge bases, with CRPQs as target lan-guage. Intuitively, the expressive power of CRPQs is able to finitely capture the infinite rewriting branches of the above algorithm.

– Finally, based on the rewriting technique for atomic queries, we present a technique for rewriting CQs into CRPQs. This is achieved by splitting the problem in two: first we deal with assertions that do not introduce labelled nulls; then, we show that the rest of the assertions are guaranteed to have only tree-like (or, more precisely, forest-like) models; this allows us to capture all paths (including the infinite ones) from roots in the forest by means of finite-state automata. The final rewriting is a CRPQ whose evaluation on the given ABox returns the correct answers to the initial CQ. Since CRPQs can be straightforwardly expressed in SPARQL 1.1, by the means of property paths, our approach is suitable for real-world settings.

– Our technique achieves optimal computational cost in data complexity, that is where the TBox and the query are fixed and the ABox alone is a variable in-put; in fact, our algorithm runs inNLOGSPACE in data complexity, which is the known (tight) bound for CQ answering underEL`inknowledge bases. Notice also that, regardingcombined complexity(where query, TBox and ABox all constitute the variable input), our rewriting is expressed in the language of CRPQs, which can be evaluated inNP. Moreover, in the case of “simple” queries such as atomic queries, our rewriting is expressed as a regular path query, which can be evaluated inNLOGSPACE.

2

Preliminaries

In this section we present the formal notions which will be used in the rest of the paper.

2.1 Description Logics

We briefly introduce the syntax of the EL`in description logic (DL) [18, 16]. The al-phabet contains three pairwise disjoint and countably infinite sets of concept names

A,role namesR, andindividual namesI. Acomplex concept Cis constructed from a special primitive concept>(‘top’), concept names and role names using the following grammar:C ::= A | ∃R.C | ∃R.>,whereA ∈ AandR ∈ R. The set of complex concepts is denoted byC. Aterminological box(or TBox)T is a finite set ofconcept

androle inclusion axiomsof the formC1vC2 and R1vR2, whereC1, C2∈Cand R1, R2∈R. Anassertion box(or ABox)Ais a finite set ofconceptandrole assertions

(5)

we denote byind(A)the set of individual names that occur inA. Taken together,T and Acomprise aknowledge base(or KB)K= (T,A).

We adopt the semantics of DL defined in terms of interpretations. Aninterpretation

I is a pair(∆I,·I)that consists of a non-emptydomain of interpretationI and an interpretation function·I which assigns (i)an elementaI I to each individual

name a,(ii) a subset AI ⊆ ∆I to each concept name Aand (iii)a binary relation

PI ⊆∆I×∆I to each role nameP. We adopt theunique name assumption(UNA); therefore distinct individuals are assumed to be interpreted by distinct domain elements. The interpretation function·Iis extended inductively for complex concepts by taking:

(∃R.>)I={u|there is avsuch that(u, v)∈RI},

(∃R.C)I={u|there is av∈CI such that(u, v)∈RI}.

We now define the satisfaction relation|=for inclusions and assertions: I |=C1vC2if and only ifC1I⊆C2I,

I |=R1vR2if and only ifRI1 ⊆RI2 ,

I |=C(a)if and only ifaI ∈CI ,

I |=R(a, b)if and only if(aI, bI)∈RI.

We say that an interpretationI is amodelof a knowledge baseK = (T,A), written I |=K, if it satisfies all concept and role inclusions of T and all concept and role assertions ofA. A TBox is said to be innormal formif each of its concept inclusion axioms is of the formsAvB,∃P.CvA, orAv ∃P.C, whereA, B ∈A,C ∈A∪ {>}andP ∈R. We recall that everyELTBox can be transformed into an equivalent TBox in normal form of size that is linear in the size of the original TBox [14].

2.2 Regular Languages and Conjunctive Regular Path Queries

We assume the reader is familiar with regular languages, represented either by regular expressions or nondeterministic finite state automata. A nondeterministic finite state automaton(NFA) over a set of symbolsΣis a tupleα= (Q, Σ, δ, q0, F), whereQis a finite set ofstates,δ ⊆Q×Σ×Qthetransition relation,q0 ∈Qtheinitial state, andF ⊆Sthe set offinal states. We useL(α)to denote the regular language defined by an NFAα, and(Σ)∗to denote the set of all strings over symbols inΣ, including the

empty string.

In order to define queries, we also need to assume the existence of a countably infinite set ofvariablesV. A termtis an individual name inIor a variable inV. An

atomis of the formα(t, t0), wheret, t0are terms, andαis an NFA or regular expression defining a regular language overR∪A. We say that a strings∈(R∪A)∗is apath.

Aconjunctive regular path query(CRPQ)qof aritynhas the formq(x)←γ(x,y), wherex=x1, . . . , xnandy=y1, . . . , ymare variables, andγ(x,y)is a set of atoms with variables fromxandy.q(x)is called theheadofqand is denoted byhead(q), andγ(x,y)is thebodyofqand denoted bybody(q). The variables inx=x1, . . . , xn are the answer variables of q, while those in y = y1, . . . , ym are the existentially

quantified variables ofq. ABoolean CRPQis a CRPQ with no answer variables. A

(6)

is an RPQq=head(q)←α(x, y)such thatα∈(R∪A)∗, whereαis thepath of q

denoted bypath(q).

Aconjunctive query(CQ)qis a CRPQ such that, for each atomα(t, t0)∈body(q),

α ∈ (R∪A). Informally, CQs disallow regular expressions in their bodies. Given a CRPQ q with answer variables x = x1, . . . , xn and an n-tuple of individuals

a= (a1, . . . , an), we useq(a)to refer to the Boolean query obtained from qby re-placingxiwithaiinbody(q), for every16i6n.

We now define the semantics of CRPQs [7]. Given the individual namesa, b, an interpretation I, and a regular language α over the alphabet R∪A, we have that I |=a−→α b if and only if there is somew = u1. . . un ∈ L(α)and some sequence

e0, . . . , en withei ∈ ∆I,0 6 i 6 n, such thate0 = aI anden = bI, and for all

1 6 i 6 n:(i)if ui = A ∈ A, thenei−1 = ei ∈ AI;(ii) ifui = R ∈ R, then

(ei−1, ei)∈ RI. Amatchfor a Boolean CRPQqin an interpretationI is a mapping

πfrom the terms inbody(q)to the elements inIsuch that:(1)π(c) = cifc ∈ I;(2)

I |=π(t)−→α π(t0)for each atomα(t, t0)inq.

Note that, to avoid notational clutter, we do not allow unary atoms in the body of the query. In fact, each atom of the formA(t), whereA∈Aandt∈V∪I, can be always replaced by a binary atomA(t, z), wherezis a variable. However, for better legibility, we use unary atoms in some examples throughout the paper. We writeI |=qif there is a match forqinI, andK |=qifI |=qfor every modelI of the KBK. For brevity, given an ABoxAwe useA |=qto refer to(,A)|=q, where(,A)is a knowledge base with empty TBox. Given a CRPQqof aritynwe say that a tuple of individual namesa= (a1, . . . , an)is acertain answerforqwith respect to a KBKif and only if K |=q(a).

3

Rewriting of Conjunctive Queries into First-Order Queries

In this section we show a technique for rewriting CQs into a union of conjunctive queriesunder anEL`in TBox. We base our approach on the rewriting algorithm pro-posed in [9], which deals withDL-LiteR KBs. We do this to establish correctness of

the rewriting approach with the NFAs illustrated in Section 4. The technique is based on two steps: areductionstep, which eliminates atoms that are more specific than some other atom, and the actualrewritingstep, which is similar to the resolution step in logic programming. Notice that the algorithm might not terminate; we present it for technical reasons, as in Sections 4 and 5 we will show that our CRPQ rewriting captures all the rewriting branches produced by the algorithm, including infinite ones.

Following the approach of [9], we say that a term of an atom in a query isboundif it corresponds to (i) an answer variable, (ii) a shared variable, that is, a variable occurring at least twice in the query body, or (iii) a constant, that is an element inI. Conversely, a term of an atom in a query isunboundif it corresponds to a non-shared existentially quantified variable. As usual, we use the symbol ‘ ’ to represent an unbound term.

A set of atomsA={a1, . . . , an}, wheren >2,unifiesif there exists a substitution

φ, calledunifierfor A, such that (i) ift∈I, thenφ(t) =t, and (ii)φ(a1) =· · ·=φ(an).

Reduce is a function that takes as input a conjunctive queryq and a set of atomsS

(7)

themost general unifierbetween the atoms ofS. We point out that, in unifying a set of atoms, each occurrence of the symbol is considered to be a different unbound variable. We now define when concept and role inclusion axioms areapplicableto atoms in a query. An axiomIisapplicable to an atomA(x1, x2)forA ∈AifIis of the form

B v A,∃R.> v Aor∃R.B v A. An axiomIisapplicable to an atomP(x1, x2)

forP ∈Rif (1)x2= and the right-hand side ofIis∃P.>or∃P.A; or (2) the

right-hand side ofIisP. An axiomIisapplicable to a pair of atomsP(x1, x2), A(x2, x3)

ifx2does not appear in other atoms of the query body,x3 = andIis of the form C v ∃P.A. Below we define the set of rewriting rules for atoms in the query body. LetIbe an inclusion assertion that is applicable to a sequence of query atomsg. The sequence of atoms obtained fromgby applyingI, denoted bygr(g, I), is defined as follows:

(a) Ifg=A(x1, x2)andI=BvA, thengr(g, I) =B(x1, x2); (b) Ifg=A(x1, x2)andI=∃P.> vA, thengr(g, I) =P(x1, );

(c) Ifg=A(x1, x2)andI=∃P.BvA, thengr(g, I) =P(x1, z1), B(z1, ), where z1is a fresh variable;

(d) Ifg=P(x1, )andI=Av ∃P.>orI=Av ∃P.B, thengr(g, I) =A(x1, ); (e) Ifg=P(x1, x2)andI=RvP , thengr(g, I) =R(x1, x2);

(f) Ifg=P(x1, x2), A(x2, )andI=Cv ∃P.A, thengr(g, I) =C(x1, );

We denote byRewrite(q,T)the rewriting procedure that generates the perfect rewrit-ing ofqwith respect toT (see Figure 1).

Algorithm 1:AlgorithmRewrite(q,T)

Data:Conjunctive queryq, TBoxT. Result:Union of conjunctive queriesQ. Q:={hq,1i};

repeat

Q0:=Q;

foreachhqr, xi ∈Q0do

/* Reduction step */

ifthere existsI∈ T such that I is not applicable toqrthen foreachset of atomsS⊆body(qr)do

ifSunifythen

Q:=Q∪ hReduce(qr, S),0i

/* Rewriting step */

foreachaxiomI∈ T do ifIis applicable toqrthen

qr0:=rewriteqraccording toI; Q:=Q∪ hqr0,1i

untilQ0=Q;

(8)

Example 4. Consider applying theRewriteprocedure to a queryqof the formq(x)←

R(x, y), R( , y)over the TBox{Av ∃R.>}, whereA∈AandR∈R. In this query, the atoms R(x, y) and R(, y) unify, and executing Reduce(q,{R(x, y), R(, y)})

yields the atomR(x, y). The variabley is now unbound, so can be replaced by “ ” (adon’t care). Note that the reduction step produces a query marked with ‘0’ whilst the rewriting step marks queries with ‘1’, and only queries marked with ‘1’ are added to the output set. We adopt this approach to avoid redundancy in the output set, as a query marked with ‘0’ is always contained in a query marked with ‘1’. Now, the axiom {Av ∃R.>}can be applied toR(x, ), whereas, before the reduction process, it could not be applied to any atom of the query. Following this, the rewriting step reformulates the query toq(x)←A(x, )which is added to the output set. For more details on the rewriting procedure refer to [9, 10].

Now we show that each disjunct of the perfect rewriting of an atomic concept query with respect to anEL`in TBox is of a special form called asimple path conjunctive query, defined below. We then define some technical lemmas which will be used in Section 4 for the rewriting of atomic concepts by means of a finite-state automaton.

Definition 1. A conjunctive query q is a simple path conjunctive query (SPCQ) if body(q)is of one of the following forms: (i)A(x1, x2);

(ii)P1(x1, y1), P2(y1, y2), . . . , Pn−1(yn−2, yn−1), Pn(yn−1, x2); or

(iii) P1(x1, y1), P2(y1, y2), . . . , Pn−1(yn−2, yn−1), Pn(yn−1, yn), A(yn, x2), where:

x1, x2are terms; for eachi,yi is an existentially quantified variable andyi 6=yi+1; n>1;A∈AandP1, . . . , Pn∈R.

Note that query q in Example 4 is not an SPCQ. An SPCQ head(q) ←

Z1(x0, x1), . . . , Zn(xn−1, xn) is equivalent to an RPQ of the form head(q) ←

Z1. . . Zn(x0, xn); thus, throughout the paper we will use either the RPQ form or the CQ form of a SPCQ, whichever is more natural in the given context. For instance, given a SPCQq, with a little abuse of notation we have thatpath(q)isZ1. . . Zn.

Given two pathsp,p0, we say thatp0containsp, writtenpvp0, if for each ABoxA and for each tuplea= (a, a0)it holds that, ifA |=q()←p(a)thenA |=q()←p0(a). Given a pathpand an NFAN over(R∪A)∗we say thatN containsp, writtenpv N if there exists someα∈L(N)such thatpvα.

Lemma 1. Given an SPCQ q, an EL`in TBoxT and an axiom ρ ∈ T that is not applicable to body(q), for each set of atomsS ⊆ body(q)that unify, ρis also not applicable tobody(Reduce(q, S)).

Proof. (Sketch)We consider all the possible cases ofρ.

Case 1: ρ is of the type B v A, ∃P.>, ∃R.B v A, R v P. ρ is not applicable to body(q) if an atom A(x1, x2) or P(x1, x2) are not in body(q). If A(x1, x2)orP(x1, x2)is not inbody(q), thenA(x1, x2)orP(x1, x2)is clearly not

inbody(Reduce(q, S))and the claim follows.

Case 2: ρis of the type A v ∃R.>.ρ is not applicable tobody(q)if an atom

(9)

body(q)andx26= , sinceqis an SPCQ, this happens only ifR(x1, x2)is not the last

atom of the path. The only way to havex2= is to unifyR(x1, x2)with the atom at its

right as it is the only atom that can havex2. If there exists a unification, the reduction

produces an atomR(xi, xi), withxi 6= and the claim follows.

Case 3: ρis of the typeA v ∃R.B. Sinceq is an SPCQ,ρis not applicable to

body(q) if the atomsR(x1, x2), B(x2, x3) are not in body(q) or if R(x1, x2)is in

body(q)andx2 6= . It is easy to see that this case is similar to the case whereρis of the typeAv ∃R.>.

Following from Lemma 1 we have that, to rewrite CQs with respect toEL`in TBoxes, the reduction step generates queries that are never processed by the rewriting step. So, in our case, the reduction step is of no use. However, we keep it in the rewriting algorithm in order to handle future extensions to the ontology language.

Lemma 2. LetT be anEL`in

TBox andq a CQ of the formq(x) ← A(x, y), with A∈A. Ifqrew∈Rewrite(q,T), thenqrewis an SPCQ.

Proof. (Sketch)Following from Lemma 1 we know that queries produced by the reduc-tion step are never processed by the rewriting step, and so they are never marked with ‘1’. So, queries produced by the reduction step are never in the output set, and thus we can ignore the reduction step. The proof is then by induction on the set of queries that are produced after each rewriting step. We denote byQ[i]the set of the queries produced after thei-th iteration of the repeat loop in Algorithm 1.

BASESTEP.Q[1]={q(x)←A(x, y)}plus the queries obtained by the 1st rewrit-ing step. The possible cases are the rewritrewrit-ing rules (a), (b) and (c) which generate SPCQs.

INDUCTIVESTEP. Ifq∈Q[i+1], thenqis computed by applying a rewriting rule to

a query inQ[i]. The claim follows by induction if for each rewritingqtoq0, we have that q0is a SPCQ. Ifqis a SPCQ then we can identify a fixed set of possible rewriting cases, according to the rewriting rules. For each possible rewriting case, whenqis rewritten toq0, it is easy to see that ifqis a SPCQ, thenq0is a SPCQ.

It is important to note that this algorithm is not guaranteed to terminate onEL`in

knowledge bases; see e.g. the TBox of Example 3. This is because the algorithm es-sentially enumerates all rewritings produced by single applications of the reduction and the rewriting steps; when the algorithm is forced by the TBox to cycle on a set of as-sertions, it produces infinite branches and does not terminate. However, it is possible to capture such cyclic applications of the rewriting steps if we adopt a more expressive target language for the rewriting; this is the subject of the next two sections: in Section 4 we show how to encode the rewritings for an atomic query by means of a finite-state automaton; in Section 5 we present a technique, similar to that shown in [14] for OWL QL, that allows us to combine rewritings for atomic queries so as to obtain a CRPQ rewriting for CQs.

4

Rewriting for Atomic Concept Queries

In this section we show how to encode rewritings for atomic queries underEL`in by

(10)

sequences of rewriting steps executed according to the algorithm of Section 3. We con-centrate on atomic queries having a concept atom in the body, since in the case of role atoms, this is done by a simple check on sequences of role inclusions in the TBox — see [13].

Definition 2. LetT be anEL`in

TBox in normal form,Σthe alphabetR∪AandAa concept name appearing inT. The NFA-rewriting ofAwith respect toT, denoted by NFAA,T, is the NFA overΣof the form(Q, Σ, δ, q0, F)defined as follows:

(1) statesSAandSFAare inQ,SFAis inF, and transition(SA, A, SFA)is inδ;

(2) SAis the initial stateq0,S>is a final state;

(3) for eachB ∈Athat appears in at least one concept or role inclusion axiom ofT, statesSB andSFBare inQ,SFBis inF, and transition(SB, B, SFB)is inδ;

(4) for each concept inclusion axiomρ∈ T: (4.1) ifρis of the formB v C, where B, C ∈ A, the transition(SC, , SB)is inδ; (4.2) ifρis of the formB v ∃R.>,

whereB ∈ Aand R ∈ R, for each transition (SX, R, S>) ∈ δ, the transition

(SX, , SB)is inδ; (4.3) ifρis of the form∃R.> vB, whereB ∈AandR∈R,

the transition(SB, R, S>)is inδ; (4.4) ifρis the form∃R.DvC, whereC, D∈A andR ∈ R, the transition(SC, R, SD)is inδ; (4.5) ifρis the formC v ∃R.D,

whereC, D∈AandR∈R, for any sequence of transitions starting fromSXthat

accepts the stringsRDorR, the transition(SX, , SC)is inδ;

(5) for each role inclusion axiom T v S ∈ T and each transition of the form

(SC, S, SB)∈δ, the transition(SC, T, SB)is inδ.

Example 5. Consider the TBox T defined by the following inclusion assertions: ∃R.C v ∃P.>,∃P.> v A, ∃P.> v B, ∃T.B v C and∃S.A v A, whereP,

R,S, T are role names and A, B,C are concept names. Consider now the query

q = q(x) ← A(x, y). First, we transformT into normal form, sayT0, by adding a

fresh concept nameXand by replacing∃R.Cv ∃P.>by∃R.C vXandXv ∃P.>. It is easy to see thatRewrite(q,T0)runs indefinitely (for instance, we have an infinite

loop when rule(c)is applied to the atom A(x, y)). Let us consider the NFA rewrit-ing of A with respect toT0. We construct NFA

A,T0 as follows: by(3) we have the transitions (SA, A, SFA),(SB, B, SFB),(SC, C, SFC) and(SX, X, SFX); by (4.3) and the inclusion assertions ∃P.> v A and ∃P.> v B, we have the transitions

(SA, P, S>) and(SB, P, S>); by (4.2)and the inclusion assertion X v ∃P.>, we

have the transitions(SA, , SX)and(SB, , SX); finally, by(4.4)and the inclusion as-sertions∃R.C vX,∃T.BvCand∃S.AvA, we have the transitions(SX, R, SC),

(SC, T, SB)and(SA, S, SA). The NFANFAA,T0 is illustrated in Figure 1. The lan-guage accepted by NFAA,T0 can be described by the following regular expression:

(∃S.)∗(A|X|(RT)∗(P|RC|RT(B|X))). It is easy to see that all the infinite outputs ofRewrite(q,T0)are of the formq(x)NFA

A,T0(x, y). For instance, some possible rewritings ofqare:

q(x)←S(x, z1), S(z1, z2), P(z2, y) q(x)←S(x, z1), S(z1, z2), A(z2, y)

(11)

SA start

SFA

S> SB

SFB

SC

SFC

SX

SFX

S

A P

C T

B P

X

[image:11.612.167.454.118.254.2]

R

Fig. 1.NFA for Example 5.

It is easy to verify that each of these output queries is a SPCQ and each path is in

L(NFAA,T0).

Theorem 1. Let T be an EL`in TBox, and a concept A. We have that q ∈

Rewrite(q(x)←A(x, y),T)if and only ifpath(q)∈L(NFAA,T).

Proof. (Sketch)(⇒) The proof is by induction on the set of queries that are marked with ‘1’ after each rewriting step, as the queries marked with ‘0’ are not returned by the algorithm. We denote byQ[i]the set of queries marked with ‘1’ after thei-th application

of the rewriting step.

BASESTEP.Q[0] ={q}. By(2)we have thatSAis the initial stateq0and by(3) we have the transition(SA, A, SFA)thereforeA∈L(NFAA,T)and the claim follows

trivially.

INDUCTIVESTEP. From Lemma 1 we have that, if an axiomρ∈ T is not applicable tobody(q), for each set of atoms S ⊆ body(q)that unify, ρis also not applicable tobody(Reduce(q, S)). It follows that if a queryq0 is marked with ‘0’ then there is

no axiom in T that is applicable to q0. Thus, ifq ∈ Q[i+1], thenq is computed by

applying a rewriting rule to a query that is marked with ‘1’ ati-th application of the rewriting step, which is a query inQ[i]. Suppose that for eachq Q[i] we have that Path(q)∈L(NFAA,T), the claim follows by induction if for each rewritingqtoq0, we

have thatPath(q0)∈L(NFAA,T). From Lemma 2 it follows that the body of each query

marked with ‘1’ is a simple path, thus we can identify a fixed set of possible rewriting cases. For each of possible rewriting case, whenqis rewritten toq0, there is a rule in the definition ofL(NFAA,T)such thatPath(q)∈L(NFAA,T)→Path(q0)∈L(NFAA,T)

is true.

(⇐) The claim follows by induction on the construction rules of theNFAA,T

start-ing fromA, which correspond to all the possible rewriting steps ofRewrite(q(x) ←

A(x, y),T).

(12)

Proof. From Theorem 1 we have thatNFAA,T is a perfect rewriting ofAwith respect

toT and the claim follows.

5

CRPQ rewriting for

EL

`in

In this section, following the approach of [13, 14], we split the problem of rewriting CQs under EL`in in two: we deal separately with the part of the TBox that does not have existential quantification on the right-hand side of assertions (that is, the part that when expanded does not produce any labelled null) and with the rest of the TBox. We make use of the algorithm for atomic queries presented in the previous section. Then, we put together the solutions devised for the two parts to produce a rewriting algorithm for CQs underEL`in.

Given anEL`in knowledge base (T,A)withT in normal form, we can find all answers to a CQqover this KB by evaluatingqover the (possibly infinite) canonical modelCT,Awhich can be constructed using the chase procedure. We begin by defining

thestandard modelIAof the ABoxAas follows:(1)∆IA =ind(A);(2)aIA =a,

for a ∈ ind(A); (3) AIA = {a | A(a) ∈ A}, for concept nameA; (4) PIA = {(a, b) | P(a, b) ∈ A}, for role nameP. Then we take the standard modelIAasI0

and apply inductively the following rules to obtainIk+1fromIk:(a’)ifd∈AI1kand A1vA2∈ T, then we adddtoAIk+1

2 ;(b’)if(d, d0)∈R Ik

1 andR1vR2∈ T , then

we add(d, d0)toRIk+1

2 ;(c’)ifd∈(R.D)Ikand∃R.DvA∈ T, whereDis a concept

name or>, then we adddtoAIk+1;(d’)ifdAIkandAv ∃R.D∈ T, whereDis a concept name or>, then we take afreshlabelled null,d0, and addd0toDIk+1and(d, d0) toRIk+1. The canonical modelC

T,Aconstructed using rules (a’), (b’), (c’) and (d’) in

a bottom-up fashion can alternatively be defined with the top-down approach illustrated in this section; this will be required for query rewriting in Section 5.2. There are two key observations that lead us to the alternative definition: first, fresh labelled nulls can only be added by applying (d’), and, second, if two labelled nulls,d1andd2, are introduced by applying(d0)with the same concept inclusionAv ∃R.D, then the same rules will be applicable tod1andd2in the continuation of the chase procedure. So, each labelled nulld0 resulting from applying (d0)to someA v ∃R.Don a domain elementdcan

be identified with a pair of the form(d,∃R.D). Following from Theorem 2, for each concept∃R.Dthat appears at the RHS of a concept inclusion axiom inT , we introduce a fresh symbolw∃R.Dthat is awitnessfor∃R.Dand define a generating relation;T,A

on the set of these witnesses together withind(A)by taking:

– a;T,Aw∃R.D, ifa∈ind(A),IA|=B(a)andBvNFAA,T, – w∃S.B;T,Aw∃R.DifB vNFAA,T andAv ∃R.D∈ T,

whereS is a role name. We point out that we are able to define a finite generating relation;T,Afor anEL`inknowledge base(T,A)with the definition ofNFAA,T. In

fact,NFAA,T captures all (possibly infinite) expressionsBsuch thatT |=BvA. This

allows us to exploit the Tree-Witness rewriting technique in [14] (see Section 5.2). Apath;T,A σis a finite sequenceaw∃R1.D1. . . w∃Rn.Dn,n > 0, such thata ∈

ind(A)and, ifn >0, thena;T,Aw∃R1.D1andw∃Ri.Di ;T,Aw∃Ri+1.Di+1, fori <

(13)

(d’) to someAv ∃R.Don the domain elementσ(and which corresponds to the pair

(σ,∃R.D)mentioned above). Let us denote bytail(σ)the last element inσ; as we noted above, the last element inσuniquely determines all the subsequent rule applications. Thecanonical modelCT,Ais defined by taking∆CT,A to be the set of allpath;T,A and taking: (1) aCT,A = a, for a ind(A); (2) ACT,A = {a ind(A) | I

A |= B(a)andB vNFAA,T} ∪ {σw∃R.D |D vNFAA,T}, for each concept nameA;(3) PCT,A ={(a, b)| I

A |=R(a, b)andT |=R vP} ∪ {(σ, σw∃R.D)| tail(σ);T,A w∃R.D,T |= R vP}, for a role name P. We point out that, by the definition of rule (b’), we have thatT |=R vP only if there is a sequence of rolesR0, . . . , Rnsuch thatRi−1vRiare inT, for16i6n, andRn =P. For proof refer to [13].

Given a CQq, we use the assertions of the TBoxT to rewriteqinto another query

q0that returns, when evaluated over the data instance (ABox)A, all the certain answers ofqwith respect to(T,A). Notice that the rewritingq0 only depends on the TBoxT and the given queryq; it is independent of the ABoxA. In query processing, therefore, we useAonly in the final step, when the rewriting is evaluated on it.

We call a CQ q and a TBox T CRPQ-rewritable if there exists a CRPQ q0

such that, for any ABox A and any tuple a of individuals in ind(A), we have

(T,A)|=q(a)if and only ifA |=q0(a).

5.1 Rewriting for FlatEL`in

We first consider an important special case offlatEL`in TBoxes that do not contain existential quantifiers on the right-hand side of concept inclusions. In other words, flat EL`inin normal form can only contain concept and role inclusions of the formA1 v

A2,∃R.D vAandR1 vR2, for concept namesA, A1, A2, role namesR1, R2, and

D a concept name or>. Now letT be a flatEL`in TBox,qa conjunctive query and

aa tuple of individuals. SinceCT,Ais the canonical model for(T,A), we have that

(T,A) |= q(a)if and only if q(a)is true in the canonical modelCT,A. The TBox

is flat, the generating relation;T,Ais empty, the canonical modelCT,Acontains no

labelled nulls, and so, by the definition ofCT,A, we have that:

– CT,A|=A(a)if and only ifIA|=B(a)andT |=BvNFAA,T, for some B, – CT,A|=P(a, b)if and only ifIA|=R(a, b)andT |=RvP, for some R.

For a CQq, we define now rewritingqext as a union of CRPQs which is the result of replacing every atom A(z1, z2)inq withAext(z1, z2)and every atom P(z1, z2) inq withPext(z1, z2), whereAext(u1, u2) = NFAA,T(u1, u2)andPext(u1, u2) =

S

T |=RvP

R(u1, u2). This leads to the following results.

Proposition 1. For all concept namesA, role namesP and individual namesaandb we have: (1)CT,A|=A(a)if and only ifIA|=q()←Aext(a, a), (2)CT,A|=P(a, b) if and only ifIA|=q()←Pext(a, b).

Proof. Follows immediately from the definitions of the formulasAextandPext.

Proposition 2. For any CQqand any flatEL`in TBoxT,q

extis the CRPQ rewriting

(14)

Proof. Follows immediately from the previous proposition and from the fact that each formula of the formR1(u1, u2)∪ · · · ∪Rn(u1, u2)can be expressed as a regular path

formula of the formR1| · · · |Rn(u1, u2).

5.2 Tree-Witness Rewriting for FullEL`in

Following a divide and conquer strategy, we show how the process of constructing FO-rewritings can be split into two steps: the first step considers only the flat part of the TBox and uses the formulasAext(u1, u2)andPext(u1, u2)defined in Section 5.1; the

second step (to be described below) takes account of the remaining part of the TBox, that is, inclusions of the formAv ∃R.D. We first need some preliminary definitions.

Definition 3. (H-completeness) Let T be a (not necessarily flat)EL`in TBox. A simple ABoxAis said to beH-complete with respect toT if, for all concept namesAand role namesP, we have:

– A(a)∈AifIA|=B(a)andBvNFAA,T, for someB, – P(a, b)∈AifIA|=R(a, b)andT |=RvP, for someR.

Observe that, if an ABoxAis H-complete with respect to T, then the ABox part of CT,Acoincides withIA. Thus, ifT is flat thenqitself is clearly the perfect rewriting

ofqandTover H-complete ABoxes. This leads to the following proposition.

Proposition 3. Ifq0is the perfect rewriting ofqandT over H-complete ABoxes, then q0extis the perfect rewriting ofqwith respect toT.

So, to generate a CRPQ rewriting we can now focus on constructing rewritings over H-complete ABoxes. To achieve this, we reuse a technique adopted in [14] calledTree Witness. SupposeT is aEL`in TBox in normal form. To compute certain answers to

qover (T,A), for someA, it is enough to find answers toqin the canonical model CT,A. To do this, we have to check, for every tupleaof elements inind(A), whether

there exists a homomorphism fromq(a)toCT,A. Thus, as in the case of flat TBoxes,

the answer variables take values from ind(A). However, the existentially quantified variables in q can be mapped both to ind(A) and to the labelled nulls in CT,A. In

order to identify how the existential variables can be mapped to the anonymous part, it is sufficient to take a look at the tree-like structure of the generating relation. This technique allows us to rewrite a CQs with respect toEL`in

TBoxes over H-complete ABoxes; for details on the Tree Witness rewriting technique, consult [13, 14].

Theorem 3. LetT be anEL`inTBox andqa CQ. Letq0be the Tree Witness rewriting forqwith respect toT over H-complete ABoxes. For any ABoxAand any tupleain ind(A), we haveCT,A|=q(a)if and only ifIA|=qext0 (a).

(15)

6

Discussion

In this paper we presented a rewriting algorithm for answering conjunctive queries un-derEL`in knowledge bases. We showed how to encode rewritings of atomic queries with finite-state automata, and finally how to combine such automata in order to pro-duce rewritings for the full language of CQs. We believe that our contribution sheds light on the possibilities of efficient query rewriting under DLs. Our rewriting tech-nique achieves optimal data complexity (see below), and produces a “compact” rewrit-ing without havrewrit-ing to take the ABox into account; then the rewritrewrit-ing is evaluated on the ABox, which does not need to be expanded. We therefore argue that this pure rewriting approach is likely to be suitable for real-world cases, especially considering that the final CRPQ evaluation step can be performed by expressing the CRPQ in SPARQL 1.1.

Complexity. When considering query answering under ontologies, the most important asymptotic complexity measure is the so-calleddata complexity, i.e. the complexity w.r.t. the ABoxA. Our rewriting is evaluated on AinNLOGSPACEin data complex-ity [4], which coincides with the lower bound for CQ answering inEL`in (see [17], whereEL`in is called DL-lite+). In terms ofcombined complexity, i.e. the complex-ity w.r.t. A,T andq, we limit ourselves to a few consideration, leaving the issue to another work. Our rewriting, which is exponential in the query and the TBox, sim-ilarly to other approaches, has the advantage of being expressed in CRPQs (which implies the possibility of being easily translated in SPARQL, as above noted) whose evaluation is inNP[8]. Moreover our technique behaves as “pay-as-you-go” because in the case of atomic queries it produces a rewriting as an RPQ which can be evaluated inNLOGSPACE.

Related work. Query rewriting has been extensively employed in query answering under ontologies [10, 16, 15]. In particular, [17] presents a resolution-based query rewriting algorithm for DL-Lite+ ontologies (which is EL`in), with Linear Datalog as target language. In [3] the authors introduce a backward chaining mechanism to identify decidable classes of tuple-generating dependencies. Tractable query rewriting (in NLOGSPACE) for the DL-Lite family was presented in [9]; similarly, Rosati [18] used a rewriting algorithm for DL TBoxes expressed in theELfamily of languages [1] to show that query answering in EL is PTIME-complete in data complexity. Other works [5, 6] study FO-rewritability of conjunctive queries in the presence of ontolo-gies formulated in a description logic betweenELand Horn-SHIF, along with related query containment problems. In [12, 11] the authors propose an algorithm for comput-ing FO rewritcomput-ings of concept queries underELTBoxes that is tailored towards efficient implementation. The tree-witness technique adopted in this paper is derived from that of [13, 14], which address query rewriting overEL,QLandRL, and propose the tree-witness approach to rewriteQL. The complexity of answering CRPQs under DL-Lite andELfamilies is studied in [7].

(16)

syntactic properties that would still guarantee rewritability of CQs into CRPQs; note that the ontology language so defined subsumesQL;(3)we intend to include complex role chains and unions in the language, as in [15]. We already have results on(1)and(3).

Acknowledgments. We thank Michael Zakharyaschev and Roman Kontchakov for pre-cious discussions about this material.

References

1. Baader, F., Brandt, S., Lutz, C.: Pushing the EL envelope. In: IJCAI (2005)

2. Baader, F., Nutt, W.: Basic description logics. In: Description logic handbook. pp. 43–95 (2003)

3. Baget, J.F., Leclre, M., Mugnier, M.L., Salvat, E.: On rules with existential variables: Walk-ing the decidability line. Artificial Intelligence 175(9), 1620–1654 (2011)

4. Barcelo, P., Libkin, L., Lin, A.W., Wood, P.T.: Expressive languages for path queries over graph-structured data. TODS 37(4), 31 (2012)

5. Bienvenu, M., Hansen, P., Lutz, C., Wolter, F.: First order-rewritability and containment of conjunctive queries in horn description logics. In: DLOG (2016)

6. Bienvenu, M., Lutz, C., Wolter, F.: First-order rewritability of atomic queries in horn descrip-tion logics. In: IJCAI (2013)

7. Bienvenu, M., Ortiz, M., Simkus, M.: Conjunctive regular path queries in lightweight de-scription logics. In: IJCAI (2013)

8. Bourhis, P., Kr¨otzsch, M., Rudolph, S.: Reasonable highly expressive query languages. In: IJCAI (2015)

9. Calvanese, D., De Giacomo, G., Lembo, D., Lenzerini, M., Rosati, R.: Tractable reasoning and efficient query answering in description logics: The DL-lite family. Journal of Automated Reasoning 39(3), 385–429 (2007)

10. Gottlob, G., Orsi, G., Pieris, A.: Ontological queries: Rewriting and optimization. In: ICDE (2011)

11. Hansen, P., Lutz, C., Seylan, I., Wolter, F.: Query rewriting under EL TBoxes: Efficient algorithms. In: Description Logics (2014)

12. Hansen, P., Lutz, C., Seylan, I., Wolter, F.: Efficient query rewriting in the description logic EL and beyond. In: IJCAI (2015)

13. Kikot, S., Kontchakov, R., Zakharyaschev, M.: Conjunctive Query Answering with OWL 2 QL. In: KR (2012)

14. Kontchakov, R., Zakharyaschev, M.: An introduction to description logics and query rewrit-ing. Reasoning Web. Reasoning on the Web in the Big Data Era (2014)

15. Mosurovic, M., Krdzavac, N., Graves, H., Zakharyaschev, M.: A decidable extension of SROIQ with complex role chains and unions. JAIR 47, 809–851 (2013)

16. P´erez-Urbina, H., Horrocks, I., Motik, B.: Efficient query answering for OWL 2. In: ISWC (2009)

17. P´erez-Urbina, H., Motik, B., Horrocks, I.: Rewriting conjunctive queries over description logic knowledge bases. In: Semantics in Data and Knowledge Bases (2008)

Figure

Fig. 1. NFA for Example 5.

References

Related documents

Plan Rewriting. The key point is careful and generic query plan rewriting. DataCell takes as input the query plans that the SQL en- gine creates, leveraging the algebraic

By designing the primers to read outward from IS elements, five different putative composite transposons were identified from human oral metagenomic DNA, each containing different

After: Once a patch is deployed, the Endpoint Manager agent automatically and continuously reassesses the endpoint status to confirm successful installation, immediately updating

After: With Tivoli Endpoint Manager, a single intelligent soft- ware agent is installed on all managed endpoints to continuously monitor and report endpoint state, including

Studying health narratives not only may help healthcare providers fix communication problems within a particular user population, but will help populations of patients and

Validity and reliability of a medical record review method identifying transitional patient safety incidents in merged primary and secondary care patients’ records.. To view

This study investigated the time course effect of lipopolysaccharide (LPs) on the steroidogenesis and mRNa expression of Toll-like receptors (TLRs), a class of key pattern

The25(OH)vitD levels from the present PICU patients were compared with the 25(OH)vitD levels that were obtained as part of a study on vitamin D status that is cur- rently