%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  ENTITY-RELATIONSHIP-RELATIONAL TRANSFORMATION EXAMPLE
%  Author: Jesus Almendros and Luis Iribarne. March 2012.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


 




 

%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% TRANSFORMATION EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%

%% TABLES

mmB:table(C) and mmB:name(C,B):-

                                         mmA:data(A) and mmA:container(A,B) and newURI(A,'table1',C).



mmB:table(D) and mmB:name(D,B):-mmA:navigable_role(C) and mmA:name(C,B) and newURI(C,'table2',D).
 

%%% ROWS

mmB:row(C) and mmB:name(C,B):-mmA:data(A) and mmA:name(A,B) and newURI(A,'row1',C).

mmB:row(G) and mmB:name(G,F):-mmA:navigable_role(C) and mmA:name(C,D) and                                                                   mmA:isdata(C,DT) and mmA:name(DT,B) and concatString(D,B,F)
                                               and newURI(C,'row2',G).

                              
%% COLS AND KEYS

mmB:col(D) and mmB:name(D,N) and mmB:type(D,T):-
                       mmA:data(A) and mmA:attr_of(A,B) and mmA:nonkeyAttribute(B)
                       and mmA:name(B,N) and
                       mmA:type(B,T) and newURI(B,'col',D).
 
mmB:key(D) and mmB:name(D,N) and mmB:type(D,T):-
                       mmA:data(A) and mmA:attr_of(A,B) and mmA:keyAttribute(B)
                       and mmA:name(B,N) and
                       mmA:type(B,T) and newURI(B,'key',D).


mmB:foreign(D) and mmB:name(D,K) and mmB:type(D,T):-
                  mmA:navigable_role(C) and
                  mmA:name(C,B) and mmA:isdata(C,DT) and mmA:name(DT,H) and
                  mmA:is(C,Q) and mmA:name(Q,F) and concatString(B,H,Aux) and concatString(Aux,F,K) and
                  mmA:type(Q,T) and newURI(C,'foreign1',D).

 
mmB:foreign(D) and mmB:name(D,K) and mmB:type(D,T):-
                  mmA:navigable_role(C) and
                  mmA:name(C,B) and mmA:isdata(C,DT) and mmA:name(DT,H) and
                  mmA:inv_qualifier_name(C,F) and concatString(B,H,Aux) and concatString(Aux,F,K) and
                  mmA:inv_qualifier_type(C,T) and newURI(C,'foreign2',D).                                
                      
% LINKS    

mmB:has(T,R):-mmA:data(A) and newURI(A,'table1',T) and newURI(A,'row1',R).
                   
mmB:has(T,R):-mmA:navigable_role(C) and newURI(C,'table2',T) and newURI(C,'row2',R).

mmB:is_col(R,CL):-mmA:data(A) and mmA:attr_of(A,B) and mmA:nonkeyAttribute(B)
                                     and newURI(A,'row1',R) and newURI(B,'col',CL).

mmB:is_key(R,K):-mmA:data(A) and mmA:attr_of(A,B) and mmA:keyAttribute(B)
                                   and newURI(A,'row1',R) and newURI(B,'key',K).

mmB:is_foreign(R,F):-mmA:navigable_role(C) and newURI(C,'row2',R) and newURI(C,'foreign1',F).

mmB:is_foreign(R,F):-mmA:navigable_role(C) and newURI(C,'row2',R) and newURI(C,'foreign2',F).