\documentclass{article}

\usepackage{pjmnotes}
\usepackage{a4wide}
\usepackage{casetool}
\usepackage{stdpjm}
\usepackage{hdm}
\usepackage{ukdate}

\def\automed{\textsc{AutoMed}}

\title{A Simple Case Study for Schema Integration Tools\\[1em]
\large  AutoMed Technical Report 1, Version 1}

\author{Peter \mcbrien}

\begin{document}

\maketitle

%\def\card#1#2{\textsf{#1:#2}}
\bibliographystyle{plain}

\section{Introduction}
%%%%%%%%%%%%%%%%%%%%%%

The purpose of this document is to record a simple small example of
database schema integration, which contains enough complexity to test
all key aspects of the AutoMed achitecture \cite{MP00c} as it is
developed. In particular, the example is used to test the
representation of modelling languages in the MDR and schemas and
transformations in the STR of the AutoMed repositories
\cite{BMT02,BMT03}. The example is a development of that presented in
\cite{MP99b}, and is presented in Figure~\ref{four-er} as three
extensional databases (\ie are actual databases with stored data)
\texttt{s1}, \texttt{s2} and \texttt{s3} in a variant of the ER
modelling langauge.


\begin{stdtable}{Constructs and declarative semantics of an 
entity-relationship model}{er-language-table}

\stdpicmag{-2}
\def\boxit(#1,#2)#3{\inlineblock{\qpic(#1,#2){\putbox(0,0)(#1,#2){#3}}}}
\def\tabtext#1{#1}

\begin{tabular}{ccp{3in}}
\rowcolor{header} Name & Symbol & Description \\ \hline
\boxit(8,5){entity set} & \qpic(8,4){\entity(0,0){e}} &
\begin{minipage}{0.5\textwidth}
Describes a set of entities in the UoD which share some
common properties. We denote the entity by the scheme \hdmn{e} 
and can enumerate the values of the entity in variable $x$ by the
expression $x \iqlin \hdmn{e}$.
\end{minipage}
\\ 

\rowcolor{evenrow}
\boxit(8,4){attribute} &
\qpic(8,4){\attribute(0,2)(6,2){a}} &
\begin{minipage}{0.5\textwidth}
A set of attributes which are of a certain type, and are
associated with members of an entity set. We denote the attribute by
the scheme \hdms{e,a}.

Each instance of the entity must be associated an instance of the
attribute, and we can emumerate. We can enumerate the values of the
association be entity and attributes by the expression
$\iqltuple{x,y} \iqlin \hdme{e,a}$.
\end{minipage} \\

\boxit(8,4){key attribute} & \qpic(8,4){%\candkey(0,1)(4,2)
\keyattribute(0,2)(6,2){a}} &  An attribute which
forms part of the key for the entity. \\ 

\rowcolor{evenrow}
\boxit(8,4){null attribute} & \qpic(8,4){%\candkey(0,1)(4,2)
\nullattribute(0,2)(6,2){a}} &  An attribute for which
not every instance of \hdmn{e} appears as instance of \hdmn{a}. \\ 

\boxit(8,12){subset}               & \qpic(8,12){\entity(0,0){$\mathsf{e_s}$}
\isa(4,4)(4,8)\entity(0,8){e}} & \tabtext{Denotes that any instance
of the \keyword{subset entity} \hdmn{e_s} is also a member of the
\keyword{superset entity} \hdmn{e}. } \\ 

\rowcolor{evenrow}
\boxit(9,13){generalisation}       & \qpic(18,14){\isa(9,8)(9,9)
\entity(5,9){$e$}\generalisation(6,6){$g$}
\path(4,4)(4,5)(14,5)(14,4)\path(9,5)(9,6)
\entity(0,0){$e_1$}\putbox(8,0)(2,4){\ldots}\entity(10,0){$e_n$}} &
\begin{minipage}{0.5\textwidth}
Denotes a series of subset entities \hdmn{e_1} \ldots \hdmn{e_n} of
superset \hdmn{e}, which have the additional property that the instances of
\hdmn{e} must be also instances of exactly one of \hdmn{e_1} \ldots \hdmn{e_n}.


If an asterisk is put by the $g$, then the above is relaxed such that
some instances of $e$ may exist
which are not instances of \hdmn{e_1} \ldots \hdmn{e_n}.
\end{minipage}\\

\boxit(8,16){relationship}        &
\qpic(8,16){\relationship(4,4)(4,12){$r$}{$l_1$:$u_1$~~~~}{~~~~$l_2$:$u_2$}
\entity(0,0){$\mathsf{e_1}$}\entity(0,12){$\mathsf{e_2}$}} 
& \begin{minipage}{0.5\textwidth}
A set 
of binary relationships between entities, where the relationships are
all of a certain type. We denote the relationship by \hdme{r,e_1,e_2}.

The cardinality
constraint $l_1$:$u_1$ gives the minimum and maximum number of instances of
$e_2$ 
that may be associated with any one instance $e_1$, and $l_2$:$u_2$
gives the minimum and maximum number of $e_1$ instances that may be
associated to a particular instance of $e_2$. 

We can enumerate the values of the
association be entity and attributes by the expression
$\iqltuple{x,y} \iqlin \hdme{r,e_1,e_2}$.
\end{minipage}

\end{tabular}

\end{stdtable}

The version of the ER modelling langauge we shall be using is given in
Table~\ref{er-language-table}. It a slight extention of the ER
language used in the well-known survey paper on schema integration
\cite{Bat86}, and similar to the well known
\keywordabbr{enhanced-ER}{EER} model \cite{EN00}.
The key features of this ER modelling langauge are that

\begin{itemize}

\item only binary relationships
are permitted,

\item relationships may not have an attribute added, 

\item attributes may be key, notnull or null, and

\item generalisations may be
total or partial.

\end{itemize}

The following sections present a number of integration scenarios, which
illustrate common techniques used in the BAV approach.

\section{Integration of Two Instance Equivalent Schemas}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Suppose that it can be determined that the \textsf{staff} entity
in \textsf{s1} always contains the same set of people as the \textsf{person}
entity in \textsf{s2}, and that the \textsf{id} key of \textsf{staff}
is the same type as the \textsf{pid} attribute of \textsf{person}. It follows
the we have a synonym conflict between the schemas, and should rename
\textsf{staff} to \textsf{person} (or \textit{visa versa}) and rename
\textsf{pid} to \textsf{id} (or \textit{visa versa}).

Also suppose that it can be determined that the instances of the
\textsf{dept} entity (and hence its \textsf{dname} key attribute) in
\textsf{s1} are always the same set as the values of the
\textsf{dname} attribute of \textsf{person} in \textsf{s2}. It follows
that we have a structural conflict between the schemas, and should
transform the \textsf{dname} attribute in \textsf{s2} into a new
entity \textsf{dept} and key attribute \textsf{dname} connected to
\textsf{person} by a relationship called \textsf{worksin}. In this
particular example, we could alternatively have transformed the
\textsf{worksin} relationship, \textsf{dept} entity and \textsf{dname}
key attribute into a single \textsf{dname} attribute of
\textsf{staff}, but this would not be the case if the \textsf{dept}
entity had any other associations (\ie it had any other attributes,
relationships, subset involvements or generalisation involvements).
 
Finally, suppose that it can be determined that the instances of the
\textsf{sex} attribute of \textsf{staff} in \textsf{s1} only takes the
string values \textsf{`m'} and \textsf{`f'}, and that always the set
of \textsf{staff} which have the value \textsf{`m'} is the same as the
set of \textsf{male} in \textsf{s2}, and the set of \textsf{staff}
which have the value \textsf{`f'} is the same as the set of
\textsf{female}. It follows
that we have a structural conflict between the schemas, and should
transform the \textsf{sex} attribute of \textsf{staff} into a total
generalisation hierarchy with two subset entities \textsf{male} and
\textsf{female}. In this particular case, we could alternatively have made the
inverse transformation on \textsf{male} and \textsf{female} in \textsf{s2}
since they have no other associations.

\begin{stdfigure}
{Example ER schemas, and the transformations that relate
them}{four-er}

\stdpicmag{-2}
\small

\def\schema(#1,#2)(#3,#4)#5#6{\setlength{\fboxsep}{0em}
\put(#1,#2){\colorbox{er}{\makebox(#3,#4){}}}
\put(#1,#2){\begin{picture}(#3,#4)
#6
\end{picture}}
\put(#1,#2){\makebox(2,2){\textsf{#5}}}}

\begin{picture}(54,91)
\schema(0,72)(22,19){s1}{\entity(12,2){staff}
\attribute(12,6)(8,7){sex}
\attribute(12,4)(8,4){name}
\keyattribute(12,2)(8,1){id}
\relationship(16,6)(16,14){\small worksin}{1:1}{1:N}
\entity(12,14){dept}
\keyattribute(12,16)(8,16){dname}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\schema(26,72)(28,18){s2}{\entity(10,13){person}
\entity(5,1){male}
\entity(15,1){female}
\generalisation(11,9){sex}
\path(9,5)(9,7)(19,7)(19,5)
\path(14,7)(14,9)
\isa(14,11)(14,13)
\keyattribute(10,14)(6,13){pid}
\attribute(10,16)(6,17){name}
\attribute(18,15)(22,15){dname}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\schema(3,0)(48,18){s3}{\entity(10,13){person}
\entity(5,1){male}
\entity(15,1){female}
\generalisation(11,9){sex}
\path(9,5)(9,7)(19,7)(19,5)
\path(14,7)(14,9)
\isa(14,11)(14,13)
\keyattribute(10,15)(6,15){id}
\relationship(18,15)(30,15){\small worksin}{1:1}{1:N}
\entity(30,13){dept}
\keyattribute(38,15)(42,15){dname}
\relationship(34,5)(34,13){runby}{1:1}{1:N}
\entity(30,1){degree}
\keyattribute(38,4)(42,5){code}
\attribute(38,2)(42,1){title}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\schema(3,48)(48,18){s4}{\entity(10,13){person}
\entity(5,1){male}
\entity(15,1){female}
\generalisation(11,9){sex}
\path(9,5)(9,7)(19,7)(19,5)
\path(14,7)(14,9)
\isa(14,11)(14,13)
\keyattribute(10,14)(6,13){id}
\attribute(10,16)(6,17){name}
\relationship(18,15)(30,15){\small worksin}{1:1}{1:N}
\entity(30,13){dept}
\keyattribute(38,15)(42,15){dname}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\schema(3,24)(48,18){s5}{\entity(10,13){person}
\entity(5,1){male}
\entity(15,1){female}
\generalisation(11,9){sex}
\path(9,5)(9,7)(19,7)(19,5)
\path(14,7)(14,9)
\isa(14,11)(14,13)
\keyattribute(10,14)(6,13){id}
\attribute(10,16)(6,17){name}
\relationship(18,15)(30,15){\small worksin}{1:1}{1:N}
\entity(30,13){dept}
\keyattribute(38,15)(42,15){dname}
\relationship(34,5)(34,13){runby}{1:1}{1:N}
\entity(30,1){degree}
\keyattribute(38,4)(42,5){code}
\attribute(38,2)(42,1){title}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\labvector(10,71)(10,67){\snsref{sonea} .. \snsref{sonee}}{}
\labvector(14,67)(14,71){}{\isnsref{sonee} .. \isnsref{sonea}}
\labvector(38,71)(38,67){\snsref{stwoa} .. \snsref{stwoe}}{}
\labvector(42,67)(42,71){}{\isnsref{stwoe} .. \isnsref{stwoa}}
\labvector(25,47)(25,43){\snsref{sfoura} .. \snsref{sfourd}}{}
\labvector(29,43)(29,47){}{\isnsref{sfourd} .. \isnsref{sfoura}}
\labvector(25,23)(25,19){\isnsref{sthreea}}{}
\labvector(29,19)(29,23){}{\snsref{sthreea}}
\end{picture}

\end{stdfigure}

Given these suppositions, we can use the following transformations to
transformation \textsf{s1} and \textsf{s2} into a new global schema
\textsf{s4}. The queries of the transformations use the AutoMed IQL
language \cite{JPZ03}. The semantics of \snsref{soneb} are that the
extent of \hdmn{male} is a list of unary tuples, taken as the
projection of the first attribute of the tuples of \hdme{person,sex}
where the second attribute equates to the value \iqlstr{m}. The
semantics of \snsref{sonee} are that the binary tuples for the
\hdme{person,sex} attribute can be covered by associating the first
attribute of the tuple an instance of \hdmn{male} and the second to
the string constant \iqlstr{m}, concatenated (by the \iqlappend\
operator) with associating the first attribute to an instance of
\hdmn{female} and the second to \iqlstr{f}. Note that \snsref{sonee}
has also a constraint added to it, stating that this transformation is
only valid when the extent of \hdme{person,sex} is just
\iqllist{\iqlstr{m},\iqlstr{f}}.

\begin{snstranslist}
& \mathsf{s1 \rightarrow s4}  \\
\snslabel{sonea} & renameEntity(\hdmn{staff},\hdmn{person}) \\
\snslabel{soneb} & addEntity(\hdmn{male}, \iqllist{\iqltuple{x} \mid 
\iqltuple{x,y} \iqlin \hdme{person,sex}; \iqlfunc{=}{y}{\iqlstr{m}}}) \\
\snslabel{sonec} & addEntity(\hdmn{female}, \iqllist{\iqltuple{x} \mid 
\iqltuple{x,y} \iqlin \hdme{person,sex}; \iqlfunc{=}{y}{\iqlstr{f}}}) \\
\snslabel{soned} & addGeneralisation(sex,total,person,male,female) \\
\snslabel{sonee} & delAttribute(\hdms{person,sex},\\
& \iqlindent
\iqllist{\iqltuple{x,y} \mid \iqltuple{x} \iqlin \hdmn{male}; 
 \iqlfunc{=}{y}{\iqlstr{m}}} \iqlappend 
\iqllist{\iqltuple{x,y} \mid \iqltuple{x} \iqlin \hdmn{female}; 
 \iqlfunc{=}{y}{\iqlstr{f}}})\\
& \iqlindent
(\iqllist{\iqlstr{m},\iqlstr{f}}=\iqllist{\iqltuple{x} \mid 
\iqltuple{x,y} \iqlin \hdme{person,sex}})
\end{snstranslist}

\begin{snstranslist}
& \mathsf{s2 \rightarrow s4}  \\
\snslabel{stwoa} & addEntity(\hdmn{dept},
\iqllist{\iqltuple{y} \mid \iqltuple{x,y} \iqlin \hdme{person,dname}}) \\
\snslabel{stwob} 
& addAttribute(\hdmn{dept,dname,key},
\iqllist{\iqltuple{y,y} \mid \iqltuple{x,y} \iqlin \hdme{person,dname}}) \\
\snslabel{stwoc} 
& addRelationship(\hdms{worksin,person,dept,\card{1}{1},\card{1}{N}},
\iqllist{\iqltuple{x,y} \mid \iqltuple{x,y} \iqlin \hdme{person,dname}}) \\
\snslabel{stwod} 
& delAttribute(\hdms{person,dname,notnull},
\iqllist{\iqltuple{x,y} \mid \iqltuple{x,y} \iqlin 
  \hdme{worksin,person,dept}}) \\
\snslabel{stwoe} & renameAttribute(\hdms{person,pid,key},\hdms{person,id,key})
\end{snstranslist}

\section{Integration of Overlapping Schemas}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Suppose it can be determined that all schema components that appear in both
\textsf{s4} and \textsf{s3} always share the same sets of values, \ie
the entity \textsf{person} in \textsf{s4} has the same set of values as
\textsf{person} in \textsf{s3}, the attribute \textsf{id} in  \textsf{s4} 
has the same set of values as \textsf{id} in  \textsf{s3}, \etc.

Also suppose that it can be determined that any construct that does
not appear in one schema cannot be derived from the remaining
components in that schema, \ie the extention of the missing
\textsf{name} attribute of \textsf{person} in \textsf{s3} cannot be
derived from any other components in \textsf{s3}, and the extention of
the missing \textsf{degree} entity and associted constructs in
\textsf{s4} cannot be derived from any other constructs in
\textsf{s4}.

Given these suppositions, we can the use \textsf{extend} transformations
to build a new global schema \textsf{s5} that contains all information
available from the three extentional schemas \textsf{s1}, \textsf{s2} and
\textsf{s3}.

\begin{snstranslist}
& \mathsf{s3 \rightarrow s5}  \\
\snslabel{sthreea} & extendAttribute(\hdme{person,name,notnull}) \\
\end{snstranslist}

\begin{snstranslist}
& \mathsf{s4 \rightarrow s5}  \\
\snslabel{sfoura} & extendEntity(\hdmn{degree}) \\
\snslabel{sfourb} & extendAttribute(\hdme{degree,code,key}) \\
\snslabel{sfourc} & extendAttribute(\hdme{degree,title,notnull}) \\
\snslabel{sfourd} & extendRelationship(\hdme{runby,degree,dept})
\end{snstranslist}

Note that these transformations may be composed to form a direct
transformation from \textsf{s3} to \textsf{s4} as follows (where
white on black text for the transformation number indicates an inverse
of the black on white transformation):

\begin{snstranslist}
& \mathsf{s3 \rightarrow s4}  \\
\snsref{sthreea} & extendAttribute(\hdme{person,name,notnull}) \\
\isnsref{sfourd} & contractRelationship(\hdme{runby,degree,dept}) \\
\isnsref{sfourc} & contractAttribute(\hdme{degree,title,notnull}) \\
\isnsref{sfourb} & contractAttribute(\hdme{degree,code,key}) \\
\isnsref{sfoura} & contractEntity(\hdmn{degree}) 
\end{snstranslist}


\section{Relational Models and Sample Data}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Figure~\ref{three-rel} illustrates three relational schemas equivalent to
the three EDB schemas of Figure~\ref{four-er}, on the basis that the
ER modelling language being used identifies instances of entities by
using the key attribute of the entity.

\begin{stdfigure}{Relational models and data}{three-rel}

\subtable[s1]{
\begin{tabular}{rlll} 
\multicolumn{4}{>{\columncolor{tablename}}c}{staff} \\ 
\rowcolor{columnname}
\underline{id} & name & sex & workins \\
1 & Alex & F & CS-BBK \\
2 & Dimitri & M & CS-BBK\\
3 & Mike & M & Comp-IC \\
4 & Nerissa & F & Comp-IC \\
5 & Peter & M & Comp-IC
\end{tabular}
\hspace{1em}
\begin{tabular}{l} 
\multicolumn{1}{>{\columncolor{tablename}}c}{dept} \\ 
\rowcolor{columnname}
\underline{dname} \\
CS-BBK \\
Comp-IC \\
\\
\\
\\
\end{tabular}}

\subtable[s2]{
\begin{tabular}{rll} 
\multicolumn{3}{>{\columncolor{tablename}}c}{person} \\ 
\rowcolor{columnname}
\underline{pid} & name & dname \\
1 & Alex & CS-BBK \\
2 & Dimitri & CS-BBK\\
3 & Mike & Comp-IC \\
4 & Nerissa & Comp-IC \\
5 & Peter & Comp-IC
\end{tabular}
\hspace{1em}
\begin{tabular}{l} 
\multicolumn{1}{>{\columncolor{tablename}}c}{male} \\ 
\rowcolor{columnname}
\underline{id} \\
2 \\
3 \\
5 \\
\\
\\
\end{tabular}
\hspace{1em}
\begin{tabular}{l} 
\multicolumn{1}{>{\columncolor{tablename}}c}{female} \\ 
\rowcolor{columnname}
\underline{id} \\
1 \\
4 \\
\\
\\
\\ 
\end{tabular}}

\subtable[s3]{\shortstack{
\begin{tabular}{rl} 
\multicolumn{2}{>{\columncolor{tablename}}c}{person} \\ 
\rowcolor{columnname}
\underline{id} & worksin \\
1 & CS-BBK \\
2 & CS-BBK\\
3 & Comp-IC \\
4 & Comp-IC \\
5 & Comp-IC
\end{tabular}
\hspace{1em}
\begin{tabular}{l} 
\multicolumn{1}{>{\columncolor{tablename}}c}{male} \\ 
\rowcolor{columnname}
\underline{id} \\
2 \\
3 \\
5 \\
\\
\\
\end{tabular}
\hspace{1em}
\begin{tabular}{l} 
\multicolumn{1}{>{\columncolor{tablename}}c}{female} \\ 
\rowcolor{columnname}
\underline{id} \\
1 \\
4 \\
\\
\\
\\ 
\end{tabular}
\\
\begin{tabular}{l} 
\multicolumn{1}{>{\columncolor{tablename}}c}{dept} \\ 
\rowcolor{columnname}
\underline{dname} \\
CS-BBK \\
Comp-IC \\
\\
\end{tabular}
\hspace{1em}
\begin{tabular}{lll} 
\multicolumn{3}{>{\columncolor{tablename}}c}{degree} \\ 
\rowcolor{columnname}
\underline{dcode} & title & runby \\
1234 & MSc Computing & CS-BBK \\
G500 & BEng Computing & Comp-IC \\
G500 & MEng Computing & Comp-IC
\end{tabular}}}

\end{stdfigure}

Given this relational model and data we can derive instances of the
ER model. For example, \textsf{s2} has the following extent:

\begin{math}
\begin{array}{l}
\hdmn{person} = 
\iqllist{\iqltuple{1},\iqltuple{2},\iqltuple{3},\iqltuple{4},\iqltuple{5}}\\
\hdmn{person,pid} = 
\iqllist{\iqltuple{1,1},\iqltuple{2,2},\iqltuple{3,3},%
\iqltuple{4,4},\iqltuple{5,5}}\\
\hdmn{person,name} = 
\iqllist{\iqltuple{1,\iqlstr{Alex}},\iqltuple{2,\iqlstr{Dimitri}},%
\iqltuple{3,\iqlstr{Mike}},%
\iqltuple{4,\iqlstr{Nerissa}},\iqltuple{5,\iqlstr{Peter}}}\\
\hdmn{person,dept} = \\
\iqlindent
\iqllist{\iqltuple{1,\iqlstr{CS-BBK}},\iqltuple{2,\iqlstr{CS-BBK}},%
\iqltuple{3,\iqlstr{Comp-IC}},%
\iqltuple{4,\iqlstr{Comp-IC}},\iqltuple{5,\iqlstr{Comp-IC}}}\\
\hdmn{male} = 
\iqllist{\iqltuple{2},\iqltuple{3},\iqltuple{5}}\\
\hdmn{female} = 
\iqllist{\iqltuple{1},\iqltuple{4}}
\end{array}
\end{math}

\bibliography{database}

\end{document}