Both sides previous revision
Poprzednia wersja
Nowa wersja
|
Poprzednia wersja
|
pl:miw:miw2008_xtt_xmlpro [2008/06/09 19:22] miw |
pl:miw:miw2008_xtt_xmlpro [2019/06/27 15:50] (aktualna) |
====== Opis ====== | ====== Opis ====== |
| __**Projekt zakończony**__ |
| |
Maksymilian Imioło <maximiolo@o2.pl> | Maksymilian Imioło <maximiolo@o2.pl> |
| |
Translacja XTTML do innych formatów z użyciem Prologu. | Translacja XTTML do innych formatów z użyciem Prologu. |
| |
====== Spotkania ====== | |
===== 08.03.04 ===== | |
* parsowanie xml w prologu | |
* obsługa XSD w prologu | |
* poczytac: graphviz, RIF | |
| |
| |
| |
===== 080318 ===== | |
* poczytać... | |
| |
===== 080408 ===== | |
* translacja [[hekate:hekate_markup_language|HML/ARDML]] (produkowanego przez [[hekate:VARDA]]) | |
* przykład z [[hekate:hekate_case_thermostat]] therm jako p. odn. | |
* podejście: | |
- mamy plik ARDML z Vardy (axg.) | |
- parsujemy go w prologu | |
- generujemy bazę wiedzy prologową dla VARDA (ard_att/1, ard_property/1, ard_depend/2, ard_hist/2) (assert(ard_att('Thermostat'))) (czyli to, co dostaniemy po listing(ard_depend),listing(ard_attribute),listing(ard_property),listing(ard_hist).) | |
- generujemy odpowiadający mu plik DOT | |
| |
http://www.swi-prolog.org/packages/sgml2pl.html | ====== Spotkania====== |
load_xml_file(+File, -ListOfContent) | |
| [[pl:miw:miw2008_xtt_xmlpro:spotkania|Spotkania]] |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
np: | |
<att name="Thermostat"/> -> assert(ard_att('Thermostat')). | |
| |
| |
| |
===== 080415 ===== | |
* parsowanie listy | |
| |
===== 080422 ===== | |
* generowanie prologu | |
| |
| |
| |
| |
===== 080603 ===== | |
* testy kodu dla varda, po ang, upload do wiki | |
* [[pl:miw:miw08_xtt_rif|XTT i RIF]] | |
===== 080610 ===== | |
* sprawozd | |
| |
====== Projekt ====== | ====== Projekt ====== |
| |
Plik do parsowania: {{:pl:miw:ard-vardy.xml|:pl:miw:ard-vardy.xml}} | Plik do parsowania: {{:pl:miw:ard-vardy.xml|:pl:miw:ard-vardy.xml}} |
| |
| |
| |
| |
| |
| |
| |
| |
Translator można uruchomić na kilka sposobów: | Translator można uruchomić na kilka sposobów: |
1 | ===1=== |
Załadować plik źródłowy i wpisać : translate('Source.xml','Destination.xml'). | Załadować plik źródłowy i wpisać : translate('Source.xml','Destination.xml'). |
Otrzymamy wydruk na ekranie monitora oraz, zapis do wskazanego pliku. | Otrzymamy wydruk na ekranie monitora oraz, zapis do wskazanego pliku. |
2 | ===2 === |
Załadować plik źródłowy i wpisać : translate('Source.xml'). | Załadować plik źródłowy i wpisać : translate('Source.xml'). |
Otrzymamy wydruk na ekranie monitora, jeśli będziemy chcieli zapisać do pliku to należy | Otrzymamy wydruk na ekranie monitora, jeśli będziemy chcieli zapisać do pliku to należy |
wpisać: save('Destination.xml'). | wpisać: save('Destination.xml'). |
3 | === 3 === |
Można połączyć translator bezpośrednio z vardą umieszczając odpowiedni wpis w pliku "VARDA.pl", | Można połączyć translator bezpośrednio z vardą umieszczając odpowiedni wpis w pliku "VARDA.pl", |
":-ensure_loaded('varda_pl2xml').", dzięki temu no załadowaniu vardy i wygenerowaniu pliku przy pomocy axg, | ":-ensure_loaded('varda_pl2xml').", dzięki temu no załadowaniu vardy i wygenerowaniu pliku przy pomocy axg, |
Poniżej znajdujesię kod translatora. | Poniżej znajdujesię kod translatora. |
<code prolog> | <code prolog> |
| |
| |
%%%%%%%%%%%%%%%%%%%%% Load %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%% Load %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| |
show, % wyświetlenie wyników | show, % wyświetlenie wyników |
save(Dest). %zapis wyniku | save(Dest). %zapis wyniku |
| |
| |
translate(Source):- | translate(Source):- |
load_structure(Source,X,[space(remove),dialect(xml)]),Z=..X,assertz(Z),element(hml,_,A), | load_structure(Source,X,[space(remove),dialect(xml)]),Z=..X,assertz(Z),element(hml,_,A), |
checkAtt(A),checkProperty(A),checkHistory(A),checkDepend(A),show. | checkAtt(A),checkProperty(A),checkHistory(A),checkDepend(A),show. |
%%%%%%%%%%%% Show %%%%%%%%%%%%%%% | |
| %%%%%%%%%%%% Wyswietl%%%%%%%%%%%%%%% |
show:- | show:- |
listing(ard_att),listing(ard_property),listing(ard_hist),listing(ard_depend). | listing(ard_att),listing(ard_property),listing(ard_hist),listing(ard_depend). |
| |
%%%%%%%%%%%%%%%%%%%%%%%%%%% Save to file %%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%% Save to file %%%%%%%%%%%%%%%%%%%%%% |
save(Dest):- | save(Dest):- |
tell(Dest),write('<?xml version="1.0" encoding="utf-8"?>'), | tell(Dest),write('<?xml version="1.0" encoding="utf-8"?>'), |
listing(ard_att),listing(ard_property),listing(ard_hist), | listing(ard_att),listing(ard_property),listing(ard_hist), |
listing(ard_depend),told. | listing(ard_depend),told. |
%%%%%%%%%%%%%%%%%%%%% Attribute_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| %%%%%%%%%%%%%%%%%%%%% Attribute_set%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| |
| |
checkAtt(A):- | checkAtt(A):- |
include(element(attribute_set,_,L),A), % sprawdzanie istnienia elementu | include(element(attribute_set,_,Li),A), % sprawdzanie istnienia elementu |
leng(L,Dl1), % wylicznie dlugości listy | leng(Li,Dl1), % wylicznie dlugości listy |
assert(viewList(List)), % deklarowanie pamięci | assert(viewList(_)), % deklarowanie pamięci |
showAtt(L,Dl1,0). | showAtt(Li,Dl1,0). |
| |
showAtt(L,0,Dl). | |
| showAtt(_,0,_). |
showAtt(L,D1,Dl):- | showAtt(L,D1,Dl):- |
D1>0, | D1>0, |
NewDlu is D1-1, | NewDlu is D1-1, |
deleteOne(Dl,L,element(att,[name=ZX,id=ID,_,_],[])), | deleteOne(Dl,L,element(att,[name=ZX,_,_,_],[])), |
string_length(ID,LENG), | assert(memory(ZX)), |
LEE is LENG-4, | memory(ZX), |
assert(memory(ZX)), | assert(ard_att(ZX)), |
memory(ZX), | viewList(LisGlob),add(LisGlob,ZX,LisGlob2), |
sub_string(ID,4,LEE,_,WY), | retractall(viewList(_)), |
assert(ard_att(ZX)), | assert(viewList(LisGlob2)), |
viewList(LisGlob),add(LisGlob,ZX,LisGlob2), | retractall(memory(_)), |
retractall(viewList(_)), | DlNew is Dl+1, |
assert(viewList(LisGlob2)), | showAtt(L,NewDlu,DlNew). |
retractall(memory(_)), | |
DlNew is Dl+1, | |
showAtt(L,NewDlu,DlNew). | |
| |
%%%%%%%%%%%%%%%%%%%%% Property_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%% Property_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
checkProperty(A):- | checkProperty(A):- |
include(element(property_set,_,L2),A), | include(element(property_set,_,L),A), |
leng(L2,D2), | leng(L,D), |
assert(view(ListaGl)), | assert(view(_)), |
showProp(L2,D2,0). | showProp(L,D,0). |
| |
showProp(L2,0,Dl2). | showProp(_,0,_). |
showProp(L2,D2,Dl2):- | showProp(L2,D2,Dl2):- |
D2>0, | D2>0, |
NewDlu2 is D2-1, | NewDlu2 is D2-1, |
deleteOne(Dl2,L2,element(property,_,C)), | deleteOne(Dl2,L2,element(property,_,C)), |
leng(C,CA), | leng(C,CA), |
writeProp(CA,C,[]),memoryList(Lista),assert(ard_property(Lista)), | writeProp(CA,C,[]),memoryList(Lista),assert(ard_property(Lista)), |
view(ListaGlob),add(ListaGlob,Lista,ListaGlob2), | view(ListaGlob),add(ListaGlob,Lista,ListaGlob2), |
retractall(view(_)), | retractall(view(_)), |
assert(view(ListaGlob2)), | assert(view(ListaGlob2)), |
retractall(memoryList(_)), | retractall(memoryList(_)), |
DlNew2 is Dl2+1, | DlNew2 is Dl2+1, |
showProp(L2,NewDlu2,DlNew2). | showProp(L2,NewDlu2,DlNew2). |
| |
writeProp(0,L,Lista). | writeProp(0,_,_). |
writeProp(CA,[J1|L1],Lel):- | writeProp(CA,[J1|L1],Lel):- |
CA>0, | CA>0, |
CNew is CA-1, | CNew is CA-1, |
showFirst(J1,element(attref, [ref=Bb], [])), | showFirst(J1,element(attref, [ref=Bb], [])), |
string_length(Bb,L), | string_length(Bb,L), |
LEEE is L-4, | LEEE is L-4, |
sub_string(Bb,4,LEEE,_,WYJ), | sub_string(Bb,4,LEEE,_,WYJ), |
checkProp(WYJ,Insert), | checkProp(WYJ,Insert), |
add(Lel,Insert,Lista1), | add(Lel,Insert,Lista1), |
retractall(memoryList(_)), | retractall(memoryList(_)), |
assert(memoryList(Lista1)), | assert(memoryList(Lista1)), |
writeProp(CNew,L1,Lista1). | writeProp(CNew,L1,Lista1). |
| |
showFirst(L,L). | showFirst(L,L). |
%%%%%%%%% | %%%%%%%%% |
checkProp(Output,Name):- | checkProp(Output,Name):- |
atom_number(Output,Wyj), | atom_number(Output,Wyj), |
viewList(All), | viewList(All), |
NWyj is Wyj+1, | NWyj is Wyj+1, |
showName(All,NWyj,Name). | showName(All,NWyj,Name). |
| |
showName(All,1,Name):- | showName(All,1,Name):- |
deleteOne(0,All,Name). | deleteOne(0,All,Name). |
| |
showName(All,Wyj,Name):- | showName(All,Wyj,Name):- |
deleteOne(Wyj-1,All,Name). | deleteOne(Wyj-1,All,Name). |
| |
%%%%%%%%%%%%%%%%%%%%% Hist_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%% Hist_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
checkHistory(A):- | checkHistory(A):- |
include(element(tph,_,L1),A), | include(element(tph,_,L1),A), |
leng(L1,D1),showlHist(L1,D1,0). | leng(L1,D1),showlHist(L1,D1,0). |
| |
showlHist(L1,0,Dl). | showlHist(_,0,_). |
showlHist(L1,D1,Dl):- | showlHist(L1,D1,Dl):- |
D1>0, | D1>0, |
NewDlu is D1-1, | NewDlu is D1-1, |
deleteOne(Dl,L1,element(trans,[src=Source,dst=Destination],[])), | deleteOne(Dl,L1,element(trans,[src=Source,dst=Destination],[])), |
string_length(Source,L), | string_length(Source,L), |
LEEE is L-4, | LEEE is L-4, |
sub_string(Source,4,LEEE,_,WYJ), | sub_string(Source,4,LEEE,_,WYJ), |
string_length(Destination,LG), | string_length(Destination,LG), |
LEEEE is LG-4, | LEEEE is LG-4, |
sub_string(Destination,4,LEEEE,_,Output), | sub_string(Destination,4,LEEEE,_,Output), |
checkHist(WYJ,Output,Z,D),assert(ard_hist(Z,D)), | checkHist(WYJ,Output,Z,D),assert(ard_hist(Z,D)), |
DlNew is Dl+1, | DlNew is Dl+1, |
showlHist(L1,NewDlu,DlNew). | showlHist(L1,NewDlu,DlNew). |
| |
%%%%%%%%%%%%%% Get src i dest %%%%%%%%%% | %%%%%%%%%%%%%% Get src i des t%%%%%%%%%% |
checkHist(Zr,De,Zrod,Dest):- | checkHist(Zr,De,Zrod,Dest):- |
atom_number(Zr,Zrr), | atom_number(Zr,Zrr), |
atom_number(De,Dee), | atom_number(De,Dee), |
view(All), | view(All), |
NZrr is Zrr+1, | NZrr is Zrr+1, |
NDee is Dee+1, | NDee is Dee+1, |
showPropert(All,NZrr,Zrod), | showPropert(All,NZrr,Zrod), |
showPropert(All,NDee,Dest). | showPropert(All,NDee,Dest). |
| |
showPropert(All,1,Output):- | showPropert(All,1,Output):- |
deleteOne(0,All,Output). | deleteOne(0,All,Output). |
| |
showPropert(All,Position,Output):- | showPropert(All,Position,Output):- |
deleteOne(Position-1,All,Output). | deleteOne(Position-1,All,Output). |
| |
%%%%%%%%%%%%%%%%%%%%% Depend_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%% Depend_set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
checkDepend(A):- | checkDepend(A):- |
include(element(ard,_,LisDep),A), | include(element(ard,_,LisDep),A), |
leng(LisDep,DlDep),wyswietlDepe(LisDep,DlDep,0). | leng(LisDep,DlDep),wyswietlDepe(LisDep,DlDep,0). |
| |
wyswietlDepe(L1,0,Dl). | wyswietlDepe(_,0,_). |
wyswietlDepe(L1,D1,Dl):- | wyswietlDepe(L1,D1,Dl):- |
D1>0, | D1>0, |
NewDlu is D1-1, | NewDlu is D1-1, |
deleteOne(Dl,L1,element(dep,[independent=Ind,dependent=Dep],[])), | deleteOne(Dl,L1,element(dep,[independent=Ind,dependent=Dep],[])), |
string_length(Ind,L), | string_length(Ind,L), |
LEEE is L-4, | LEEE is L-4, |
sub_string(Ind,4,LEEE,_,WYJ), | sub_string(Ind,4,LEEE,_,WYJ), |
string_length(Dep,LENG), | string_length(Dep,LENG), |
LEE is LENG-4, | LEE is LENG-4, |
sub_string(Dep,4,LEE,_,Output), | sub_string(Dep,4,LEE,_,Output), |
checkDep(WYJ,Output,Indep,Depen),assert(ard_depend(Indep,Depen)), | checkDep(WYJ,Output,Indep,Depen),assert(ard_depend(Indep,Depen)), |
DlNew is Dl+1, | DlNew is Dl+1, |
wyswietlDepe(L1,NewDlu,DlNew). | wyswietlDepe(L1,NewDlu,DlNew). |
| |
%%%%%%%%%%%%%% Get independent i dependent %%%%%%%%%%%%%% | %%%%%%%%%%%%%% Get independent i dependent %%%%%%%%%%%%%% |
checkDep(In,De,InOut,DeOut):- | checkDep(In,De,InOut,DeOut):- |
atom_number(In,Inn), | atom_number(In,Inn), |
atom_number(De,Depe), | atom_number(De,Depe), |
view(All), | view(All), |
NInn is Inn+1, | NInn is Inn+1, |
NDepe is Depe+1, | NDepe is Depe+1, |
showDependent(All,NInn,InOut), | showDependent(All,NInn,InOut), |
showDependent(All,NDepe,DeOut). | showDependent(All,NDepe,DeOut). |
| |
showDependent(All,1,Output):- | showDependent(All,1,Output):- |
deleteOne(0,All,Output). | deleteOne(0,All,Output). |
| |
showDependent(All,Position,Output):- | showDependent(All,Position,Output):- |
deleteOne(Position-1,All,Output). | deleteOne(Position-1,All,Output). |
| |
%%%%%%%%%%%%%%%%%%%%%%%%%%% Others %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%% Others %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
add([G|O],X,[G|R]):- | add([G|O],X,[G|R]):- |
add(O,X,R). | add(O,X,R). |
| |
| |
| |
{{:pl:miw:varda_pl2xml.pl|Translator}} {{:pl:miw:input.xml|Plik wejściowy}} {{:pl:miw:out.pl|Plik wyjściowy}} | {{:pl:miw:varda_pl2xml.pl|Translator}} {{:pl:miw:input.xml|Plik wejściowy}} {{:pl:miw:out.pl|Plik wyjściowy}} |
| |
| |
| Dla potrzeb wyświetlenia wyników plik wyjściowy został powyżej dołączony z rozszerzeniem pl. |
| |
| |
assert(view(ListaGlob2)), | assert(view(ListaGlob2)), |
retractall(memoryList(_)), | retractall(memoryList(_)), |
| </code> |
| ===Podczas kompilacji=== |
| Podczas kompilacji otrzymuję komunikat, który jednak nie ma wpływu na otrzymany wynik translacji. |
| <code prolog> |
| ERROR: SGML2PL(xml): input.xml:2: file ".\hml.dtd" does not exist |
| </code> |
| Błąd ten dotyczy linijki, która pojawiła sie w wersji 1 Vardy. |
| <code prolog> |
| <!DOCTYPE hml SYSTEM "hml.dtd"> |
| |
</code> | </code> |
| |