在 XPCE 中通过 GUI 更改数据库
Change database via GUI in XPCE
1) 如何在 XPCE 中使用按钮和文本字段更改我的数据库(事实)?比如我有一组事实:
country('Austria',84,8200,3900).
country('Belgium',30,10300,36500).
country('Bulgaria',1111,7323,11800).
country('United_Kingdom',245,60776,35300).
% and so on
我已经创建了一些带有 GUI 的组,用于更改、编辑或删除现有事实:
new(AddNewName, text_item('Enter new country here:')),
new(AddNewPop, text_item('Enter new country population:')),
new(AddNewArea, text_item('Enter new country area:')),
new(AddNewGDP, text_item('Enter new country GDP:')),
send(H10, append, AddNewName),
send(H10, append, AddNewPop),
send(H10, append, AddNewArea),
send(H10, append, AddNewGDP),
send(H10, append, button(add)), %message(@prolog, memberCountry, Etiq, Result))), what should be here?
send(H10, alignment, left),
new(EditNewName, text_item('Enter country here:')),
new(EditNewPop, text_item('Enter new country population:')),
new(EditNewArea, text_item('Enter new country area:')),
new(EditNewGDP, text_item('Enter new country GDP:')),
send(H11, append, EditNewName),
send(H11, append, EditNewPop),
send(H11, append, EditNewArea),
send(H11, append, EditNewGDP),
send(H11, append, button(edit)), %message(@prolog, memberCountry, Etiq, Result))), what should be here?
send(H11, alignment, left),
new(DeleteNewName, text_item('Enter country name here:')),
send(H12, append, DeleteName),
send(H12, append, button(delete)), %message(@prolog, memberCountry, Etiq, Result))), what should be here?
send(H12, alignment, left),
那么,我应该如何构建我的按钮消息?
2) 我的第二个问题是为什么我看不到深度优先搜索的结果?这是我的 GUI 代码和功能:
new(Path1, text('6) Path form-to (serach in deep)')),
new(From1, text_item('Enter country FROM here:')),
new(To1, text_item('Enter country TO here:')),
send(H2, append, Path1),
send(H2, append, From1),
send(H2, append, To1),
new(Path1Res, list_browser),
send(H2, append, button(path, message(@prolog, dfs, From1?selection, To1?selection, [], [], Path1Res))),
send(H2, append, Path1Res),
send(Path1Res, alignment, center),
%...
dfs(From, To, _, [(From, To)]):-
border(From, To).
dfs(From, To, VisitedNodes, [(From, X)|TailPath], Path1):-
border(From, X),
not(member(X, VisitedNodes)),
dfs(X, To, [From|VisitedNodes], TailPath),
send(Path1, append, TailPath).
提前致谢!
对于第一个问题,我认为你应该从文件 country.pl 中读取数据库,将谓词 country/4 声明为 dynamic ,并在程序结束时保存整个数据库。
send(H11, append, button(edit)), %message(@prolog, addCountry, AddNewName?selection, AddNewPop?selection, AddNewArea?selection, AddNewGDP?selection))), what should be here?
可能是:
addCountry(Name, Pop, Area, Gdb) :-
assert(country(Name, Pop, Area, Gdb)).
对于
editCountry(Name, Pop, Area, Gdb) :-
retract(country(Name, _, _, _)),
assert(country(Name, Pop, Area, Gdb)).
这是一个可以做什么的例子(问题 2)
showForm :-
%new(W, window('Test', size(800, 800))),
new(D, dialog('Main window', size(800, 800))),
new(H1, dialog_group(' ')),
new(H2, dialog_group(' ')),
new(H3, dialog_group(' ')),
send(D, append, H1),
send(D, append, H2, right),
send(D, append, H3),
/* 6) serach if country is in Europe */
new(Etiq, text_item('1) Enter country here:')),
send(H1, append, Etiq),
new(Result, label),
send(H1, append, Result),
send(H1, append, button(search)),
new(Lb, list_browser),
/* 7) Path form-to (serach in deep) */
new(Path1, text('6) Path form-to (search in deep)')),
new(From, text_item('Enter country FROM here:')),
new(To, text_item('Enter country TO here:')),
send(H2, append, Path1),
send(H2, append, From),
send(H2, append, To),
send(H2, append,
button(path,
message(@prolog, search, From?selection, To?selection, Lb))),
send(H3, append, Lb),
send(D, open),
get(H2, height, HS2),
send(H1, height, HS2-8),
get(D, width, WD),
send(H3, width, WD-30).
search(From, To, Lb) :-
send(Lb, clear),
send(Lb, append, From),
send(Lb, append, To).
EDIT1
要保存新的 bdd,您可以这样做:
% Bdd holds the complete path to the bdd (for example c:\users\me\prolog\bdd\country.pl)
save(Bdd) :-
tell(Bdd),
listing(country),
told.
EDIT2
我假设 Way 是这种 [paris, calais, dover, london] 的列表,你可以这样做
search(From, To, Lb) :-
%% get the path from Paris to London
%% Way= [paris, calais, dover, london]
send(Lb, clear),
forall(member(X, Way), send(Lb, append, X)).
1) 如何在 XPCE 中使用按钮和文本字段更改我的数据库(事实)?比如我有一组事实:
country('Austria',84,8200,3900).
country('Belgium',30,10300,36500).
country('Bulgaria',1111,7323,11800).
country('United_Kingdom',245,60776,35300).
% and so on
我已经创建了一些带有 GUI 的组,用于更改、编辑或删除现有事实:
new(AddNewName, text_item('Enter new country here:')),
new(AddNewPop, text_item('Enter new country population:')),
new(AddNewArea, text_item('Enter new country area:')),
new(AddNewGDP, text_item('Enter new country GDP:')),
send(H10, append, AddNewName),
send(H10, append, AddNewPop),
send(H10, append, AddNewArea),
send(H10, append, AddNewGDP),
send(H10, append, button(add)), %message(@prolog, memberCountry, Etiq, Result))), what should be here?
send(H10, alignment, left),
new(EditNewName, text_item('Enter country here:')),
new(EditNewPop, text_item('Enter new country population:')),
new(EditNewArea, text_item('Enter new country area:')),
new(EditNewGDP, text_item('Enter new country GDP:')),
send(H11, append, EditNewName),
send(H11, append, EditNewPop),
send(H11, append, EditNewArea),
send(H11, append, EditNewGDP),
send(H11, append, button(edit)), %message(@prolog, memberCountry, Etiq, Result))), what should be here?
send(H11, alignment, left),
new(DeleteNewName, text_item('Enter country name here:')),
send(H12, append, DeleteName),
send(H12, append, button(delete)), %message(@prolog, memberCountry, Etiq, Result))), what should be here?
send(H12, alignment, left),
那么,我应该如何构建我的按钮消息?
2) 我的第二个问题是为什么我看不到深度优先搜索的结果?这是我的 GUI 代码和功能:
new(Path1, text('6) Path form-to (serach in deep)')),
new(From1, text_item('Enter country FROM here:')),
new(To1, text_item('Enter country TO here:')),
send(H2, append, Path1),
send(H2, append, From1),
send(H2, append, To1),
new(Path1Res, list_browser),
send(H2, append, button(path, message(@prolog, dfs, From1?selection, To1?selection, [], [], Path1Res))),
send(H2, append, Path1Res),
send(Path1Res, alignment, center),
%...
dfs(From, To, _, [(From, To)]):-
border(From, To).
dfs(From, To, VisitedNodes, [(From, X)|TailPath], Path1):-
border(From, X),
not(member(X, VisitedNodes)),
dfs(X, To, [From|VisitedNodes], TailPath),
send(Path1, append, TailPath).
提前致谢!
对于第一个问题,我认为你应该从文件 country.pl 中读取数据库,将谓词 country/4 声明为 dynamic ,并在程序结束时保存整个数据库。
send(H11, append, button(edit)), %message(@prolog, addCountry, AddNewName?selection, AddNewPop?selection, AddNewArea?selection, AddNewGDP?selection))), what should be here?
可能是:
addCountry(Name, Pop, Area, Gdb) :-
assert(country(Name, Pop, Area, Gdb)).
对于
editCountry(Name, Pop, Area, Gdb) :-
retract(country(Name, _, _, _)),
assert(country(Name, Pop, Area, Gdb)).
这是一个可以做什么的例子(问题 2)
showForm :-
%new(W, window('Test', size(800, 800))),
new(D, dialog('Main window', size(800, 800))),
new(H1, dialog_group(' ')),
new(H2, dialog_group(' ')),
new(H3, dialog_group(' ')),
send(D, append, H1),
send(D, append, H2, right),
send(D, append, H3),
/* 6) serach if country is in Europe */
new(Etiq, text_item('1) Enter country here:')),
send(H1, append, Etiq),
new(Result, label),
send(H1, append, Result),
send(H1, append, button(search)),
new(Lb, list_browser),
/* 7) Path form-to (serach in deep) */
new(Path1, text('6) Path form-to (search in deep)')),
new(From, text_item('Enter country FROM here:')),
new(To, text_item('Enter country TO here:')),
send(H2, append, Path1),
send(H2, append, From),
send(H2, append, To),
send(H2, append,
button(path,
message(@prolog, search, From?selection, To?selection, Lb))),
send(H3, append, Lb),
send(D, open),
get(H2, height, HS2),
send(H1, height, HS2-8),
get(D, width, WD),
send(H3, width, WD-30).
search(From, To, Lb) :-
send(Lb, clear),
send(Lb, append, From),
send(Lb, append, To).
EDIT1 要保存新的 bdd,您可以这样做:
% Bdd holds the complete path to the bdd (for example c:\users\me\prolog\bdd\country.pl)
save(Bdd) :-
tell(Bdd),
listing(country),
told.
EDIT2
我假设 Way 是这种 [paris, calais, dover, london] 的列表,你可以这样做
search(From, To, Lb) :-
%% get the path from Paris to London
%% Way= [paris, calais, dover, london]
send(Lb, clear),
forall(member(X, Way), send(Lb, append, X)).