1

我正在 swi-prolog 中构建我的第一个项目。它是一个专家系统,可以根据用户的输入猜测用户身份。这段代码会生成一个对话框,允许用户输入信息,然后验证信息并允许用户访问。有没有办法改进代码?

 % user facts to enable the user to log in
user(dac,dac11).
user(dac101,daa).

% login Gui. checks the database to log in
loginGui :- new(Dialog,dialog('Login')),
          send_list(Dialog, append,
                  [
                    new( UserName, text_item(username)),
                    new(Password, text_item(password)),
                    button(enter, and(message(@prolog,
                               checkUser,
                              UserName?selection,
                               Password?selection),
                                message(Dialog, destroy)
                               ))]),
                    send(Dialog, default_button, enter),
                    send(Dialog, open).

% verfies user logging
checkUser(UserName,Password):-user(UserName,Password),
                               UserName \== Password,
                               new(Dialog,dialog('Login')),
                  send_list(Dialog, append,
                  [
                    new(  label(welcome_to_criminal_system,welcome_to_criminal_system)),
                    button(enter, and(message(@prolog,
                               ask_user),
                                message(Dialog, destroy)
                               ))]),
                    send(Dialog, default_button, enter),
                    send(Dialog, open).


% main menu loggin , user can search or select different option
ask_user :-
        new(Dialog, dialog('Main Menu')),
        all_offence(T),all_eye_color(E),all_skin_colour(Skin),
         all_hair_colour(HC) ,all_hair_style(HS),
        send_list(Dialog, append,
                  [ new(N1, text_item(firstName)),
                    new(N2, text_item(lastName)),
                    new(N3, new(S, menu(gender))),
                    new(N4, new(Offense, menu(offense,cycle))),
                    new(N5 , new(Eye,menu(eye_color,cycle))),
                    new(N6,  new(Hair,menu(hair_color,cycle))),
                    new(N8,  new(HairStyle,menu(hair_style,cycle))),
                    new(N9, new(Skincolor,menu(skin_color,cycle))),
                    button(all_criminals,and(message(@prolog,
                                                      all_criminals),
                                                             message(Dialog, destroy))),
                    button(add_criminals,and(message(@prolog,add_criminal_gui), message(Dialog, destroy))),
                    button(exit, message(Dialog, destroy)),
                    button(enter, and(message(@prolog,
                                              pick_search_algorithm,
                                              N1?selection,
                                              N2?selection,
                                              N3?selection,
                                              N4?selection,
                                              N5?selection,
                                              N6?selection,
                                              N8?selection,
                                              N9?selection),
                                      message(Dialog, destroy)))
                  ]),
        send_list(Offense, append,T),
        send_list(Eye, append,E),
        send_list(Hair, append,HC),
        send_list(HairStyle, append,HS),
        send_list(Skincolor, append,Skin),
        send_list(S, append,  [male, female,none]),
        send(Dialog, default_button, enter),
        send(Dialog, open).
4

0 回答 0