Advertisement
Guest User

Untitled

a guest
Mar 31st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 3.04 KB | None | 0 0
  1. :- consult('opcje.pl').  % Use ensure_loaded if available.
  2.  
  3. %
  4. % Main control procedures
  5. %
  6.  
  7. start :-
  8.    write('Program pomoze Ci dobrac odpowiedniego producenta telefonow'),nl,
  9.    write('Odpowiadaj na pytania w formie zgodnej z podpowiedziami'),nl,
  10.    clear_stored_answers,
  11.    try_all_possibilities.
  12.  
  13. try_all_possibilities :-     % Backtrack through all possibilities...
  14.    mozliwy_telefon(D),
  15.    explain(D),
  16.    fail.
  17.  
  18. try_all_possibilities.       % ...then succeed with no further action.
  19.  
  20.  
  21. %
  22. % Diagnostic knowledge base
  23. %   (conditions under which to give each diagnosis)
  24. %
  25.  
  26. mozliwy_telefon(apple) :-
  27.    user_says(bateria,no),
  28.    user_says(kolor,bialy),
  29.    user_says(funkcjonalnosci,1).
  30.  
  31. mozliwy_telefon(nokia) :-
  32.    user_says(bateria,yes),
  33.    user_says(kolor,czarny),
  34.    user_says(funkcjonalnosci,2).
  35.  
  36. mozliwy_telefon(huawei) :-
  37.    user_says(bateria,no),
  38.    user_says(kolor,czarny),
  39.    user_says(funkcjonalnosci,3).
  40.  
  41. mozliwy_telefon(samsung) :-
  42.    user_says(bateria,yes),
  43.    user_says(kolor,zloty),
  44.    user_says(funkcjonalnosci,4).
  45.  
  46.  
  47. %
  48. % Case knowledge base
  49. %   (information supplied by the user during the consultation)
  50. %
  51.  
  52. :- dynamic(stored_answer/2).
  53.  
  54.    % (Clauses get added as user answers questions.)
  55.  
  56.  
  57. %
  58. % Procedure to get rid of the stored answers
  59. % without abolishing the dynamic declaration
  60. %
  61.  
  62. clear_stored_answers :- retract(stored_answer(_,_)),fail.
  63. clear_stored_answers.
  64.  
  65.  
  66. %
  67. % Procedure to retrieve the user's answer to each question when needed,
  68. % or ask the question if it has not already been asked
  69. %
  70.  
  71. user_says(Q,A) :- stored_answer(Q,A).
  72.  
  73. user_says(Q,A) :- \+ stored_answer(Q,_),
  74.                   nl,nl,
  75.                   ask_question(Q),
  76.                   get_yes_or_no(Response),
  77.                   asserta(stored_answer(Q,Response)),
  78.                   Response = A.
  79.  
  80.  
  81. %
  82. % Texts of the questions
  83. %
  84.  
  85. ask_question(budzet) :-
  86.    write('Jaki jest twoj budzet na zakup urzadzenia?'),nl.
  87.  
  88. ask_question(funkcjonalnosci) :-
  89.    write('Jaka funkcjonalnosc jest dla Ciebie najwazniejsza?'),nl,
  90.    write('1 - aparat'),nl,
  91.    write('2 - pamiec'),nl,
  92.    write('3 - rozmiar'),nl,
  93.    write('4 - personalizacja interfejsu'),nl.
  94.  
  95. ask_question(kolor) :-
  96.    write('Jaki jest Twoj wymarzony kolor telefonu?'),nl,
  97.    write('C - czarny'),nl,
  98.    write('Z - zloty'),nl,
  99.    write('R - rozowy'),nl,
  100.    write('B - bialy'),nl.
  101.  
  102. ask_question(bateria) :-
  103.    write('Czy czas pracy baterii jest dla Ciebie istotny?'),nl,
  104.    write('T - tak, N - nie'),nl.
  105.  
  106. ask_question(raty) :-
  107.    write('Czy zamierzasz kupić telefon na raty?'),nl,
  108.    write('T - tak, N - nie'),nl.
  109.  
  110. ask_question(aplikacje) :-
  111.    write('Czy korzystasz z wielu różnych aplikacji?'),nl,
  112.    write('T - tak, N - nie'),nl.
  113.  
  114.  
  115. %
  116. %  Explanations for the various diagnoses
  117. %
  118.  
  119. explain(apple) :-
  120.    nl,
  121.    write('Potrzebujesz Apple!'),nl.
  122.  
  123. explain(nokia) :-
  124.    nl,
  125.    write('Potrzebujesz Nokii!'),nl.
  126.  
  127. explain(huawei) :-
  128.    nl,
  129.    write('Potrzebujesz Huawei!'),nl.
  130.  
  131. explain(samsung) :-
  132.    nl,
  133.    write('Potrzebujesz Samsunga!'),nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement