# Acquiring Ontology Axioms through Mappings to Data Sources +
## 5 Query Answering
### Query Rewriting  
The basic idea of our technique is to reduce the computation of the perfect rewriting of an IHUCQ over a \(\mathit{DL}\text{-}\mathit{Lite}_{\mathcal{R}}\) TBox to the computation of the perfect rewriting of an UCQ over a \(\mathit{DL}\text{-}\mathit{Lite}_{\mathcal{R}}\) TBox, which can be then done by using the algorithm _PerfectRef_ described in [23]. To this aim, we first transform the IHUCQ into a standard UCQ, actually an EUCQ. This is realized through a first partial grounding of the query, using the function \(\mathit{PMG}\) and then through the functions _Normalize_ and \(\tau\). In particular, the function \(\mathit{PMG}\) eliminates the meta-variables, i.e., the variables occurring as a concept or as a role argument, from the query, _Normalize_ substitutes \(\mathit{Inst}_{C}\) atoms whose second argument is of the form \(\mathit{Exists}(e)\) into \(\mathit{Inst}_{R}\) atoms (i.e., the instance of the domain or the range of a role expression \(e\) is reformulated as an instance of \(e\)), and \(\tau\) transforms \(\mathit{Inst}_{C}\) and \(\mathit{Inst}_{R}\) atoms in DL atoms. Afterwards, the query resulting from the perfect rewriting of the EUCQ is transformed back into an IHUCQ, by the functions _Denormalize_ and \(\tau^{-}\). This is because the third step of the query answering algorithm assumes the query to be an IHUCQ. We now describe in more detail the functions _PMG_, _Normalize_, _Denormalize_, \(\tau\) and \(\tau^{-}\). If \(q,q^{\prime}\) are two IHCQs, and \(\mathcal{T}\) is a TBox, then \(q^{\prime}\) is a _partial metagrounding of \(q\) with respect to \(\mathcal{T}\)_ if \(q^{\prime}=\sigma(q)\), where \(\sigma\) is a partial substitution of the meta-variables of \(q\) with the expressions occurring in \(\mathcal{T}\) such that, for each meta-variable \(x\) of \(q\), either \(\sigma(x)=x\) or:  
* if \(x\) occurs in a concept position in \(q\), then \(\sigma(x)\in\mathit{Concepts}(\mathcal{T})\);
* if \(x\) occurs in a role position in \(q\), then \(\sigma(x)\in\mathit{Roles}(\mathcal{T})\). Given an IHCQ \(q\) and a TBox \(\mathcal{T}\), the function _PMG_ applied to \(q\) and \(\mathcal{T}\) computes the set of all partial metapgroundings of \(q\) with respect to \(\mathcal{T}\), i.e., it computes the IHUCQ \(Q=\{q^{\prime}\mid q^{\prime}\) is a partial metapgrounding of \(q\) w.r.t. \(\mathcal{T}\}\). When applied to an IHUCQ \(Q\) and a TBox \(\mathcal{T}\), the function _PMG_ computes the IHUCQ \(\bigcup_{q\in Q}\mathit{PMG}(q,\mathcal{T})\). **Example 6**. : _Consider the MKB \(\mathcal{K}=\langle\mathcal{D},\mathcal{M}\rangle\) given in Example 4, the TBox \(\mathcal{T}\) dynamically constructed from \(\mathcal{D}\) through \(\mathcal{M}\), and represented in Figure 6, and the query (i) given in Example 5. Then, \(\mathit{Concepts}(\mathcal{T})=\{Car,Coupe,Ford,\dots,1973\)ALCONIBGTCOPE,\dots,Exists(produced\_in),\dots\}\), \(\mathit{Roles}(\mathcal{T})=\{produced\_in,Inv(produced\_in)\}\), and \(\mathit{PMG}(q,\mathcal{T})\), contains, among other queries, the query:_  
\[q(x)\leftarrow\mathit{Inst}_{C}(x,Ford),\mathit{Inst}_{C}(x,\mathit{FALCON}), \mathit{Inst}_{C}(\mathit{FALCON},Coupe),\mathit{Inst}_{R}(x,\textsc{australia}, \text{produced\_in}) \tag{1}\]  
_where we abbreviated 1973 FALCONIBGTCOPE into FALCON (to obtain all other queries in \(\mathit{PMG}(q,\mathcal{T})\) substitute FALCON with all elements of \(\mathit{Concepts}(\mathcal{T})\))._  
Notice that the notion of partial metagrounding _PMG_ is crucial for our rewriting method. Indeed, even if in \(\mathit{Hi}(\mathit{DL\_Lite}_{\mathcal{R}})\) the set of expressions that can be constructed from a finite set of names occurring in the TBox is infinite, we can in fact limit to ground the meta-variables in the query on a finite set of expressions only, as stated by the following lemma. **Lemma 1**.