我是 Prolog 的新手。我曾尝试开发一个主要选择简单的专家系统,但我被卡住了
I am new to Prolog. I have tried to develop a major selection simple expert system, but I am stuck
我希望能够让用户选择几个选项,而不是全部让假设显示出来。示例:用户对计算机、编程和技术感兴趣,但对应用程序不感兴趣,我仍然希望系统显示用户可以主修信息技术。
此代码能够 运行 在 swi-prolog 中。
go:-
hypothesis(Major),
write('I believe that the student can major in '),
write(Major), nl,
write('GOOD LUCK '),
undo.
/*Hypothesis that should be tested*/
hypothesis(informationTechnology) :-
informationTechnology, !.
hypothesis(informationTechnology_or_medicine) :-
informationTechnology_or_medicine, !.
hypothesis(medicine) :- medicine, !.
hypothesis(hospitality) :- hospitality, !.
hypothesis(business) :- business, !.
hypothesis(law) :- law, !.
hypothesis(unknown). /* no diagnosis*/
/*Hypothesis Identification Rules*/
informationTechnology :-
verify(computers),
verify(apps),
verify(technology),
verify(programming),
write('Courses to choose from:'), nl,
write('1: Computer Science'), nl,
write('2: Information Systems'), nl,
write('3: Security Technology'), nl,
write('Please wear warm cloths Because'), nl.
informationTechnology_or_medicine :-
verify(computers),
verify(science),
verify(communication),
verify(problem_solving),
verify(research),
verify(technology),
write('Courses to choose from:'), nl,
write('1: Computer Science'), nl,
write('2: Information Systems'), nl,
write('3: Security Technology'), nl,
write('These are the available courses.'), nl.
medicine :-
verify(science),
verify(health),
verify(research),
verify(helping_people),
write('Courses to choose from:'), nl,
write('1: Nursing'), nl,
write('2: Medicine'), nl,
write('3: Physiotherapy'), nl,
write('These are the available courses.'), nl.
hospitality :-
verify(helping_people),
verify(management),
verify(communication),
verify(planning),
write('Courses to choose from:'), nl,
write('1: Hotel Management'), nl,
write('2: Culinary arts'), nl,
write('3: Human Resources Management'), nl,
write('4: Public Relations'), nl,
write('These are the available courses.'), nl.
business :-
verify(money_making),
verify(apps),
verify(economy),
verify(communication),
write('Courses to choose from:'), nl,
write('1: Business Administration'), nl,
write('2: Accounting and Finance'), nl,
write('3: Marketing and E-commerce'), nl,
write('4: International Business'), nl,
write('These are the available courses.'), nl.
law :-
verify(law),
verify(justice),
verify(government),
verify(politics),
verify(reading),
write('Courses to choose from:'), nl,
write('1: Criminology'), nl,
write('2: Political Science'), nl,
write('3: Psychology'), nl,
write('4: Forensics'), nl,
write('These are the available courses.'), nl.
/* how to ask questions */
ask(Question) :-
write('Do you have interest in:'),
write(Question),
write('? '),
read(Response), nl,
( (Response == yes ; Response == y)
->
assert(yes(Question)) ;
assert(no(Question)), fail).
:- dynamic yes/1,no/1.
/*How to verify something */
verify(S) :-
(yes(S)
->
true ;
(no(S)
->
fail ;
ask(S))).
/* undo all yes/no assertions*/
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.
再添加一个这样的假设:
hypothesis(informationTechnology_without_apps) :-
informationTechnology_without_apps, !.
和一个新的假设识别规则:
informationTechnology_without_apps :-
verify(computers),
verify(technology),
verify(programming),
write('Courses to choose from:'), nl,
write('1: Computer Science'), nl,
write('2: Information Systems'), nl,
write('3: Security Technology'), nl,
write('Please wear warm cloths Because'), nl.
我希望能够让用户选择几个选项,而不是全部让假设显示出来。示例:用户对计算机、编程和技术感兴趣,但对应用程序不感兴趣,我仍然希望系统显示用户可以主修信息技术。
此代码能够 运行 在 swi-prolog 中。
go:-
hypothesis(Major),
write('I believe that the student can major in '),
write(Major), nl,
write('GOOD LUCK '),
undo.
/*Hypothesis that should be tested*/
hypothesis(informationTechnology) :-
informationTechnology, !.
hypothesis(informationTechnology_or_medicine) :-
informationTechnology_or_medicine, !.
hypothesis(medicine) :- medicine, !.
hypothesis(hospitality) :- hospitality, !.
hypothesis(business) :- business, !.
hypothesis(law) :- law, !.
hypothesis(unknown). /* no diagnosis*/
/*Hypothesis Identification Rules*/
informationTechnology :-
verify(computers),
verify(apps),
verify(technology),
verify(programming),
write('Courses to choose from:'), nl,
write('1: Computer Science'), nl,
write('2: Information Systems'), nl,
write('3: Security Technology'), nl,
write('Please wear warm cloths Because'), nl.
informationTechnology_or_medicine :-
verify(computers),
verify(science),
verify(communication),
verify(problem_solving),
verify(research),
verify(technology),
write('Courses to choose from:'), nl,
write('1: Computer Science'), nl,
write('2: Information Systems'), nl,
write('3: Security Technology'), nl,
write('These are the available courses.'), nl.
medicine :-
verify(science),
verify(health),
verify(research),
verify(helping_people),
write('Courses to choose from:'), nl,
write('1: Nursing'), nl,
write('2: Medicine'), nl,
write('3: Physiotherapy'), nl,
write('These are the available courses.'), nl.
hospitality :-
verify(helping_people),
verify(management),
verify(communication),
verify(planning),
write('Courses to choose from:'), nl,
write('1: Hotel Management'), nl,
write('2: Culinary arts'), nl,
write('3: Human Resources Management'), nl,
write('4: Public Relations'), nl,
write('These are the available courses.'), nl.
business :-
verify(money_making),
verify(apps),
verify(economy),
verify(communication),
write('Courses to choose from:'), nl,
write('1: Business Administration'), nl,
write('2: Accounting and Finance'), nl,
write('3: Marketing and E-commerce'), nl,
write('4: International Business'), nl,
write('These are the available courses.'), nl.
law :-
verify(law),
verify(justice),
verify(government),
verify(politics),
verify(reading),
write('Courses to choose from:'), nl,
write('1: Criminology'), nl,
write('2: Political Science'), nl,
write('3: Psychology'), nl,
write('4: Forensics'), nl,
write('These are the available courses.'), nl.
/* how to ask questions */
ask(Question) :-
write('Do you have interest in:'),
write(Question),
write('? '),
read(Response), nl,
( (Response == yes ; Response == y)
->
assert(yes(Question)) ;
assert(no(Question)), fail).
:- dynamic yes/1,no/1.
/*How to verify something */
verify(S) :-
(yes(S)
->
true ;
(no(S)
->
fail ;
ask(S))).
/* undo all yes/no assertions*/
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.
再添加一个这样的假设:
hypothesis(informationTechnology_without_apps) :-
informationTechnology_without_apps, !.
和一个新的假设识别规则:
informationTechnology_without_apps :-
verify(computers),
verify(technology),
verify(programming),
write('Courses to choose from:'), nl,
write('1: Computer Science'), nl,
write('2: Information Systems'), nl,
write('3: Security Technology'), nl,
write('Please wear warm cloths Because'), nl.