Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- consult('opcje.pl'). % Use ensure_loaded if available.
- %
- % Main control procedures
- %
- start :-
- write('Program pomoze Ci dobrac odpowiedniego producenta telefonow'),nl,
- write('Odpowiadaj na pytania w formie zgodnej z podpowiedziami'),nl,
- clear_stored_answers,
- try_all_possibilities.
- try_all_possibilities :- % Backtrack through all possibilities...
- mozliwy_telefon(D),
- explain(D),
- fail.
- try_all_possibilities. % ...then succeed with no further action.
- %
- % Diagnostic knowledge base
- % (conditions under which to give each diagnosis)
- %
- mozliwy_telefon(apple) :-
- user_says(bateria,no),
- user_says(kolor,bialy),
- user_says(funkcjonalnosci,1).
- mozliwy_telefon(nokia) :-
- user_says(bateria,yes),
- user_says(kolor,czarny),
- user_says(funkcjonalnosci,2).
- mozliwy_telefon(huawei) :-
- user_says(bateria,no),
- user_says(kolor,czarny),
- user_says(funkcjonalnosci,3).
- mozliwy_telefon(samsung) :-
- user_says(bateria,yes),
- user_says(kolor,zloty),
- user_says(funkcjonalnosci,4).
- %
- % Case knowledge base
- % (information supplied by the user during the consultation)
- %
- :- dynamic(stored_answer/2).
- % (Clauses get added as user answers questions.)
- %
- % Procedure to get rid of the stored answers
- % without abolishing the dynamic declaration
- %
- clear_stored_answers :- retract(stored_answer(_,_)),fail.
- clear_stored_answers.
- %
- % Procedure to retrieve the user's answer to each question when needed,
- % or ask the question if it has not already been asked
- %
- user_says(Q,A) :- stored_answer(Q,A).
- user_says(Q,A) :- \+ stored_answer(Q,_),
- nl,nl,
- ask_question(Q),
- get_yes_or_no(Response),
- asserta(stored_answer(Q,Response)),
- Response = A.
- %
- % Texts of the questions
- %
- ask_question(budzet) :-
- write('Jaki jest twoj budzet na zakup urzadzenia?'),nl.
- ask_question(funkcjonalnosci) :-
- write('Jaka funkcjonalnosc jest dla Ciebie najwazniejsza?'),nl,
- write('1 - aparat'),nl,
- write('2 - pamiec'),nl,
- write('3 - rozmiar'),nl,
- write('4 - personalizacja interfejsu'),nl.
- ask_question(kolor) :-
- write('Jaki jest Twoj wymarzony kolor telefonu?'),nl,
- write('C - czarny'),nl,
- write('Z - zloty'),nl,
- write('R - rozowy'),nl,
- write('B - bialy'),nl.
- ask_question(bateria) :-
- write('Czy czas pracy baterii jest dla Ciebie istotny?'),nl,
- write('T - tak, N - nie'),nl.
- ask_question(raty) :-
- write('Czy zamierzasz kupić telefon na raty?'),nl,
- write('T - tak, N - nie'),nl.
- ask_question(aplikacje) :-
- write('Czy korzystasz z wielu różnych aplikacji?'),nl,
- write('T - tak, N - nie'),nl.
- %
- % Explanations for the various diagnoses
- %
- explain(apple) :-
- nl,
- write('Potrzebujesz Apple!'),nl.
- explain(nokia) :-
- nl,
- write('Potrzebujesz Nokii!'),nl.
- explain(huawei) :-
- nl,
- write('Potrzebujesz Huawei!'),nl.
- explain(samsung) :-
- nl,
- write('Potrzebujesz Samsunga!'),nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement