[[
✎ pl:miw:miw08_prolog_xml:prolog_api
]]
aiWiki
Pokaż stronę
Ostatnie zmiany
Indeks
Zaloguj
Ta strona jest tylko do odczytu. Możesz wyświetlić źródła tej strony ale nie możesz ich zmienić.
===== API ===== ==== Wersja 1 - płaska struktura ==== <code prolog> delete(A, [A|B], B). delete(B, [A|C], [A|D]) :- delete(B, C, D). add(A, B, [A|B]). make_node(Name,List) :- add(element(Name, [], []), [], List), X=..List, assert(X), write(List). make_node(Name, Attr, Cont, List) :- add(element(Name, Attr, Cont), [], List), X=..List, assert(X), write(List). add_child(Parent,Child,Nlist):- element(Parent,A,C), retract(element(Parent,A,C)), add(element(Child,[],[]),C,L), make_node(Parent,A,L,Nlist). add_child(Parent,Child,Ch_att,Ch_cont,Nlist):- element(Parent,A,C), retract(element(Parent,A,C)), add(element(Child,Ch_att,Ch_cont),C,L), make_node(Parent,A,L,Nlist). make_list(List) :- bagof(A,element(A,B,C),A), L=..A, add(element(L,B,C),[],List), write(List). save :- tell('wiedza.pl'), listing(element), told. prolog2xml(List,File):- tell(File), open(File,write,S), xml_write(S,List,[]), told, close(S). ---------------------------------- add_child(Parent,Child,Nlist):- element(Parent,A,C), element(Child,Chatt,Chcont), retract(element(Parent,A,C)), retract(element(Child,Chatt,Chcont)), add(element(Child,Chatt,Chcont),C,L), make_node(Parent,A,L,Nlist). add_child(Parent,A,Child,Chatt,Nlist):- element(Parent,A,C), element(Child,Chatt,Chcont), retract(element(Parent,A,C)), retract(element(Child,Chatt,Chcont)), add(element(Child,Chatt,Chcont),C,L), make_node(Parent,A,L,Nlist). </code> ==== Wersja 2 ==== <code prolog> add(A, B, [A|B]). add2end(X,[H|T],[H|NewT]):-add2end(X,T,NewT). add2end(X,[],[X]). append([], A, A). append([A|B], C, [A|D]) :- append(B, C, D). belongs(X,[X|_]). belongs(X,[_|Yogon]) :- belongs(X,Yogon). last(E,L) :- append(_,[_,E],L). first(E,L) :- append([],[E|_],L). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% create_root(Name):- assert(element(Name,[],[])), write(element(Name,[],[])). app_child(Parent, Child):- search(Parent,A,L,1), add2end(element(Child,[],[]),L,L1), retract(element(Parent,A,L)), assert(element(Parent,A,L1)), retract(wezel(element(Parent,A,L),Z,P)), assert(wezel(element(Parent,A,L1),Z,P)), retractall(element(_,_,_)). search(N,LA,LN,_):- element(N,LA,LN),!. search(N,LA,LN,P1):- element(X,X1,L), X\=N, member2(element(_,_,_),L,element(X,X1,[]),P1,P2),!, Pn is P2, assert(liczba(Pn)), retract(element(X,X1,L)), assert(element(X,X1,[])), search(N,LA,LN,Pn). member1(D,L,O):- belongs(D,L), assert(D), assert(wezel(D,O)), fail;true. member2(D,L,O,P,P3):- L\=[], P > 0, belongs(D,L), assert(D), assert(wezel(D,O,P)), P2 is P + 1, usun(D,L,Ln), ( Ln ==[] -> P3 is P2,true ; first(E,Ln), member2(E,Ln,O,P2,P3) ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% make_list(List) :- bagof(A,element(A,B,C),A), L=..A, add(element(L,B,C),[],List). zapisz :- tell('wiedza.pl'), listing(element), told. prolog2xml(List,File):- tell(File), open(File,write,S), xml_write(S,List,[]), told, close(S). </code>
pl/miw/miw08_prolog_xml/prolog_api.1211142859.txt.gz
· ostatnio zmienione: 2019/06/27 15:59 (edycja zewnętrzna)
Pokaż stronę
Poprzednie wersje
Menadżer multimediów
Do góry