%\documentclass{article}

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

%\title{The Model Definitions Repository\\
%\normalsize Technical Report Automed/2/1 (1st Draft)}

%\author{Michael Boyd}
 

%%% There 

%\begin{document}

%\bibliographystyle{alpha}

%\maketitle

\section{MDR Schema}
%%%%%%%%%%%%%%%%%%%%

\label{mdr-schema-sec}

Table~\ref{mdr-tab} lists the tables which make up the
\keywordabbr{model definitions repository schema}{MDR Schema}. Each
type of modelling language (for example ER, Relational, UML, \etc)
that may be held in the MDR will have one entry in the \keyword{model}
table, where the fields have the following meaning:

\begin{itemize}

\item \keyword{mid} is a numeric identifier for the modelling language,
used inside the MDR. 

\item \keyword{name} is the textual name the modelling langauge may be
referred to as in API calls made to the MDR.

\end{itemize}

\begin{stdtable}{Model Definitions Repository Schema}{mdr-tab}

\subtable[]{
\begin{tabular}{|ll|}
\hline \multicolumn{2}{|c|}{model} \\
\hline\hline \underline{mid} & integer \\
name & varchar \\
\hline
\end{tabular}}
\hspace{1em}
\subtable[]{\begin{tabular}{>{\bf}lll}
\multicolumn{3}{>{\columncolor{header}}c}{construct} \\
\underline{mid} 
& integer 
& references model \\
\rowcolor{evenrow}
\underline{cid} 
& integer 
& \\
name 
& varchar  
& \\
\rowcolor{evenrow}
class 
& \multicolumn{2}{>{\columncolor{evenrow}}l}{ $(\textrm{Nodal} \mid
\textrm{Link} \mid \textrm{Link-Nodal} \mid \textrm{Constraint})$ } \\
isRoot 
& boolean 
& 
\end{tabular}}

\subtable[]{\begin{tabular}{|lll|}
\hline \multicolumn{3}{|c|}{scheme} \\
\hline\hline \underline{mid} & integer & references model \\
\underline{cid} & integer & \\
\underline{pos} & integer & \\
type & 
\multicolumn{2}{l|}{ (Name $|$ Construct $|$ Alternation $|$ Sequence) } \\
argMid 
& integer & \\
argCid 
& integer 
& \\
isKey 
& boolean 
& \\
HdmType & \multicolumn{2}{l|}{ ($N_{1} \mid P_{1} \mid N_{2} \mid P_{2} 
\mid C$) } \\
lower & integer & \\
upper & integer & \\
\hline
\multicolumn{3}{|l|}{ (mid, cid) references construct } \\
\multicolumn{3}{|l|}{ (argMid, argCid) references scheme } \\
\hline
\end{tabular}}

\end{stdtable}

The \keyword{construct} relation has one tuple per modelling language
construct.  Examples of modelling language constructs are entities,
attributes, relationships etc.  The class field determines the
correspondence between the construct and its representative HDM.  This
determines, via the HDM template below, what values the HdmType field
may take in this construct's different scheme positions.  Note that
all HDM types may have constraints associated with them; the
constraint HDM type serves to model a constaint alone.


\begin{stdtable}{HDM Types supported by the MDR}{mdr-hdmtypes-tab}

\begin{tabular}{l|l}
\multicolumn{1}{c|}{class} & \multicolumn{1}{c}{HDM Template} \\
\hline Nodal & $\hdms{N_{1}}$ \\
Link & $\hdms{N_{1}, P_{1}, P_{2}}$ \\
Link-Nodal & $\hdms{N_{1}, P_{1}, N_{2}}$ \\
Contstraint & $X$ \\
\end{tabular}

\end{stdtable}

Each construct has a number of scheme tuples associated with it.  Each
scheme tuple corresponds to one argument in the constructor for its
construct.  The HdmType of an argument must be either constraint or
one of the types in the HDM template for the class of the associated
construct.  If the type is name then argMid and argCid have no meaning and
the only HDM type allowed (other than constraint) is $N_{i}$.
Otherwise, they refer to another construct and the only allowable HDM
type is $P_{i}$.  Fields lower and upper determine how many times the
scheme argument can be repeated, repetitions are comma seperated and
together form the HDM type $N_{i}$ or $P_{i}$.  When (argCid, argMid)
refer to another construct, all schemes for the construct with isKey
true must be named to uniquely identify it.  If upper is less than lower
(typically lower = 1, upper = 0) then there is no upper bound. 

The type construct simply means that this argument must refer to an
existing construct of the type referred to by argCid and argMid.  The
type alternation means that any one of the schemes of the construct
referred to can appear as the argument.  It could be used, for
instance to state that an attribute is always associated with an
existing entity or relationship.  In this case the construct that is
referenced would have two scheme arguments of type construct and it
would probably have isRoot set to false as it is unlikely to be a
construct of the modelling language itself.  The type sequence is
similar to alternation, the difference being that all the scheme
arguments of the referenced construct, in order, make up the scheme
argument.

\section{ER Example}
%%%%%%%%%%%%%%%%%%%%

\label{er-example-sec}

Figure~\ref{mdr-er-example-fig} is an example of how to represent
simple \keywordabbr{entity relationship}{ER} \cite{Che76}, which
contains entities, simple attributes on entities, and binary
relationships without cardinality constraints.

\begin{stdfigure}{ER Model Represented in the MDR}{mdr-er-example-fig}



\begin{tabular}{|ll|}
\hline \multicolumn{2}{|c|}{model} \\
\hline \multicolumn{1}{|l}{mid} & \multicolumn{1}{|l|}{name} \\
\hline 1 & ER \\
\hline
\end{tabular}
\hspace{1em}
\begin{tabular}{|lllll|}
\hline \multicolumn{5}{|c|}{construct} \\
\hline \multicolumn{1}{|l}{mid} & \multicolumn{1}{|l}{cid} & \multicolumn{1}{|l}{name} &
\multicolumn{1}{|l}{class} & \multicolumn{1}{|l|}{isRoot} \\
\hline 1 & 1 & entity & Nodal & true \\
1 & 2 & attribute & Link-Nodal & true \\
1 & 3 & relationship & Link & true \\
\hline
\end{tabular}

\begin{tabular}{|llllllllll|}
\hline \multicolumn{10}{|c|}{scheme} \\
\hline \multicolumn{1}{|l}{mid} & \multicolumn{1}{|l}{cid} & \multicolumn{1}{|l}{pos} &
\multicolumn{1}{|l}{type} & \multicolumn{1}{|l}{argMid} & \multicolumn{1}{|l|}{argCid} & 
\multicolumn{1}{|l}{isKey} & \multicolumn{1}{|l}{HdmType} & \multicolumn{1}{|l}{lower} &
\multicolumn{1}{|l|}{upper} \\
\hline 1 & 1 & 1 & name & - & - & true & $N_{1}$ & 1 & 1 \\
1 & 2 & 1 & construct & 1 & 1 & true & $P_{1}$ & 1 & 1 \\
1 & 2 & 2 & name & - & - & true & $N_{2}$ & 1 & 1 \\
1 & 3 & 1 & name & - & - & true & $N_{1}$ & 1 & 1 \\
1 & 3 & 2 & construct & 1 & 1 & true & $P_{1}$ & 1 & 1 \\
1 & 3 & 3 & construct & 1 & 1 & true & $P_{2}$ & 1 & 1 \\
\hline
\end{tabular}

\end{stdfigure}

In this example there is a direct one-to-one correspondence between
the modelling language constructs and the HDM types.  Note that
although attribute has HDM type Link-Nodal, it has no $N_{1}$ in the
constructor.  This means that the HDM name of the edge between the
attribute node and entity node has no name.  E.g.

\vspace{0.3cm}

\begin{tabular}{l|l}
\multicolumn{1}{c|}{Construct} 
& \multicolumn{1}{c}{Resulting HDM} \\
\hline ER.entity(person) 
& \hdmn{person} \\
ER.attribute(person,age) 
& \hdme{null,person,age} \\
ER.entity(department) 
& \hdmn{department} \\
ER.relationship(works\_in,person,department) 
& \hdme{works\_in,person,deparment} \\
\end{tabular}

\vspace{0.3cm}

If we allow relationships between more than two entities then we
simply change the upper limit on scheme(1,3,2) or scheme(1,3,3) to 0.
If we also wanted to allow attributes on relationships then we need to
define an alternation for the attribute to refer to.

\vspace{0.3cm}

\begin{tabular}{|lllll|}
\hline \multicolumn{5}{|c|}{construct} \\
\hline \multicolumn{1}{|l}{mid} & \multicolumn{1}{|l}{cid} & \multicolumn{1}{|l}{name} &
\multicolumn{1}{|l}{class} & \multicolumn{1}{|l|}{isRoot} \\
\hline \vdots & \vdots & \vdots & \vdots & \vdots \\
1 & 4 & entity\_relationship & constraint & false \\
\hline
\end{tabular}

\vspace{0.3cm}

This defines the construct and states that it is not a user construct
of the modelling language.  The class constraint simply means that an
instance of this construct does not directly relate to any HDM.

\vspace{0.3cm}

\noindent We now need to define the alternatives for the construct.

\vspace{0.3cm}

\begin{tabular}{|llllllllll|}
\hline \multicolumn{10}{|c|}{scheme} \\
\hline \multicolumn{1}{|l}{mid} & \multicolumn{1}{|l}{cid} & \multicolumn{1}{|l}{pos} &
\multicolumn{1}{|l}{type} & \multicolumn{1}{|l}{argMid} & \multicolumn{1}{|l|}{argCid} & 
\multicolumn{1}{|l}{isKey} & \multicolumn{1}{|l}{HdmType} & \multicolumn{1}{|l}{lower} &
\multicolumn{1}{|l|}{upper} \\
\hline \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
1 & 4 & 1 & consruct & 1 & 1 & true & $C$ & 1 & 1 \\
1 & 4 & 2 & name & - & - & true & $C$ & 1 & 1 \\
\hline
\end{tabular}

\vspace{0.3cm}

Note that the construct itself is not defined as an alternation, a
reference to it specifies what its arguments mean.  Also note that
the HdmType is $C$, this simply means that there is no correspinding
HDM for this argument (as must be the case as the construct itself
is of type constraint).

\noindent We can now change the definition of attribiute so that the referenced
construct $P_{1}$ can be either an entity or relationship.

\vspace{0.3cm}

\begin{tabular}{|llllllllll|}
\hline \multicolumn{10}{|c|}{scheme} \\
\hline \multicolumn{1}{|l}{mid} & \multicolumn{1}{|l}{cid} & \multicolumn{1}{|l}{pos} &
\multicolumn{1}{|l}{type} & \multicolumn{1}{|l}{argMid} & \multicolumn{1}{|l|}{argCid} & 
\multicolumn{1}{|l}{isKey} & \multicolumn{1}{|l}{HdmType} & \multicolumn{1}{|l}{lower} &
\multicolumn{1}{|l|}{upper} \\
\hline \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
1 & 2 & 1 & consruct & 1 & 4 & true & $P_{1}$ & 1 & 1 \\
\vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
\hline
\end{tabular}

\vspace{0.3cm}

We can now add an attribute to the works\_in relationship.

\vspace{0.3cm}

\begin{small}
\begin{center}
\begin{tabular}{l|l}
\multicolumn{1}{c|}{Construct} & \multicolumn{1}{c}{Resulting HDM} \\
\hline ER.attribute((works\_in, person, department), salary) & $\ll null,\ll works\_in,person,deparment \gg,salary \gg$ \\
\end{tabular}
\end{center}
\end{small}

\vspace{0.3cm}

Note that we have to name all the key scheme positions of the relationship works\_in.

%\bibliography{database}

%\end{document}
