%%%%%%%%%%%%%%%%%%%%% Load %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% translate(Source,Dest):- load_structure(Source,X,[space(remove),dialect(xml)]), %załadowanie pliku Z=..X,assertz(Z),element(hml,_,A), %wyciągnięcie elementu hml checkAtt(A), %analiza elementu "attribute_set" checkProperty(A), %analiza elementu "property_set" checkHistory(A), %analiza elementu "tph" checkDepend(A), %analiza elementu "ard" show, % wyświetlenie wyników save(Dest). %zapis wyniku translate(Source):- load_structure(Source,X,[space(remove),dialect(xml)]),Z=..X,assertz(Z),element(hml,_,A), checkAtt(A),checkProperty(A),checkHistory(A),checkDepend(A),show. %%%%%%%%%%%% Wyswietl%%%%%%%%%%%%%%% show:- listing(ard_att),listing(ard_property),listing(ard_hist),listing(ard_depend). %%%%%%%%%%%%%%%%%%%%%%%%%%% Save to file %%%%%%%%%%%%%%%%%%%%%% save(Dest):- tell(Dest),write(''), listing(ard_att),listing(ard_property),listing(ard_hist), listing(ard_depend),told. %%%%%%%%%%%%%%%%%%%%% Attribute_set%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% checkAtt(A):- include(element(attribute_set,_,Li),A), % sprawdzanie istnienia elementu leng(Li,Dl1), % wylicznie dlugości listy assert(viewList(_)), % deklarowanie pamięci showAtt(Li,Dl1,0). showAtt(_,0,_). showAtt(L,D1,Dl):- D1>0, NewDlu is D1-1, deleteOne(Dl,L,element(att,[name=ZX,_,_,_],[])), assert(memory(ZX)), memory(ZX), assert(ard_att(ZX)), viewList(LisGlob),add(LisGlob,ZX,LisGlob2), retractall(viewList(_)), assert(viewList(LisGlob2)), retractall(memory(_)), DlNew is Dl+1, showAtt(L,NewDlu,DlNew). %%%%%%%%%%%%%%%%%%%%% Property_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% checkProperty(A):- include(element(property_set,_,L),A), leng(L,D), assert(view(_)), showProp(L,D,0). showProp(_,0,_). showProp(L2,D2,Dl2):- D2>0, NewDlu2 is D2-1, deleteOne(Dl2,L2,element(property,_,C)), leng(C,CA), writeProp(CA,C,[]),memoryList(Lista),assert(ard_property(Lista)), view(ListaGlob),add(ListaGlob,Lista,ListaGlob2), retractall(view(_)), assert(view(ListaGlob2)), retractall(memoryList(_)), DlNew2 is Dl2+1, showProp(L2,NewDlu2,DlNew2). writeProp(0,_,_). writeProp(CA,[J1|L1],Lel):- CA>0, CNew is CA-1, showFirst(J1,element(attref, [ref=Bb], [])), string_length(Bb,L), LEEE is L-4, sub_string(Bb,4,LEEE,_,WYJ), checkProp(WYJ,Insert), add(Lel,Insert,Lista1), retractall(memoryList(_)), assert(memoryList(Lista1)), writeProp(CNew,L1,Lista1). showFirst(L,L). %%%%%%%%% checkProp(Output,Name):- atom_number(Output,Wyj), viewList(All), NWyj is Wyj+1, showName(All,NWyj,Name). showName(All,1,Name):- deleteOne(0,All,Name). showName(All,Wyj,Name):- deleteOne(Wyj-1,All,Name). %%%%%%%%%%%%%%%%%%%%% Hist_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% checkHistory(A):- include(element(tph,_,L1),A), leng(L1,D1),showlHist(L1,D1,0). showlHist(_,0,_). showlHist(L1,D1,Dl):- D1>0, NewDlu is D1-1, deleteOne(Dl,L1,element(trans,[src=Source,dst=Destination],[])), string_length(Source,L), LEEE is L-4, sub_string(Source,4,LEEE,_,WYJ), string_length(Destination,LG), LEEEE is LG-4, sub_string(Destination,4,LEEEE,_,Output), checkHist(WYJ,Output,Z,D),assert(ard_hist(Z,D)), DlNew is Dl+1, showlHist(L1,NewDlu,DlNew). %%%%%%%%%%%%%% Get src i des t%%%%%%%%%% checkHist(Zr,De,Zrod,Dest):- atom_number(Zr,Zrr), atom_number(De,Dee), view(All), NZrr is Zrr+1, NDee is Dee+1, showPropert(All,NZrr,Zrod), showPropert(All,NDee,Dest). showPropert(All,1,Output):- deleteOne(0,All,Output). showPropert(All,Position,Output):- deleteOne(Position-1,All,Output). %%%%%%%%%%%%%%%%%%%%% Depend_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% checkDepend(A):- include(element(ard,_,LisDep),A), leng(LisDep,DlDep),wyswietlDepe(LisDep,DlDep,0). wyswietlDepe(_,0,_). wyswietlDepe(L1,D1,Dl):- D1>0, NewDlu is D1-1, deleteOne(Dl,L1,element(dep,[independent=Ind,dependent=Dep],[])), string_length(Ind,L), LEEE is L-4, sub_string(Ind,4,LEEE,_,WYJ), string_length(Dep,LENG), LEE is LENG-4, sub_string(Dep,4,LEE,_,Output), checkDep(WYJ,Output,Indep,Depen),assert(ard_depend(Indep,Depen)), DlNew is Dl+1, wyswietlDepe(L1,NewDlu,DlNew). %%%%%%%%%%%%%% Get independent i dependent %%%%%%%%%%%%%% checkDep(In,De,InOut,DeOut):- atom_number(In,Inn), atom_number(De,Depe), view(All), NInn is Inn+1, NDepe is Depe+1, showDependent(All,NInn,InOut), showDependent(All,NDepe,DeOut). showDependent(All,1,Output):- deleteOne(0,All,Output). showDependent(All,Position,Output):- deleteOne(Position-1,All,Output). %%%%%%%%%%%%%%%%%%%%%%%%%%% Others %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % sprawdzanie istnienia elementów w liście include(X,[X|_]). include(X,[_|Tail]) :- include(X,Tail). % obliczanie długości listy leng([],0). leng([_|Tail],Dlug) :- leng(Tail,X), Dlug is X+1. % wyciąganie konkretnego elementu listy deleteOne(0,[F|_],F). deleteOne(Poz,[_|Xx],W):- Poz>0, PozNew is Poz-1, deleteOne(PozNew,Xx,W). % dodanie do listy add([],X,[X]). add([G|O],X,[G|R]):- add(O,X,R).