У меня есть основной файл .pl, который получает данные из 2 других файлов, prologRules.pl и englishRules.pl.
Это основной файл:
%%%%%%%%%%%solve_WithOutCertainty_WithHistory%%%%%%%%%%%%%%%
solve(a):-
abolish(known, 3), abolish(known, 4), abolish(certainty, 1), abolish(history, 1),abolish(history, 2), abolish(history, 3), asserta(certainty(no)), asserta(history(no)), prove([top_goal(X)]),
write('The answer is '), write(X), nl.
solve(a):-
write('No answer found for solve_WithOutCertainty_WithHistory.'), nl.
prove([]).
prove([true]):- !.
prove([Goal|Rest]):-
prov(Goal),
prove(Rest).
prov(true):-!.
prov(menuask(X, Y, Z)):-menuaskB(X, Y, Z), !.
prov(ask(X, Y)):-askB(X,Y), !.
prov(Goal):-
clause(Goal, BodyOfClause),
toList(BodyOfClause, List),
prove(List).
askB(Attribute, Value) :-
clause(known(_,_,_),_),
known(_, Attribute, Value),
!.
askB(Attribute, Value) :-
clause(known(_,_,_),_),
known(_, Attribute, Value),
!, fail.
askB(Attribute, _) :-
not(multivalued(Attribute)),
clause(known(_,_,_),_),
known(yes, Attribute, _),
!, fail.
askB(A, V) :-
write(A :V),
write('? (yes or no) '),
get_user(Y),
asserta(known(Y, A, V)),
assert(history(Y, A is V)),
Y = yes.
get_user(X):-
repeat,
write('> '),
read(X),
process_ansB(X), !.
process_ansB(why) :-
write('no history is available'), !, fail.
process_ansB(X).
menuaskB(Attribute, Value, _) :-
clause(known(_,_,_),_),
known(yes, Attribute, Value),
!.
menuaskB(Attribute, _, _) :-
clause(known(_,_,_),_),
known(yes, Attribute, _),
!, fail.
menuaskB(Attribute, AskValue, Menu) :-
nl, write('What is the value for '),
write(Attribute), write('?'), nl,
display_menu(Menu),
write('Enter the number of choice > '),
get_user(Num), nl,
pick_menu(Num, AnswerValue, Menu),
asserta(known(yes, Attribute, AnswerValue)),
assert(history(yes, Attribute is AnswerValue)),
AskValue = AnswerValue.
why(Goal) :- write('because'),nl, known(_,X,Y), write(X),write(':'),write('('),write(Y),write(')'), nl, fail; true.
Мои примеры прогонов:
> |: solve_WithOutCertainty_WithHistory.
nostrils:external_tubular? (yes or no) > |: yes.
live:at_sea? (yes or no) > |: yes.
bill:hooked? (yes or no) > |: no.
What is the value for size?
1 :large
2 :plump
3 :medium
4 :small
Enter the number of choice > > |: 2.
feet:webbed? (yes or no) > |: yes.
bill:flat? (yes or no) > |: yes.
neck:long? (yes or no) > |: no.
color:white? (yes or no) > |: no.
What is the value for flight?
1 :ponderous
2 :powerful
3 :agile
4 :flap_glide
5 :other
Enter the number of choice > > |: 3.
feed:on_water_surface? (yes or no) > |: yes.
voice:quack? (yes or no) > |: yes.
head:green? (yes or no) > |: yes.
The answer is mallard
> |: why(mallard).
because
head:(green)
voice:(quack)
feed:(on_water_surface)
flight:(agile)
color:(white)
neck:(long)
bill:(flat)
feet:(webbed)
size:(plump)
bill:(hooked)
live:(at_sea)
nostrils:(external_tubular)
> |:
Однако мне нужно отследить и распечатать историю моих известных фактов, а не просто печатать выбранные опции:
The answer is mallard
> |: why(mallard).
because
bird(mallard):family(duck)voice(quack)head(green)family(duck):
order(waterfowl)feed(on_water_surface)flight(agile)
order(waterfowl): feet(webbed),bill(flat)
Мне нужно изменить причину (цель), но я не уверен, что делать дальше. Мне нужна помощь в этом.