Appendix A TURBO PROLOG PROGRAM LISTING There are three types of files in this software (i) Files with extensions ".dba" eii) Files with extensions ".txt" (iii) Files with extensions ".pro These file stores the databases generated during the dialog. system generates two types of files: ·;l (i) Database name .dba For each database des i gned by the'· system, the database name and the list of user views during the design session are stored in this file. eii) View_name .dba : For each user view and for the intermediate' as well as for the final integrated view, the databases for thel prolog representation of the EER model are stored in these files. Every time the system is used for designing a new database , these files already created should be stored in some backup medias for letter use, and should be deleted from the current di rectory.
104
Embed
SCREEN3 .TXT ATT EG .TXT KEY EG .TXT BREL EG .TXT …shodhganga.inflibnet.ac.in/bitstream/10603/16108/14/14_appendices.pdf · Appendix A TURBO PROLOG PROGRAM LISTING There are three
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Appendix A
TURBO PROLOG PROGRAM LISTING
There are three types of files in this software
(i) Files with extensions ".dba"
eii) Files with extensions ".txt"
(iii) Files with extensions ".pro
These file stores the databases generated during the dialog. The~
system generates two types of files: .~ ·;l
(i) Database name .dba For each database des i gned by the'·
system, the database name and the list of user views
during the design session are stored in this file.
eii) View_name .dba : For each user view and for the intermediate'
as well as for the final integrated view, the databases for thel
prolog representation of the EER model are stored in these
files.
Every time the system is used for designing a new
database , these files already created should be stored in some
backup medias for letter use, and should be deleted from the
current di rectory. _'_~txt ~-.fjJe~
These files contains information such as examples,
introductions, etc. Which are to be displayed during the dialog.
TRANS. PRO Predicates in this file implement the view
translation algorithm, to translate a view from the EER model
into the relational model.
STEPS FOR USING THE ~YSTEM
1 . Ensure that all '. PRO' and 'TXT' files are in the same directory.
2. Enter the TURBO PROLOG (Version 2.0) environment. 3. Load the f; 1 e VMIT.PRO, and Compile using memory option, and
then select the RUN option. 4. Run the program and select option -1 fro the main-menu to
create\add views. 5. Select option 2 to integrate views created so far. 6. Select option 3 to translate the view from EER model into the
relational model to produce the database schema. 7. Select option 4 to exit the system.
3
1*************************************************************1 1* FILE: V"IT .PRO *1 1* *1 1* "ain Purpose: "ain program for the database design and *1 1* the menu driven controls for user interfaces. *1 1* *1 1* TOP LEVEL PREDICATE: v.it *1 1* */ 1*************************************************************/ code : 8000 include "vdo •. pro" include "utility.pro" include ~screen.pro" include "eer.pro" include "ent.pro" include "brel.pro" include "nrel.pro" include "card.pro" include "edit.pro" include "vI.pro" include "dbc.pro" predicates
go Vlit menu_ch(integer) lenu wait(integer)
Clauses go : -vlit. vlit :- clearwindow,lakewindo.(1,7,7,"" ,3,12,20,S2), file_str("open_scr.txt" ,A), .rite(A),nl,nl, .rite(" Press any key to continue .... "), readchar(_),clearwindow,file_str("scren1.txt" ,8), write(B),nl,write(" Press any key to continue .... "), readchar(_),clear.indow, file_str("scren2.txt" ,e), write(C),nl,nl, write(" Press any key to continue .... "), readchar(_),clearwindow, file_str("scren3.txt" ,0), write(O),nl, write(" Press any key to continue .... "), readchar(_),clearwindow, file_str("scren4.txt" ,E), write(E),nl, write(" Press any key to continue .... "), readchar(_),clearwindow, file_str("scren5.txt" ,F), write(F),nl, write(" Press any key to continue .... "), readchar(_),relovewindow,lenu. lenu:-Iakewindow(l,7,7, ""AIH7"ENU",S,S,20,6S), write(" ) Select your choice frol yhe following lenu :"),n1,nl,nl, write(" 1. Creat/Add views."),nl, write(" 2. Integrate VieNs"),nl, write(" 3. Translate View "),nl, write(" 4. Exit "),nl,nl, .rite(" ) Enter your choice :"),
f*************************************************************1 f* FILE: SCREEN.PRO *1 1* *1 1* "ain Purpose: Contains predicates for perforling standard *1 1* screen functions, such as: display lists in rONNise and *1 1* colulnNise, displaying latrices , etc. *1 1* *1 1* TOP LEVEL PREDICATE: display_list il 1* *1 1*************************************************************/ PREDICATES
Nriteline(integer) N rite 1 is t (1 is t)~ display_col(list) display_roN(list,integer,integer,integer) test_syn(string,string) forcol(integer,integer,integer,integer,integer) forroN(integerlintegerlintegerlinteger,integer) revise(integer,integer,integer,integer,string) wri teset(list) display_list(strlist,integer);display_list(list,integer)
displaY-COl\lH;I]):- IIrlte{ ,H},nI, IIrite('------------------'), display-col(T) . displaYJoII([],_,_,J:- !. display_roll([H:T],R,C,L) :- C> 80, Rl : R +1, display_roll([HiT],R1,C,L). display_row([H:T),R,C,L) :- Cl : C t L, cursor(R,C), IIrite(H),display_row(T,R,Cl,L),!. displayJist([],J :-!. display_list([H:L],I) II : I t l,Mrite(" ',I,') ',Hl,nl, display_list(L,Il).
/*uuuuuuuuuu*uu***uuuuuuu~uu*******/
/* FILJ : SCREHl. txt */
/* An efficient database design assures that *1 /* all the data requirelents of all the users *1 1* are stored Nithin the database and are *1 1* easily accessible. Thus 'a key cOlponent '1 1* of a database design systel is obtaining '1 1* frol the user a clear understanding of the *1 /* data requirelents. '1 j* '1 1****··*······················*·············*····*····***1
fi This syste. autolates the process of *f f* database design by using expert syste. */ f* techniques. */ f* The stages you will go throug are: *f f* 1. View "odelling *1 1* 2. View Integration *1 1* 3. View T ransla tion * I I**********i******i****************************i****i***1
1*****'**""**"*"'*'********"******'**'*'****************/ /* FILE: OBC.PRO *1 1* '1 1* Main Purpose: Contains predicates for creatr~g user ./ /* views. */
disp_vws :-IIrite(" LIST OF VIEWS :"),nl, findal1(V,vie~(V),L), display_list(L,l),!. db_desn :-nl,nl, IIrite(" ) For what do you lIish to design a database ?"),nl, IIrite(" (If you need lore than one lIord to respond, then"),nl, IIrite(" connect the lIords with underscore characters.)"),nl, write(" ) "),readln(Hale), not(Hale: ""), upper_loller(Hale,H), assertz(dbase(H),viellls), lakellindoll(2,7,7, "Oefinition" ,0,0,5,50), lakellindow(5,7,7, "EXAMPLES" ,5,0,10,50), lakewindoll(4,7,7, "",0,50,15,30), lakellindow(3,7,7, "OIALOG",15,0,10,80), aSk_vws,viewlist(L),creat_db(L), shiftllindoll(2),relovellindow, shiftllindow(3),removellindow, shiftwindow(4),relov8windoll, getfile(N,F),save(F,viellls). db _desn. creat_db( (J). creat_db((X:V]) '. vc(X),creat_db(V). ask_vIIs :.
shiftwindoll(2),clearwindow, write("User view is a specification of the content"),nl, IIrite('of a database appropriate for a single task"),nl, IIrite("that sOle users perforl. '), shiftllindoll(5),clearllindoll, file_str("viell_eg. txt" ,A),lIrite(A), shiftwindoll(3),clearllindoll,dbase(O), upper_Ioller(OU,D),
write(') Enter below the views for the database' ,OU),nl, write(') Entet one nale per line. ' ), write('When done, Press Return .... ' ),nl, ask_vwsl,! . ask_vws! :-shiftwindow(4),clearMindoN, disp_vMs,shiftwindow(3), write(' ) '),readln ( HU ),not(NU :"), upper_lower(HU,HL), chop_nale(NL,H) ,chk_dupv(H) ,ask_vws!. ask_vws! :- ask_vws2. ask_vws2 ;- clearwindow, write(') Are there any lore views (Y/N) ? a), readln(AHS) ,upper _lower('Y' ,ANS), write(') Enter one nale per line .• ), write('When done, Press Return ... : ),nl, ask_vwsl. ask_vws2 ;findall(V,view(V),L),retractall(view(_)), assertz(viewlist(L),viewls),dbase(O), getfile(D,F),save(F,viewls). chk_dupv(V) :-view(V),write(' View nale already exists. '),nl, write(' Give another nale. '),nl,ask_vwsl. chk_dupv(V) :-assertz(view(V)).
exp_ent :shiftMindoM(2),clearMindoM, Mrite(O Entities are objects about Mhich you Mant'), nl, Mrite(' to store inforlation in or retrieve'),nl, Mrite(' inforlation frol a database. O), shiftMindow(S),clearwindoM, f i le_str (0 ent_eg. txt' ,A) ,Mrite(A) ,shi f tMi ndow( 3) , ask_entl. ask_entl :- clearwindow,view(V), Mrite(') Enter beloM the objects'), write(' of interest to you in • ,V),nl, write(') Enter one nal' per line. ' ), write('When done, Press Return .... ' l,n1, ask_ent2. ask_ent2 :-shiftwindow(4),c1earwindow, disp_ents,shiftwindow(3l, write(' ) '), read1n ( NU ), not(NU :"). upper_lower(NU,NL), chop _nale( Nt, N) , chk_dupe(N),ask_ent2,!. ask_ent2 :- clearwindow,. write(') Are there any lOre objects (Y/N) ? 0), readln(ANS), upper_loMer('y',ANS),
10
Nrite(') Enter one na.e per line .• ), Mrite('When done, Press Return .... • ),nl, ask_ent2, ! . ask_ent2: -! . chk_dupe( E) :-entL.E), Nrite(' Entity nale already exists ").nl, Nrite(' Give another na.e. ·),nl. chk_dupe(L) :- check_ea(E). check_ea(E) :- split(E,X,Y), idlelber(Y) , Nrite(") ',E,' is an attribute nale. '),nl, att_ent(E,X). check_ea(E) :-vieN(V),assertz(ent(V,E)). att_ent(E,X) :- upper_loNer(XU,X), upper_loNer(EU,E),clearNindoN, Nrite(' ",EU,' is a property of the object' ,XU),nl, write(' So ',XU,' Nill be added as an entity instead of • ,EU),nl, write(' Do you Nant to give another nale for " XU" • ( Y / N) ? '), readln(AN), upper _loNer('Y' ,AN), write(' ) Enter the nale : '), readln(NU),not(NU:"), chop_nale(NU,N), view(V),assertz(ent(V,N)), assertz(attrib(N,E)),clearNindow, write(' > Enter other objects: '),nl, Nrite(' > Enter one na.e per line .• ), Nrite("When done, Press Return ....• ),nl. att_ent(E,X) ~-view(V),assertz(ent(V,x)), assertz(attrib(X,E)), Nrite(' > Enter other objects. Press Retu~n for nono ...• ·),I. exp_att :-shit tNi ndoN( 2), clearNindoN, write("Attributes are characterstics or properties'), nl,Nrite('ot objects that are used to describe it.·)~ shittNindow(5),clearwindow, file_str(·att_eg.txt· ,A), wri te(A),!. ask_att:-exp_att,ask_attl,!. ask_at tl :-ent(V,E), shit twi ndoN( 3), c1earllindoll, upper_loller(EU,E), Nrite(') Enter beloll the attributes of entity ·,EU).n1, IIrite(' Enter one attribute nale per lin •. '), write("When done, press return .... '),n1, ask_a tt2( E), fail. ask_at tl~l! .
ask_att2(E) :shiftwindow(4),clearwindow, disp_atts( E), shi f twindolf( 3), ni te(" ) ')' readln(AU), not(AU :"), upper_lower(AU,Al), chop_nale(Al,A), chk_dae(E,A) ,ask_att2(E),!. ask_att2(E):-ask_att3(E),!. ask_att3(E) :- clearwindow,upper_lower(EU,E), write(') Are there any lore attributes of entity' ,EU,' (V/N) ? '), readln(ANS), upper_lower('V' ,ANS), ask_att2(E), !. aSk_att3(E);- chk_nulle(E),!. chk_dae(E,A) :att(_,E,l),lelber(All), write(' ) Duplicate attribute nales are not allowed. '),nl, write(' Enter again ·),nl. chkjae(E,A) :-attrib(E,A), write(' ) Duplicate attribute nales are not allowed. '),nl, write(' Enter again "),nl. chk_dae(E,A) ;ent(_,A),upper_lower(AU,A), write(' ) • ,AU, • is an object. So this will not be added as an "),nl, write(" attribute of the entity ",E),nl, write(" > Vou shall be Isked to provide a relationship between the "),nl, write(" ) entities ", E " and" ,A, • later on. '),nl, assertz(liss_rel(E,A)), write(" > Enter other attributes.·),nl,!. chk_dae( E, A) ; -spli t( A I X, y) ,idlelber( V), upper_lower(X,Xl), not(E:Xl), cae(Xl ,E ,A),!. chk_dae(E,A) ;-assertz(attrib(E,A)),!. cae(X,E,A) ;-entL,X), upper _lower(AU,A), write(' ) ',AU, • is an attrib.te of the object ',X),nl, write(" So this will not be added as an attribute of the entity' ,E),nl, write(' ) You shall be asked to provide a relationship between the '),nl, write(" ) entities " E ," and • ,X, • later on!, ."),nl, assertz(liss_rel(EIX))laddat(A,X),
12
~rite(O > Enter other attributes of O,E), ~rite( Press return for none.O),nl,!. cae(X,E,A) :-~rite(O > Do you ~ant to add ., X,· as an entity (V/N) : .), readln(N), upper_lo~er(OyO,N),view(Y),
assertz(ent(Y,x)),assertz(att(V,X,[A])), assertz(liss_rel(E,X)), write(· ) Enter other attributes of ",E,·. Press return for none.O),nl,!. cae(_,E,A) :-assertz(attrib(E,A)),!. chk_nulle(E) :-retract(att(V,E,Bl)), findall(A,attrib(E,A),Al), union(Al,Bl,Cl), assertz(att(V,E,Cl)),!. chk_nulle(E) :-keyL,E,J,!. chk_nulle(E) :-attrib(E,J, findall(A,a~trib(E,A),AL),view(V), assertz(att(V,E,Al)),!. chk_nulle(E) :-edge( _,E ,_, ·ISA 0, J,! . chk_nulle(E) :-concat(E, "_id",X), chop_nale(X,XN), view(V),upper_lower(XN,Xl), assertz(att(V,E,[XL])),!. ask_ea(E) :-eKp_att,shift~indON(3), clearllindON,~ upper_lONer(EU,E), !!rite(· ) Enter be10!! the attributes of entity " ,EU),n1, !!rite(· Enter one attribute nale per line. "), !!rite(·When done, press return .••. "),n1, ask_att2(E),! • addat(A,E) :-attL,E,L), lelber(A,L),! . addat(A,E) :-retract(att(V,E,L)), assertz(att(V,E,[A:L])),!. addat(A,E) :-vie!!(V), assertz(att(V,E,[A))),!.
exp_Ia :-att(_,_,A), listlen(A.L).l >1. shiftMindow(S).clearwindow, file_str(",ult.txt" ,C). Mrite(C),shiftwindow(3). clearMindow, write(">. Now we Mant to know which of the attribute of an entity·),nl, write(· can take several values for each instance of the entity. ·),nl, write(" (see exalple) ·),nl,nl, write(") Press any key to continue ...• ·).nl, readchar (J , ask_Ii, ! . ask_II :-att(_,E,AL),ask_Ial(E,AL),fail. ask_la:- conv_lul,!. ask_la1(E,K):-list1en(K.l), l > 1, clearwindow, upper_lower(EU.E), Mrite(· > NOM for entity: ·),n1, write(" ·,EU.· ["), wd telist( K), write("]"),n1, write(" > Enter the attribute that has several values for each ·),nl, write(" instance of the entity ·,EU),nl, write(· > Enter one attribute per line. When done, Press Return •.•.• ), n1,shiftwindow(4),clearwindow. disp_la(E),shiftwindow(3), ask_1I3(E). !. ask_1i1 L. J . ask_1i3( E) :-wri te(" ) • ), readln(NU),not(NU:··),upper_10wer(NU,N), check_la(E,N).!. ask_1i3(E) :-ask_1I4(E),!. ask_Ia4(E):-nl,att(_,E,K),listlen(K,l), l > 1, write(· ) Is there any lore attribute (yIN) ? .), readln(ANS).upper_lower(·Y· ,ANS), ask_1I3(E),! . ask_u4U. check_crs :- cursor(R._),R < 7,!. check_crs :- cursor(S,O),nl,n1,cursor(S,O),!. check_Ia(E,N) :-lul_entL,H), cursor(R,_),str_len(H,L), 11 : L +3, R1 : R -I,
14
cursor(Rl, L1), ~rite(' : This is already kRONn as a lultivalued attribute. '),nI, nI ,ask_1I4(E). check_Ia(E,H) :-att(_,E,NA), lelber(H,HA),l, checLluI (E,H). check_Ia(E,H):cursor(RR,_),str_ien(N,L), Ll : L +3, Rl : RR -1,cursor(Rl,Ll), Mrite(" : Undeclared/Misspelled attribute. "),nl, aSk_1I4(E). check_Iul(E,A) :-lul_ent(_,X),eqiv~att(A,X), assertz(lul_att(X,A)), aSk_1I3( E) , 1 • check_IuI(E,A) :- assertz(lul_ent(E,A)), aSk_1I3( E) , 1 • conv_luI:- luI_ent(E,A),ent_IuI(E,A),faiI. conv_IUI:-! . conv_la(E) :-IU I_att( E, A), assertz( at trib( E, A)), f,il. cony _la(J:-!. ent_Iul(E,A) :split(A,X,_),upper_IoMer(AU,X), clearMindoM,vieM(V),Mrite{" Entity: "), display_ent(E,V),nl, retract(att(Y,E,Al)), delete(A,AL,Bl),assertz(att(Y,E,8l)),!, Mrite(" ) ",AU, " Mill be converted to an entity. '),nI, Mrite(" Do you Mant to give another nale for', AU,": "),nl,Mrite(") ( Enter the Hale/ Press Return for Ho thange ) : "), readln(Ans),act_la(E,X,Ans),!. ent_IuI(E,A) :-upper_IoMer(AU,A), cIearMindoM,vieM(Y),Mrite(" Entity: "), displaLent(E,Y),nl,retract(att(V,E,Al)), delete(A,AL,BL),assertz(att(Y,E;8L)),!, Mrite(" ) ",AU, " Mill be converted to an .ntity. "),nl, Mrite(" Do you Mant to give another nale for', AU," : "),nl,Mrite(" ) ( Enter the Nale/ Press Return for No change) : "), readln(Ans), act_Ia(E,A,Ans),!. act_u(E,N, "") :-vieN(Y), assertz(ent(V,N)),assertz(liss_rel(E,H)), conv_la(H),ask_ea(H),!. act_Ia(E,X,NU):-vieM(V),upper_IoMer(HU,H), assertz(ent(V,N)),assertz(liss_fel(E,H)), cony _1a(N) ,ask_ea(N),!.
axp_key :- lakewindow(6,7,7, "",8,50,7,30), explk,ask_keys,shiftwindow(6),relov&window,!. explk:-shiftwindow(2),clearwindow, write(:The key of an entity il the list of attributes"),nl, write("that deterlina the viiues of all other·),nl,write(·attributes of the entity. "), shiftwindow(5),clearwindow, file_str("key_eg.txt·,K),write(K), shiftwindow(3),clearwindow, write(") In genral, there lay be lore than one key for an entity, and·),nl, write(· sOlatiles the key of another entity lay be required to deterline·),nl, write(· the values of all the attributes of the entity. ").nl,n1,n1,nl, write(· ) Press any key to continue ..•. ·), readchar(J,!. ask_keys :-ent(_,E),ask_keysl(E),fail. ask_keys :-weakents. ask_keysl(E) :-att(_,E,[]),l. ask_keysl(E) :-att(V,E,[X)),upper~ower(EU,E), upper_10wer(XU,X),shiftwindow(4),c1.arwindow, shiftwindow(3),c1earwindow, write(" ) Is the attribute·, XU, • a k9y of the entity" ,EU, • (yiN) ? "), read1n(Ans),upper_lower("Y" ,Ans), assertz(a1t(V,E,[X))),l. ask_keysl(E) :- upper_10wer(EU,E), att(~,E,K),c1aar.indow, IIrite(· ) Now for entity: ·),n1, .rite(" ",EU,· [·),write1ilt(K),write(·]"),n1, shiftwindow(4),c1earwindow, dispjktyS(E), shiftwindow(3), write (" ) Enter the attributes that forls the k~y. "), n1,write (" ) Enter one attribute per line. " ), write ("When done, Press Return .... " ),nl, ask_keys3(E,Keyl, [] ), check_key(E,Keyl); check_exist(E),! . ask_keysl(E):-l. check_exist(E) :-a1t(_,E,_), ask_keys2( E), ! . check_exist( E.) :- c1ear.indow, write(" ) There lust be at1east one key for: ",E ), nl, askJeysl( E ),!. '. ask_keys2(E) :-att(_,E,A),list1en(A;L),l )1, clearwindo.,upper_lower(EU,E),
16
write(' ) Are there Iny lore keys for" , EU, ' (Y/N) ? '),readln(ANS),upper_lower('Y',ANS), write(' ) Enter the other keys. '),nl, ask_keysl(E),l. ask_keys2(_):-!. ask_keys3 ( E, KI, IN ) :shiftwindow(6),clearwindow, disp_katts(E), shiftwindow(3), write(' > ') ,readIn ( NU ), not ( NU : " ),upper_lower(NU,N), exist_aH(E,N, IN ,OUT) ,askjeys3( E, KI,OUT ),!. ask_keys3(E,[],[]):-!. ask_keys3( E, KI, IN ) :-write(' )·Any lore attributes in the key (YIN)? ' ), readln ( ANS ), upper_lower ( 'y', ANS ), ask_keys3 ( E, KI, IN ),!. askjeys3 ( _, K, K ): -! . exist_att(E,N,IN,IN) :-lelber(N,IN), write(' Duplicate attribute nales are not allowed. '), nl,! . exist_att(E,N,IN,[N:IN]) :-att(_,E,K),lelber(N,K), assertz(katt(E,N)),!. exist_att(p,N,IN,[N:IN]) :ent(_,N),assertz(katt(E,N)),!. exist_att(E,N,IN,[N:IN]) :split(N,X,Y),idlelber(Y), entpart(X,E),assertz(katt(E,N)), addat(N,E),!. exist_att ( _ ,_, X, X) :-write(' Undeclared/ "isspelled attribute. ' ), nl, !. check_key(E,K) :-alt(_,E,K), writer ) This key is already known'. ' ),nl, !. check_key( r, []) : -.!. check_key(E,K):-view(V),assertz(alt(V,E,K)), retractall(katt(E,J)'! . weakents :-alt(V,EI,KI),.nt(V,E2),equal([E2],KI), retract(alt(V,El,KI)), assertz(edge(V,El,E2, 'ISA'," )),fail. weakents :-aIt(V,EI,Kl),.nt(V,E2),lelber(E2,Kl), d.l.t.(E2,Kl, K ),retract(alt(V, El, KI)), assertz(aIt(V, El, K ) ), assertz(edge(V,El, E2, '10', " )), fail. weakents . disp_katts(E) :-writ.(' ATTRIBUTES Of THE PRESENT'), nl,write(' KEY OF ENTITY: ',E),nl, findall(A,katt(E,A),Al),display_list(AL,l).
17
lii*iiiiiiii*.****i***i* •••• i*****.********.****************i*1 Ii FILE: BREL.PRO *1 /* */ 1* "ain Purpose: To obtain binary relationships frOt the */ 1* user. *1 /* *1 1* */ 1* TOP LEVEL PREDICATE : ask_brel2 */ /* */ 1* */ /**********************.**************************************/
aSk_brels:- , shiftMindoM(2),clearMindoM, Mrite(' Relationships art associations bltMeen"),nl, Mrite(' tMO or lOre entities."), shiftMindoM(S),clearMindoM, file_,tr(·brel_eg.txt· ,R),Mrite(R), shiftMindoM(3),clearMindoM, Mrite(') Here Me Mant to see the different"), Mrite(' types of associations 'that exist "),nl, Mrite(' betMeen pair of entities. '),nl,nl, Mrite(') Press any key to continue ..... "), readchar(J, ask_brell,conv_isa,!. askjrell :-clearNindoN, Nrite(' Enter the binary relationships betNeen '), Nrite(' entities in the fori of :'),nl, Mrite(' EntitY_l VERB_PHRASE Entity_2 . '),nl,
chk_ebe(_,_,_) :-write(" Misspelled/Unknown entities are used "),nl, write(" Enter the relationship again "),nl, ask)re13.
check_accept(R,E1,E2) :-write(" Entity ~,E2," is Misspelled/UnknONn "),nl, write(" Which of the following actions you want to take :"),nl, write(" 1) Give another nale. "),nl, write(" 2) Retain this as an entity.") ,nl, write(" 3) Discard it. "),nl, write(" Enter your choice (1/2/3) "), readi nt(I), dO_Ibe(R,E1,E2,1). check_accept(_,_,_) :-!. dO_Ibe(R,E1,E2,1) :-view(V), write(" Give another nale for" ,E2, ": "), readln(Nale),not(Nale :""),upper_Iower(Nale,Nl), chop_nale(Nl,N), assertz(rel(V,R)), askJole(R, E1), ask_fole(R,N),!. dO_lbe(R,E1,E2,2) :-view(V),assertz(rel(V,R)), assertz(liss_ent(E2)), askJole(R,E1), askJole(R,E2),! . dO_Ibe(_,_,_,_) • ask_role(R,E) :-view(V) , write(" Give the role of the .ntity ",E), write(" in the relationship : ",R),nl,nl, write(" ) Role: ·),readln(l),nl, assertz(edge(V,R,E,l, .")),!.
ask_nrels :-shiftwindow(5), file_str('nrel_eg.txt·,R),write(R), shiftwindow(3),cl.~rwindow, write(' Here we want to see the different"), .rite(" types of associations that exist "),n1, write(' along entities'),nl,nl, write(' Press any key to continue ...... ·), readchar(_),ask_nrell,!. ask_nrell :-clearwindow, write(') Enter the "_ary relationships alOng '), write(' entities in the following fori :'),n1, write(') First enter the nale of the relationship') write(' and then enter the list '),n1, write(' entities over which it is defined. '),nl, write(' Enter one relationship per line. "),nl, ask_nre12, !. ask_nre12 :-shiftwindow(4),clearwindow, disp_rels,shiftwindow(3),
write(') Enter the Relationship nale : H), readln(RN),not(RN:"), upper_lower(RN,NL),chop_nale(HL,N), check_dupr(N),ask_nre12,! . ask_nre12 :- aSk_nre13,!. ask_nre13: -clearwindow, write(') Are there any lore relationships (Y/N) ? H), readln(ANS),upper _lower('Y' ,ANS), ask_nreI2. ask_nreI3: -! • ask_nent3(R) :-clearwindow, upper_Iower(RU,R), write(" Enter the entities for 'the relationship ',RU),nl, write(" Enter one entity per line. '), writer' When done, Press Return .... '),nl, accept_ents(R) . check_dupr(H) :-relL,Nl', write(" Relationship nale already exists'),nl, write(' Give another nale. '),nl,lsk_nreI2,!. _ check_dupr(R) :-view(V), assertz(rel(V,R)), ask_nent3(R) , check_null(R) . check_null(R) :- edgeL.R,_,_,J. check_null(R) :-retract(rel(_,R)). accept_ents(R) :- ~ write(" ) Entity: "),readln(EU), not(EU:'"),upper_lower(EU,E), check_ent_dup(E,R). accept_ents(R) :-write(') Is there any lore entity (Y/H) ? '), readln(ANS),upper _lower('Y' ,ANS), accept_ents(R) . accept_entsU. check_ent~dup(E,R) :- edge(_,R,E,_,_), write(' Duplicate entity nales are not all,wed'), write(' Enter again'),accept_ents(R). check_ent_dup(E,R):- check_exist_ent(E,R). check_exist_ent(E ,R) :-ent(V ,E), assertz(edge(V,R,E," ,")), accept_ents(R). check_exist_ent(E,R) :-write(" The entity ",E, ' is Undeclared/ "isspelled entity'),nl, write(" Nhich of the following actions
you lIant to take :'),nl, Mrite(' 1) Give another nale. '),nl, Nrite(' 2) Retain this as an entity.·),nl, Mrite(' 3) Discard it.·),nl, Nrite(' Enter your choice (1/2/3) : '), readint(I}, dO_liiS_nent(R,E,I),accept_ents(R). dO_liss_nent(R,E,l):-viell(V), , IIrite(' Give another nale for' ,E, ': '), readln(Nale),not(Nale :"),upper_loller(Nale,Nl), chop_nale(Nl,N),assertz(edge(V,R,N," ,")). dO_liss_nent(R,E,2) :-vieN(V), assertz(edge(V,R,E,", ")), assertz (Iiss _ent (E)) . dO_Iiss_nent(_,_,_):-!.
not(Rl:R2),tlstrol(E,Rl,R2),fail. rolls:- repalrl,!. testrol(E,Rl,R2) :-edge(_,Rl,El,_,_),not(E:El), edge(_,R2,El,_,_),askrol(E,Rl,R2),!. testrolL._,J. askrol(E ,Rl ,R2) :view(V),nl,display_rel(V,Rl),nl, display_rel(V,R2),nl,nl, write(" ) Sive different roles for", E, • in these two relationships :'),nl, writer' ) Role for' ,E,' in ',Rl,' "),readln(Nl), not(Nl :"),upper _lower(Nl,ll),nl, writer' ) Role for ',E,' in. ',R2,' '),readln(N2), not(N2: "),upper ~lower(H2,l2),nl, assertz(role(Rl,E,Ll)), assertz(role(R2,E,l2)),!. askrol(E,Rl,R2) :-writer' > You should provide different and none e.pty roles for' ,E),nl, writer' > Enter again :'),nl, askrol(E,Rl,R2),! . repalrl:-retract(role(R,E,l)), reprl(R,E,L),fail. repaIrl:-!. reprl(R,E,L) :- retract(edge(V,R,E,_,C)), assertz(edge(V,R,E,l,C)), !.
/*************************************************************/ /* FILE: EDIT.PRO */ /* *1 1* "ain Purpose: TO allow yhe user to .odify the view. */ /* */ 1* */ /* *1 1* TOP LEVEL PREDICATE : ed_view *1 /* *f 1* */ /*************************************************************/
clearwindow, writer" ) Select the appropriate options frol the following '),nl, writer" lenu to do the lodifications. "),n1,nl, writer" 1. Add Entities. "),nl, writer" 2. Delete Entities. "),nl, writer' 3. Renale entities. "),nl, writer' 4. Add attribute to Entities. "),nl, writer" S. Delete Attributes frol Entities. '), nl,write(" 6. Renale attributes of entffies."), n1,write(" 7. Exit '),n1,n1, writer' ) Select Your Choice: '), readint(I), do_ent(I) .
do_ent(1) :exp_ent, ent_el .
do_ent(2) :shiftwindow(17),clearwindow,nl, IIri te(· ) Enter the ,nale of the entity you want to ~elete "), IIrite(" frol the above list: "),nl,nl, shiftllindoll(12),clearwindoll, disp_ents,shiftllindow(17), IIrit~(' ) ( Enter the nale/Press Return for none) "), readln(N),not(N :'"), upper_lower(N,NL), ehkere(NL),ent_el.
renat(E) :-att(_,E,K), clearwindOlj,nl,upper_lower(EU,E), write(" ",EU," ("), writelist(K), write(T),nl, write(" ) Do, you want to renale attributes of ", EU ," (Y!H) ? "), readln(Ans), upper_lower("Y" ,Ans), ren_att(E,K),l. ~ renat(_) :-clearwindow,!. ren_att(E,[]) :-!. ren_att(E,[H:T]) :-cursor(3,O),nl,nl,nl,nl,cursor(l,O), upper_loNer(HU,H), write(" ) Renale the attribute" ,HU,· ? "),nl, write(" ) (Enter the new nale! Press Return for no change) : .), readln(AHS),not(AHS : ."), upper_lower(ANS,H),retract(att(V,E,AL)), delete(H,AL,Bl),!, assertz(att(V,E,(N:Bl))), renal(E,H,N),ren_att(E,T),l. ren_att(E,[_:T)) :- ren_att(E, T),!. renal(E,H,H) :-alt(_,E,K),lelber(H,K), renkl(E,H,H),fail. renal (E,H, N) :-kev(V,E,K),delete(H,K,Kl), assertz(key(V,E,[N:Kl])),!. renalC,_,J :-!. renkl(E,H,N) :-retract(alt(V,E,K)), delete(H,K,Kl), assertz(alt(V,E,(H:Kl])),!. delat(E) :-clearwindow,nl,upper_lower(EU,E),
29
att(_,E,K),write(" ",EU," [OJ, writelist(K),write("]"),nl, write(" ) 00 you want to delete attribut.s frol ., EU ,. (YIN) ? "), readl n( Ans), upper _lower("Y" ,Ans), att(_,E,AL), del_att(E,AL),!. delatU ;-!. del_attL [J) ;"-!. del_a t t( E, [H: T]) ; -cursor( 4,0) ,nl ,nl ,nl ,cursor{-4 ,0) I upper _lower(HU,H), writer" ) Do you want to delete" ,HU," (yIN) : "), readln(Ans), not(Ans:""), upper_lower("Y" ,Ans), retract(att(V,E,AL)), delete(H,AL,BL), assertz(att(V,E,Bl)), deI_att(E, T),!. del_att(E,LPJ) ;-del_att(E,T),!. chkere(N) :-edge(_,R,N,_,_), writer" > The entity can not be deleted as it participates "), writer" in a relationship. "),nI,!. chkere(N) ;-edge(_I_,N, "ISA",_), writer" > The entity can not be deleted as it is a generic entity. "),nl,!. chkere(N) :-edge(_,_,N, "10",_), write(" > The entity can not be deleted as it is a Strong entity."),nl,!. chkere(N) ;-retract(ent(_,N)), retractalI(att(_,N,_)), retractall(alt(_,N,_)), retractall(key(_,N,_)),!. chkereU; -! .
reI_el ;-shiftwindow(11), clearwindow, nI, writer" > Select the appropriate options frol the following "),nl, write(" lenu to do the lodifications. "),nI,nl, write(" 1. Add Relationships. "),nl, write(" 2. Delete Relationships. "),nl, write(" 3. Renale Relationships. "),nl, write(" 4. Add attributes to Relationships "),nl, write(O S. Delete attributes frol Relationships. "), nI,write(" 6. Renale attributes of relationships. "), nl,write(" 7. Exit this Kenu. "),nl,nl, writer" ) Select Choice ; "), readint(I), do_rel(I),!. dOJel(1) .;-ask_brels,ask_nrels,
30
ex_card, eXJela, rel_el,!. do_rel(2) :-lhiftMinda.{17),cliarMinda.,nl. Mrite(" ) Enter the nale of the relationship you Mant to delete "),nl, tHite(" frol the above list: "),01.01, shiftMindoM(12),clearMindoM. disp_rels,shiftMindoM(17). Mrite(" ) (Enier the nale/Presl Return for none) : "), readln(RN), .-riot(RN : " "). upper_loMer(RN.R), rel(_.R).cher_r(R), del_rel(R). rel_el, !. dOJel(2) :- . clearMindoM, rel_el,! . dOJel(3) :-shiftMindoM(17).clearMinda., findall(R,rel(_,R),RL), renrl(RL), . rel_el.! . dOJel(4) :-
/. The ' phases through which you will go through are; */
/* 1) Select Views; You will be asked to select two views */ /* frol a list of views for integration. */ /* 2) Conflict Resolution : */ /* In this stip various conflicts will b. identified */ /* and resolved. * I /* 3) "erging : The two conflict free views will be lerged into a '1 1* single view. */
1*************************************************************1 1* FILE: VI.PRO *1 1* *1 1* Kain Purpose: Kain progral for integrating user views by *1 Ii identifying and resolving various conflicts and lerging *1 1* thel thel into a single global view to produce the conc-*/ Ii ptual schela of the required database. *1 1* */ 1* TOP LEVEL PREDICATt : vlit */ 1* .- */ 1*************************'***********************************/ include ·hc.pro· include ·sc.pro· include ·sta.pro· include "hyc.pro· include "rolee.pro· include ·carde.pro· include ·keyc.pro· include ·Ierge.pro· predicates
CLAUSES
vi vint(strlist) vil(string,string,string) vintr checksell(strlist,integer,integer) checkse12(strlist,integer,integer,int.ger) check_vn(string,string) getview(string,string,string)
checksell(L,I1,N) :-write(" first Vilw (1-· ,N,') : '), readint(I1),nl,I1 ( N t I,!. checksel1(L,Il,N) :-write(·) You should select a nUlber frol (1-",N, ·)"),nl, write(") Please s.lect the first view again. '),nl, checksel1(L,Il,N). checkse12(L,Il,I2,N) :- write(' Second Viaw (1-",N,") : "), readint(I2),nl,I2 ( N t 1, 11 () 12,!. checkse12(L,Il,I2,N) :-write(") The nUlber should be frol (1-· ,N, ")"), write(" and different frot ",11," ."),nl, writer") Please select the second view again."),nl, checkse12(L,Il,I2,N). vintr :-file_str("vintl.txt" ,A), wri telA) ,nl ,nI, write(" ) Press any key to continue ..... "), readcharU. getview(K, Y ,I) :-shi f twindow(1), clearwindow, write(" ) Give the nale of the integrated view: "), readln(N),check_vn(N,I).
33
check_vn(N,N) :- str_len(N,L),L ( 15. check_vn(N,Z) :- frontstr(15,N,l,_). vi :- lakewindow(1,2,11, 'OIALOG' ,0,0,25,80), vintr, viewlist(F),vint(F),!. vi :- write(') No views are there for integration. '), write(') first create sOle views and then integrate thel:), relovewindow. vint([X)) :- ret:.all, getfile(X, F), consu It (f) , shiftwindow(I),clearwindow, dispview(X), relovewindow. vint(L):- laklwindow(6,2,11, 'SELECT VIEWS' ,0,0,25,80). retract(viewlist(_)),listlen(L,H),clearwindow, write(') Select any two views frol the'). write(' following list for integration: '),nl, display_list(L.l), checksell(L,Il,H). checkse12(L.Il.I2.H). nth_elel(L.Il.Vl). nth_elel(L.I2,V2), v i1 ( VI. V2 ,Z) , delete(Vl,L,Ll), delete(V2,Ll,L2), append(Z,L2,L3), assertz(viewlist(L3),viewls), vint(L3),! . vil(X,Y,Z) :-retractall(view(_)); retractall(ent(_,_)), retractall(rel(_,_)), retractall(att(_,_,_)), retractall(keY(_'_'_))i retractall(alt(_,_,_)), retractall(edge(_,_,_,_,_)), getfile(X,fl), getfile(Y,F2), consul t( Fl), consu It (F2), getview(X,Y,Z), hcl(X,Y),hc2(X,Y),syn_ent(X,Y), syn_rel(X,Y),syn_att(X,Y),dc(X,Y), card_conf(X,Y),roll~c(X,Y), hc(X,Y),sthc(X,Y),key_conf(X,Y),I.rge(X,Y), ren_view(X,Z) , getfile(l,f), retractall(att(_,_,[])), save(F), ! .
ask ... ent(X, Y ,Sl ,S2 hupper_loMer(XU,X), upper_loMer(YU,Y), shi fhindoM(2). clearMindoM, display_ent(X,Sl),nl. shiftMindoll(l) , clearllindoM, display_ent(Y,S2),nl, shifhindoll(4). clearllindoll, Mrite(') Nhich of the follolling relationship holds for these entities '), nl, Mrite(" of the tllO vieMs :'),nl, Mri te(" 1) The enti ties arB exact! y sale in both the viells, ')' nl, Mrite(' 2) The entity" ,XU,' of I' ,Sl,"' is I su~set of the entity"),nl, IIrite(" ",YU,' of the ',S2,',"),n1, llrite(' l) The entity ·,YU,. of I' ,52," is a subset of the entity"),nl, Mritl(" ',XU," of the ',Sl,', "),nl, IIrite(' 4) Both the entities ", XU, " and' ,YU), IIrite(" have a cOllon dOlain,'), nl, IIrite(' 5) None of the above are true, "),nl,nl, IIrite(') Enter your choice (1-5) : "),!,
hc3(Sl,52):- ent(SI,E), rel(S2,E), hc31(E,SI,S2),fail. hc3(Sl,S2) :- rel(SI,R), ent(52,R), hc32(R,51,S2), fail. hc3(_,_) :-reloveMindoM,relovewindoM, reiovelii ndoM, ! . hc31(E,Sl,S2):- ask31(E,Sl,S2), readln(ReplY),upper_lower("H",Reply), hc3ll(E,Sl ,S2). hc31(_,_,J :- !. hc32(R,Sl,S2) :. ask32(R,51,S2), readln(ReplY),upper_lolier("N",Reply), hc311 (R, S2, SI) . hc32(_,_,_) :-!. hc3(R,Sl,S2) :-shiftliindoli(2),clearliindoli, lirite(" Schela : ",SI),nl, nl, display_ent(Sl,X),shiftMindoM(3), clearliindoM,lirite{" Schela : ",S2),nl, display_rel(S2,X),shiftliindoli(4), lirite(") Is the leaning and dolain of the EHTITV ",X), lirite("the sale as "),nl, lirite{" the leaning and the dOllin of the RELATIONSHIP ",X), lirite(" (yIN) ? : ",). hc311(X,Sl,S2) :- . write(") Renale the entity or the relationship,,"), liri te(" Heli nales should be different .. : .• "), nl, nl, lirite(") Do you liant to renale the entity '",x,"'"),nl, lirite(" in", 51, " (Y/H) ? "),readln(Rl),upper_lolier(RUl,Rl), renale_ent(X,Sl,RUl),nl, write(") Do you liant to renale the relationship '",X,"'"),nl, llrite(" in ", S2: (yIN) ? "), readln(R2),upper_lolier(RU2,R2), renale_rel(X,S2,RU21,check_renl(X,SI,S2,RUl,RU2),l. hC311L._,J :- l. check_renl(X,SI,S2,"H", "H") :- nl, lirite(") Please confirl whether the leaning and dOlain of the"),lirite("EHTITY ",X), Nrite(" the sale as the leaning and the dOlain of the RELATIONSHIP ",X),liriteC" (v/H) ? : "), readln(YN), upper_lolier("N",YH),nl,clearliindoli, lirite(") You should rena Ie at least the entity or the relationship"),nl,hc311(X,Sl,S2). check_renl(_ ,_,_,_,_). ask32(X,51,S2) :-shiftNindow(2),lirite(" Schela : ",SI),nl, nl, display_rel(Sl,X),shiftliindoll(3),lirite(" Schela : ",52),nl, display_entCS2,X),shiftliindoli(4), write(") Is the leaning and dOlain of the RELATIONSHIP" ,X), IIrite("the sale as "),nl, write(" the leaning and the dOlain of the ENTITY" ,X), Nrite(" (Y/H) ? ; "J.
dochoice(X,Y,Sl,S2,Ch}, shiftwindow(2},ralovawindow, shiftwindON(3},relovlwindow, shiftwindow(4},relovewindow,!. dochoice(X,Y,Sl,S2,l} :-clearwindol, write(") Renale both the entities as • IX, " or' ,Y,", "), nl,nl,write(" Which nale you lant to use? "},nl, writer" 1) ", X),nl, writer" 2)'",y),nl, writer" Entar your choice (1/2): "), readint(Choice), dosubchoice(X,Y,SI~S2,Choice),!. dochoice(X,Y,SI,S2,2) :- add_sub(X,Y), add_syn_ent(X,Y),!. dochoice(X,Y,SI,S2,3) :- add_sub(Y,X), add_syn_ent(X,Y),l. dochoice(X,Y,Sl,S2,.) :- sub(X,'E), a4d_sub(Y,E),!. dochoice(X,Y,Sl,12,.) :- sub(Y,E),add_sub(X,E),!. dochoice(X,Y,Sl,S2,.) :-clearwindow, split(X,Xs,Xe), write(") Is the entity'" ,Xe, " genlralization of both the entities"), nl,write(" ", X," and", Y, ' ?(Y/N) "),readln(YN), upper _lower("Y" ,YK), add_sub(X,Xe), add_sub(Y,Xe),n1,!. dochoice(X,Y,Sl,S2,4) :-write(") Give the nals of an entity which is a generalization of '), write("both the entities "),n1, write(" ", X," and ", Y, ' : "),n1, write(" It should be different frol the folloNing entities .••... "),n1, display_entset(SI),ni, display_entset(S2',nl, write(") 0), readln(Nale),add_sub(X,Nale), add_sub(Y,Nale), add_syn_ent(X,Nale), add_syn_ent(Y,Nale), add_syn_ent(X,Y),! . dochoice(X,Y,Sl,S2,5) :-!, dosubchoice(X,Y,SI,S2,1) :ren_ent(S2,Y,X), add_syn_ent(X, y),!. dosubchoice(X,Y,Sl,S2,2) :ren_ent(Sl,X,Y), add_syn_ent(X,Y),!. dosubchoice(X,Y,Sl,S2,Ch) :- Ch < 1, writer" The choice should be 1 or 2 only. '),n1, write(" Enter your choice again (1/2) :"), readint(Chl}, dosubchoice(X,Y,Sl,S2,Chl), !, dosubchoice(X,Y,Sl,S2,Ch} :- Ch ) 2, write'," The choice should be 1 or 2only."),nl, writer' Enter your choice again (1/2) :'), readint(Chl), dosubchoice(X,Y,Sl,S2,Chl), I
case_sc2(X,Y,SI,S2) :- synonYI_rll(X,_),!. case_sc2(X, Y ,SI,S2) :- synonYIJel(_, Y),!. case_sc2(Rl,R2,Sl,S2) :rel_ents(SI,Rl,ES1),rel_ents(S2,R2,ES2), eq_entset(ESl,ES2), act_synrel(Rl,R2,Sl,S2),!. case_sc2(Rl,R2,SI,S2):- eqiv_nale(Rl,R2) ,act_synrel(Rl,R2,Sl,S2),!. case _sc2 (R I, R2 ,S I, S2) : - !. act_synrel(X,Y,SI,S2) :-ask_rel(X,Y,Sl,S2), readln(Ch), upper _lower(UC,Ch), do_relsyn(X,Y,SI,S2,UC),!. do_relsyn(X,Y,SI,S2, .y") :-clearwindow,
40
write(") Renale both the relationships as ",X, " or"), write(Y,". "),nl,nl, . write(" Which nale you want to use ? ")~nl, llrite(" I) ", X),nl, IIrite(" 2) ",Y),nl, IIrite(" Enter your choice (1/2): H), readint(Choice), dosubch(X,Y,SI,S2,Choice),! . do_relsyn(X,Y,SI,S2,_) :- !. dosubch(X,Y,SI,S2,1) :ren_rel(S2,Y,X), add_syn_rel(X,Y),!. dosubch(X,Y,Sl,~2,2) :ren_rel(SI,X,Y), add_synJel (X, Y),! . dosubch(X,Y,SI,S21Ch) :- Ch < I, IIrite(" The choice should be I or 2 only. "),nl, write(" Enter your choice again (1/2) ;"), readint(Chl), dosubch(X,Y,Sl,S2,Chl), !. dosubch(X,Y,SI,S2,Ch) :- Ch ) 2, write(" The choice should be I or 2 only. "),nl, IIrite(" Enter your choice again (1/2) ;"), readint(Chl), dosubch(X,Y,Sl,S2,Chl), !. add_syn_rel(X,Y) ;- synonYI_rel(X,Y),!. add_syn_rel(X,Y) :~
write("---------------------------------------------------------"), writeline(L2), shiftwindow(13),clearwindow, write(") If the pair of relationships in the row and coluln "),nl, write(" are synonYls then enter (Y), otherwise enter (N):),nl, shiftwindow(14), retractall(rowcol(_,_)), forrow(1,4,3,L2,Ll),~ shiftwindow(13),nl,nl, write(" ) Do you want to revise again ?(Y/N) :"), readln(Again), upper _lower(AU,Again), shiftwindow(14), revise(L2,Ll,4,3,AU), ask_relsyn(Sl,S2,RSl,RS2). ask_relsyn(Sl,S2,RSl,RS2) :- rowcol(R,C),clearwindow, nth_elel(RSl,C,A),nth_elel(RS2,R,B), write(") Which of the following Relationship you want to use :"), nl, write(" 1) ",A),nl, write(" ~)" ,B),nl, write(" Please enter your choice (1/2) :"), readln(I), rel_ren(Sl,S2,A,B,I),fail,!. ask_relsyn(_,_,_,_) :-clearwindow,!. rel_ren(SI,S2,A,B, "I") :-ren_rel(S2,B,A),!. rel_ren(SI.S2.A.B. "2") :-ren rel(Sl.A.8). 1_
42
1*************************************************************1 1* FILE : STA. PRO *1 1* *1 1* Main Purpose: To identify attribute_attribute, attribute_*1 1* entity type conflicts between pair of views and to *1 1* resolve thel. *1 1* *1 1* TOP LEVEL PREDICATE: card_conf *1 i* *1 1* */ Il*************************************~**********************1 predicates .
clauses rhc(51,52) :lakewindow(2,7,7,51,O,O,6,80), lakewindow(3,7,7,S2,6,O,6,80), lakewindow(4,7,7, ·DIA~OG",12,O,13,80), findall(E,edge(Sl,_,E, °ISA" ,_),EU), findall(F,edge(51,F,_, °ISAo ,_),EL), testrhc(Sl,S2,EU,EL), shiftwindow(2),relovlwindow, shiftwindow(3),relovlwindow, shiftwindow(4),relovewindow,l. testrhc(Sl,S2,EU,EL) :- lelber(E1,EL),lelber(E2,EU), testeh(S1,S2,El,E2),fail. testrhc(_,_,_,_) :-!. testeh(Sl,S2,El,E2) :~ isa(El,E2,Sl), isa(E2,El,S2), ask_rhc(Sl,52,El,E2),!. isa(E1,E2,S) :- edge(S,E1,E2,OISA",_),!. isa(E1,E2,5) :- edge(S,E1,E3, "ISA",_), i sa (E3, E2 ,S) , l . ask_thc(Sl,S2,El,E2):-shi ftwindow(2), c lea rwi ndow, display_ent(El,Sl), shiftwindow(3), clearwindow, display_ent(E2,S2), shi f hi ndow( 4 ) , clearwindow, nl, write(") Which of the following relationship holds for these two entities"), write(" (1/2) :.), cursor(R,C),nl,nl, write(" 1) • ,E1,· is a subset of the entity", E2, •. ·),nl, write(· 2) • ,E2,· is a subset of the entity·,
shiftNindoN(2),reloveNindoN, shiftwindoN(3),reloveNindoN, shiftNindoN(4),reloveNindoN,!. testhcr(Sl,S2,El,E2,R) :retract(edge(S2,R,El,_,_)), asserta(edge(S2,El,E2,'ISA', .')),!, act_hc(SI,S2,El,E2,R) :·reltype(R), retract(rel(S2,R)), retract(edge(S2,R,E2,_,_)), retract(edge(S2,R,El,_,_)), asserta(edge(S2,Er,E2,·ISA· , •• )),!. act_hc(Sl,S2,El,E2,R) :~rel_ents(S2,R,ES), upper_loNer(EIU,El), upper_loNer(RU,R), clearNindoN, shi f twindow( 2) , clearNindoN, display_ent(El,SI),nl,nl, NrHe(· ',51), shiftNindoN( 3), clearNindoN, writer· • ,RU, ·(·,El,·, ·,E2,· )'),nl, Nriter \ • ,S2) , shiftNindoN(4),clearwindow, write(·) Which of the following Inforlation do you like to keep·), n 1 , writer· within the Oatabase Application (1/2) :.), cursor(RoN,Col),nl,nl, writer· 1) The relationship • ,RU, 'between the entities ·),nl, writer" ·,El,· and ·,[2:·,·),nl,nl, Nri te(· 2) The .enti ty ., E1, • is a subset of the entity ·,E2,·:), . cursor(Row,Col),readln(Reply), choicehc(Sl,S2,El,E2,R,Reply),!.
choicehc(Sl,S2,El,E2,R, ·1') :. asserta(rel(SI,R)), edge(S2,R,El,ll,Cl), edge(S2,R,E2,l2,C2), asserta(edge(Sl,R,El,ll,C1)), asserta(edge(S2,R,E2,l2,C2)), retract(edge(SI,E1,E2,·ISA·,_)),!. choicehc(S1,S2,El,E2,R,'2') :- retract(rel(S2,R)), retract(edge(S2,R,El,_,_)), retract(edge(S2,R,E2,_,_)), asserta(edge(S2,El,E2,'ISA',")),! , choicehc(Sl,S2,El,E2,R,N):- . cursor(4 ,0), write(" ) It should be '1' or '2"),nl, II!rHer· ) Phase enter again (1/2) :.)' readln("),choicehc(S1,S2,El,E2,R,"),!.
askJc(SI ,S2, El ,E2) : -upper )ower( EIU, El),
47
upper_Iower(E2U,E2), clearwindoN, shiftNindow(2), clearNindoN, display_ent(El,Sl),nl,nl, writer" ",Sl), shiftwindow(3), cleafldndow, display_.nt(E2,S2),nl,nl, write(" ",52), shit twindow( 4), clearwindoN, nl, write(") Is the entity" ,E1U," is a subset of the entity ",E2U ," (yIn) :"),. readln(YN), upper_Iower("N" ,VN), retract(edge(51,El,E2, "ISA" ,J),!. ask_hc(51,S2,El,E2):-asserta(edge(S2,El,E2, "ISA" ,")),!. reltype(contains). reltype(instance). reltype(colponent_of). reltype(possesses). \ reltype(have). reltype(has) • reI type( is_a). reltype(instance_of).
48
/*************************************************************/ /* FILE : CARDC.PRO */ /* il /* Hain Purpose: To identify cardinility conflicts between */ 1* pair of relationships of two views ~nd to resolve them. *1 /* il /* il /* TOP LEVEL PREDICATE card.conf */ 1* */ /* *1 /**************************-**********************************/
Nrite(") Which of the folloNing Rolls you Nant to use for entity '",E, ",a), nl, Nrite(" in the relationship '", R, "' in both the vieNs ~ "),n1, Nrite(" 1) ., L1),nl, Nrite(" 2) ", L2),nl,nl, Nrite(") Please enter your choice (1/2) :"), readln(I), ren_role(Sl,S2,R,E~L1,L2,I),!,
ren_role{Sl,S2,R,E,L1,L2, °2°):-retract{edge(Sl,R,E,L1,C)), asserta(edge(Sl,R,E,L2,C)),!, ren_role(Sl,S2,R,E,Ll,L2,CH) :-nl, Nrite(") The choice should be '1' or '2' ,O),nl, Nrite(o) Please enter your choice again :0), readln(NCH), ren_role(Sl,S2,R,E,ll;L2,HCH),!,
f********"*""'*"*""***"""*'*"""""""'"""**"f I' FILE: DC. PRO *1 1* *1 1* Kain Purpose: To identify and resolve degree conflicts. ;f f* */ f· */ f. TOP LEVEL PREDICATE: dc */ f* */ f""""'****"""""""'*"*"****"'**'***'*""'***'*"f
/*************************************************************/ /* FILE : KEYC. PRO */ /* , */ /* Hain Purpose: To identify key conflicts between pair of */ /* equivalent entities of two views and to resolve thel. */ /* */ /* */ /* TOP LEVEL PREDICATE: key_conf */ /* */ /* .. */ /*************************************************************/
J } For !;Jhat do you wish to design il dat.abase! (? (1 f Ij(iU need ffitlr'e than (me In(Wd ,to respond I t.hen (:r.:rmect the t,,(wds wHh underf.i:core characters.)
··---------[~ef ini t ion--·-"-'~·----·-·Jl·"----·~-------·l User Vtf:Hi.t is Il t~pedfi(;atiun of the canient .... lISTOf" VIEWS :. . t of a dal~base!l41r.WQpriah~ for- a ~ingle ta~tt 1) tt"ip_vielil
,--------Definit ion,------___, ,-----------.... Enti ties are objects about hlh i ch you want to store information in or retrieve information from a database.
The entities might include: Fl ight Passenger Aircraft Person Ticket
LIST OF ENTITIES : 1) da iJ ~tr" ip 2) rQute_seg 3) cl ient 4) passenger
r------------DIALOG~-- ---------, > Ar"e ther"e any more objects ('y'/tH ? y > Enter one name per line. When dons, Press Return ....
> agenc:!:Lno
,-------Def inU lonr-------., ,-----------., Entities Bt'e objects about which yOU want to store information in or retrieve information from a database.
~------------------------~ .--------:EXANPLES----
Airl ine-reservation I·' The entities might include:
Fl ight Passenger Aircraft Person
LIST OF ENTiTIES : 1) dail,~t"rip 2) f'oute_seg 3) cl ient 4) passenger
Ticket I '------_-----.I 1 _______ -----'
,-------------------DIALOG,--""..--------------, AGENCY_NO is a property of the object AGENCY So AGENCY will be added as an ent. ity instead of AGENCY_NO Do you want to give another name for AGENCY (YIN) ? y
sc.'RE.E:f'i -12-
De /'}· 't' .------,- T 1111 100--------. r------------, Attributes are characterst i cs or proped ies of objects that are used to describe it.
r-------tEXAMPLES--------. The attributes for the entiyies might include: Ent it.y AHri butes
} Ho!;] 'fvf' ent i lIJ : • DAIlYTRIP Uri.Ullhdep_.dt'::Jtat"r_c:H!J1t~peJ .. ,. I:,: > tute:' the ath-Um'ie Und; hat $~M~f'td ",ahHt~ ~Ot~ each .. : ~ I (nstanc* of the enHtq DA1LYTRll' ,-'
l,En:= __ .\.:r.iW:in~:=:R.t~~ __ J;
r;;:::-f.~:7~·:::~::-I' o::"-bta'-::I~~:''';~~:I~ I ~:ll:~~:::~-·f·:··::::-. '::.:'J-;w~·:.--::~:-·-··----·-----l
lr ;,1'. ~':l""" U f.J.*1J1 ,,,'H,,.. ..... ft~\~:::e :f./;.it 1hlJ1·". ~~~'ttAIii. ,., .. ~~ 1\·.,t~1 I~'l ~'l 1 .. ,~'t; .1.lI"~i! o:..u.u i
""tJll."f·t. !"iC.<· ·i/-i. ~.'!l!}-f J~llllth'"'' el~.I·I' H'~ IW't.l b/, !'f'(lul"ed lU ,11.>I!r'>'''liflf' I ..-" • ..., ·"~· ...... i· 1>' t .. .l' • .... ~7' _'\;oj ~ 10,..' ~ ... ~:, '14" .. , /iO-- \":~', 'i' IV e</-", ... l. olt ' f.., I 11.;" 'iall'''''''' (.1' J>ll ~I"" ,,' t.,:L .. ~ ........ j' ·H·.~, <'i'~ :.\, ' I (.,k" ."' ... '" .·1 Mi , .• \;1 .... ,., .!J .... ,.~." I)T ,,, .... k ,\,. ,.). 'j!
.... --. ".".~. ' ...... ~--'--.-.• Df.f in i i l on------~.-~-~--]-.. r-'--. -'-~-~"-'.~--'--.-Th~ k~1J of em tlutHy it Hie list t)f (tUdbutes LIST (IF KEYS OF 'i.het deter':'flane U~fJ \t~lues. of all ~ther nnn'i : da~ 19tdp
,aHr'ibuhlS of ihe errUtiJ. . , ",..--. ...... --..... "' ............. -~-~~~.------~----.. -r-----~fl~Hf:TAi~j1PLES----·~-··--~-·l
I. if! 1 gI~ lJlulOber 0 ity-fI'Oill c ity-tq i ! ,
t 47 Bou-;bay Ltmdon . -----~----" .. - .. 707 Ue!;.! lie 1 hi Par i $
DJ1ILYTRIP r tpip~p!,hdej:.U,;d·1.:1,. at'f'_C it,tJt t-tJpeJ I } £u'C er the dUX Hwhs: Hart· fO:~lli$ tht1 key. t i Enter i]!'It ~.ttdbute p~f" ) ine. t!fhen done, Pn~':$~ Rehlt'n ..•.•
> tr ip_rK~
'.SCR(EN- 1 q
~·T· 1.- '(-e:-~f" '."~,~ :'I~;l:~ef ,~n :~~fJ~~':;-:~ ~, !'~b";:-]' 'r' ~";~;-;;-·~cv~"·~;'''--~--·--~''I he ), ;? 0 a" .... I, .. ~ ".' ... 1<", L. '';;'. ". ~~' ...... :'. ... t·e~ :., ..... '.;I. '. :!f . '\L. I ': VI' I H~at . deh·t~~HlIi: "ht:'. 'JlllU/;;$ (ff all ::the:~ I £H!l n' : c ~ umt I i].Hf'lb'Jtf:s of the 6'ntd';l. i client. ( Hv 1
r-"~-~L£S~J··II I, i ~n ight.J~ullibe(~ cit'rf'rt'tfll i,;:H'rbl t .
747 tkrrnba'J b:mdtm --,'" -~-----"---' 797 Helt! Delhi Par-is ATTfHBUT£S ~*" THE PRESENT I 717 Bomba'} Net~-'{tJ('k kEY or EtnTf'l ! d; ent
Ii t~~~'~--:r;~;~;~;'~~~:'~:'~'-~~'~~:i~:;-~':;":~ 1 -the ~ ~ ~i:~l:nu j etlii' ie~ in Uds tabl~. Hence NUfuher' hi a I<~·;. ___ .,... ___ ~_ ... ______________ .. 1 ... ___ ~ ... ____ . ___ ... ___ ........._.
D f i . t· r---- - '8 n 1 1011--------. r------------. R.e I a.t i oosh i P$ are a~·soc i at i OilS betlJ.\een tt.110 or IllUf'e ent it i es •
r------....,EXAf1PlES ...... · --.-----.--,.
Re 1 at. i oO$n i p : Pas1;,enger reserves-for night
Here "reser'v£-for" aSSOt iates the tttlO
el1t it i es: PASSENGER and F'LI GHT .
Hence fMerves-for is a binar9 relationship.
LIST Of RELATlOHSHIPS : holders ( client,route_ses
J
~---------------.------------------~~-----------------~ ....----------... '·-DIALOG·--~--- -, _. --_._---._-} Are there any more rila.iionships (YIN) ? ~ > cl ient is_()n~.board r1)ute_seg
~-~.. Definition.--------I ....... -----------
Relationships are associations between UST or RELATIONSHIPS : . twa at"' t1ICII~e entities. holders [ c1ient.,rf;lu1.e_~e9
1 ---r------~--EXAJ1PLES -•. -------
Air 1 ineJeservat ioo_Syst.em
Hef'''' ., 'e "". -.... tC!ru --',..1. 110 .... '$ ... rv~-, 1· assac l .... \·e~
ent ities:PASSEttGER and fUfiHT.
Hefll:;e f'eserves-ffJr is a binat"Y relationship. "--________ .. __ ------......-1 -----.. __ . _______ ---' Give the ~~-:;-;;;:nt i t; cl i'e~·t.DI~~le··I~~;io~;·i~~· i~;;j;~;l
> R{)le :
Give the 1~lJle of th~ ~fltit!.J r(ltl'te~s.~g in ~.he f'1~le:lioMhip hU:.mJ1QRf'dl
} Select the apprQpriate opt.ions from 'the follol).!ing r~nu to dQ the modifications.
1. Mod if!; Ent i ti i es • 2. Modify Relationships. 3. Exit..
> Select yourchtiice '~ 1
Sod<, E £ rJ ~ 2-2t
....--------------1:. ~:DIT-Ef'lTlTlES,----------__. > Select the appropriate options from the following
menu to do the modifications.
1. Add Entities. 2. Delete Entities. 3. Rename entities. 4. Add attribute to Entities. 5. Delete Attributes from Entities. 6. Rename attributes of entitles. 7. Exit
> Select Your Choice: 3
.--------------DIALOG(-i--------------.
-'>~S-e' led -U-;e-r:-",p-p-,'o-p-r-ia''te {) li·s·r···Of-£'-N-T-H-I-ES~-:-----'-1 menu t.o do the modificai H dai hl~;rip I
2) route_seg
I I
1. Add Entities. J) client 2. De lete Errtii i,es. 3. Rename entities. 4. Add at. tr ibute to Ent, i 5, De lete Aiir'ibutes ~'PIJ 6. Rename aUribu{~es of (. Exit
.-------------t.DlT-EiiT1TIES-·------------, > Select. t.he appropriat.e opth.f \1S from the fcllowing
menu to do the modifications.
1. Add Entities. 2. De lete tnt it. ies. 3. ReMJile ent.ities. 4. Add attribute to Entities. S. Delete Attf'ibutes from Ent.ities. G. Rename at.tributes. of entities, 7. Exit
> Selt~t Your Choice: 5
·---------DIALOGr----------------,
AGEtiCY [f1gef!c!J_nD 1 fifl: cred it._limi tJ > Do ~.!OU b.lant to de let.e attributes from AGE~C,( (Vim 1 iJ
[ you ... nt to delete NO {Yilii : y
.......... -----._._.,. .. _. __ • __ ----l
View: trip_view Entities Attributes
dai 1 y_.tri p route __ seg c 1 i ent passenger agency
r--·-- ·-----·---·--~C'h~d.':..·l e I} i elil'--·---.. ---·-'··---~---~--·'1 TO' P···I . t . . ! .. '-. " . I' .. , .... , 'I "'''''fl'' 1" , ~,·",·"~· ..... ·,·t,, "';;'I~/'!1"!!"" ""n,;; """;:'11·' ~rln l"li'i J "" ..... , ._" ..... t nJ- ~ 1.,..li-I r " _1 .",t.1It '_I.""'4':/U'''·\..-\\J'U'7~''\''.t''''''''!,;,'·''W ("IIl- f<" ,fw I - -., ... !
I I L __ ._ .. _ .. __ .. __ ~._. _____ .. __ ._. __ , .. __ ._. ____ . __ J r-·-----· .. -----·--·----· .. -----D I ALOG-------·-·-----·-.. -···~-·--·--·----·-til' Hhicb of the f'cllol.!dn£l reiElJionship hold$ hi¥' these entitie:s I
of the hJu I.liei).!$ ; ! i 1) The entities are e:,hdh; ~aille inut1th the Vif:";W;;:. f 2! The enU't:1 DAILYIRIP [;f' !tdp_yiew' is a sljbs~t of the efrI:.HI~; »
r·----·-·----·-.... -----"··nIj~\..OG_--,-··---·---.. -·-rl.-.-"--1 Ii' .;. !.lh 1 (,I-, pCI ~·I·"e· f .. · 'Il fi l ,,; "1'1 ~,~ 1 ''If ; ,. ..... r. .• ~.;" 1",1,1",. [:r •• ' ",-I,"!'!"'" ""r,'} j·t I' eo' I' I I·U' .. I~'..J \. 1 I ........... ·t.:'~'ll~::..f 1 Li \O!''''';.. .... ·~twil4''tJ' '~'<i'At.t;.;· "VII \- ,...,~ ... \...>~t':. J;" J.'
I ~f th~ lwo vie~8 : t I 1) The eilt.iii~s .11"8 exact.l~ s,::rme in both the ')i!:..~W;L i l 2) The enUty R0UTE_S:EG of ~l~dp._"i'ii:t;.l! is a $:..rk!1ei: of' the entih) I ! OPDJ~OIJTE_SEG of t.ht:, s;chedule_.viet,J. t I 3) Th!: ent.it'~ ORD_ROU1E_.~}EG IJf 'st:htduli3_':ielL1' is Ii suo$et of tbe entHy J J p'nUTE c'Er f' i., f·,. '. .' i I, .~ _ . .;, 30 IJ.le ,.,lp_,.le1.11. J
L ~-------------------------DIALO~-~-·--------------------~ > ~\Ihich of the follol!ting relalionship hulds for t.hese entities
of the t.wo 'v'ielt.!s : 1) The entities are e:(actly saffle in both theviel.l.ls. 2} The entity DAILY.JRIP of 'driver.Jile' i11: a subset of the entity
DAILY TRIP of the bus file. 3) The eoUty DAllY_TRIP-of 'bus._file' is a subset. of the entity
DAILY_TRIP of the driver_file,. 4) Both the entities DAILY_TRIP and DAILY_TRIP hav.~ a common demain. S) None of t.he above are t.rue
> Enter' your choice (1-5) : ~I----------------------------------.-"-,------------.------.--~
I SC. HEDULEJ-'I EI1 Attributes at I
Cr .... ' t ... I ..... ". ':} . I
1 ~~~~------··-------i I __ ~::~~:~~--------I type
~----------- ~'-----------, .-----.-r --- .. DIALOGi---" -----------> If t.he pail' of attributes in t.he ('01.1.1 and column l' ,"
M'e !J9nonyms thtm entef' (Y), othenl.lise enter Hi).
·L _____________________ , _J s~~rJ-4~
[ , ' 'l~' ,AHribute.)~ynonyfrl assedion' l
SCHEDULE_ V I £1.1 TR I P _VI EN ('lAo t I" q. ".j. '"'''' ot I At J. "1' b .. te<, of ::'nt l'tll • RnuITC' e'Er- ' ~ "d .. · ~ J. .. J·..t,.~~·v • ,l~1 \.i ..... ..:.. to.... ':I'" .. \.I" llt._..) ~' 1 lEnt i .~~ : I -.-----------------------------------.~---.~ .. -----------------1 r,i;)fl P, '!I JiE ~~r.; dat e J·o.t a I "eat<' "'e""ef"'V "e,"'t~ i
It~i,\,.~_t\';J_. -~' .. " •. t, -I~ J,_~ , ..,,:. I ~ -.~ iA .... . I --~;;-:~~~-------- ---~--------------~---.----.. ------~------------------------ .