Discussions related to Visual Prolog
billanova
Posts: 5
Joined: 26 Jul 2022 5:50

Move from Prolog to Visual Prolog

Unread post by billanova »

Hi every one.
How i can translate this Prolog source code to Visual Prolog ?
I am working on my Thesis and i must implement a diagnostic tool about mobile phones with Visual Prolog.
Please help....


This is the code...

Code: Select all

go :- guess(Ac),       write('you probably have :  '),       write(Ac),       nl,       undo.                   /*hypotheses to be tested*/   guess(virus)  :- virus, !.        guess(bad_battery)   :- bad_battery, !. guess(low_storage)   :- low_storage, !. guess(synchronization_issue)   :- synchronization_issue, !. guess(screen_that_isnt_working_right) :- screen_that_isnt_working_right , !. guess(deadpixel) :- deadpixel  , !. guess(softbrick) :- softbrick , !. guess(sim)     :- sim , !.   guess(google_play_cache_error) :- google_play_cache_error,!. guess(microsd_false_format) :- microsd_false_format,!. guess(damaged_charging_port) :- damaged_charging_port,!. guess(hacked) :- hacked,!. guess(hardware_issue) :- hardware_issue,!. guess(outdated_bootloader) :- outdated_bootloader,!.   guess(unknown).              /*no diagnosis*/   /* illness identification rules */ virus                                           :- verify(lag),                                                                 verify(freeze),                                                                 verify(crashes),                                                                 verify(consumin_data_without_any_reason),                                                                 verify(get_suspicious_shortcut_files).   bad_battery                                 :- verify(lag);                                                                 verify(do_you_overcharge_your_battery);                                                                 verify(overheating).                         bad_battery                             :- verify(phone_is_dead).   low_storage                                     :- verify(freeze) ;                                                                 verify(cant_download_apps);                                                                 verify(cant_shoot_a_photo);                                                                 verify(cant_save_files);                                                                 verify(phone_freezes_when_certain_apps_are_opened).   synchronization_issue                   :- verify(cant_connect_to_internet_services). synchronization_issue                   :- verify(some_apps_dont_work_or_freeze). synchronization_issue                   :- verify(gps_is_not_accurate).                                                                                                         screen_that_isnt_working_right  :- verify(cracks_spots_and_blotches);                                 verify(buzzing).        deadpixel                                               :- verify(dead_or_stuck_pixels);                                 verify(stuttering_or_flickering).                                                                                                       softbrick                               :- verify(repeating_rebooting).   sim                             :- verify(calls_being_interrupted_or_messages_delayed);                                                                 verify(pin_code_requested_without_rebooting_the_phone);                                                                 verify(sudden_airplane_mode). google_play_cache_error         :- verify(play_store_soesnt_work_properly).                                                                     microsd_false_format                    :- verify(microsd_card_does_not_work).          damaged_charging_port                   :- verify(not_charging). hacked                                                  :- verify(your_device_s_sending_or_receiving_strange_text_messages);                                                                    verify(new_apps_are_installed_on_your_device_and_you_didnt_install_them);                                                                    verify(websites_appear_somewhat_different_than_before);                                                                    verify(your_cell-phone_bill_shows_unexpected_charges);                                                                    verify(your_email_from_the_device_is_getting_blocked_by_spam_filters). hardware_issue                                  :- verify(randomly_powers_on). outdated_bootloader                             :- verify(wi-fi_signal_is_constantly_cutting_out_with_a_weak_signal).     /*question to be asked*/                        ask(Question) :-     write('Is/Does your phone : '),     write(Question),     write('? '),     read(Response),     nl,     ( (Response == yes ; Response == y)       ->        assert(yes(Question)) ;        assert(no(Question)), fail).   :- dynamic yes/1,no/1.   verify(S) :-    (yes(S)     ->     true ;     (no(S)      ->      fail ;      ask(S))).     undo :- retract(yes(_)),fail. undo :- retract(no(_)),fail. undo.
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Re: Move from Prolog to Visual Prolog

Unread post by Harrison Pratt »

Something like the following should get you started. VP is a big leap from classic prolog, but VP has a lot of advantages, especially once your project becomes complex.

The code below is for a console application, so all you need to do is invoke ask/0 from your main application code.

Code: Select all

class predicates     ask : (). clauses     ask() :-         SymptomList = collectPossibleSymptoms(),         S = list::getMember_nd(SymptomList),         stdio::write("\nIs this the problem: ", S, " ? (Enter Y,N or Q) "),         C = string::charUpper(string::frontChar(stdio::readLine())),         if C = 'Y' then             if PP = tryGetProblem(S) and PP <> [] then                 stdio::write("\n\tPossible problems include: ", PP)             else                 stdio::write("\n\tNo match for ", S)             end if         elseif C = 'N' then             stdio::write("\n\tTrying another symptom ...")         end if,         C = 'Q',         !.     ask().   class predicates     collectPossibleSymptoms : () -> string* SymptomList. clauses     collectPossibleSymptoms() =         [ S ||             probSymptoms(_, Symptoms),             S in Symptoms         ].   class predicates     tryGetProblem : (string Symptom) -> probListDOM determ. % FAIL if no match clauses     tryGetProblem(Symptom) = PP :-         PP =             [ P ||                 probSymptoms(P, SymptomList),                 list::isMember(Symptom, SymptomList)             ],         PP <> [].   domains     probDOM =         bad_battery; damaged_charging_port; deadpixel; google_play_cache_error; hacked; hardware_issue; low_storage; microsd_false_format;         outdated_bootloader; screen_that_isnt_working_right; sim; softbrick; synchronization_issue; virus.     probListDOM = probDOM*.   class facts     probSymptoms : (probDOM Problem, string* Symptoms).   clauses     probSymptoms(virus, ["lag", "freeze", "crashes", "consumin_data_without_any_reason", "get_suspicious_shortcut_files"]).     probSymptoms(bad_battery, ["do_you_overcharge_your_battery", "overheating", "phone_is_dead"]).     probSymptoms(low_storage, ["cant_download_apps", "cant_shoot_a_photo", "cant_save_files", "phone_freezes_when_certain_apps_are_opened"]).     probSymptoms(synchronization_issue, ["cant_connect_to_internet_services", "some_apps_dont_work_or_freeze", "gps_is_not_accurate"]).     probSymptoms(screen_that_isnt_working_right, ["cracks_spots_and_blotches", "buzzing"]).     probSymptoms(softbrick, ["stuttering_or_flickering", "repeating_rebooting"]).     probSymptoms(deadpixel, ["dead_or_stuck_pixels"]).     probSymptoms(sim, ["calls_being_interrupted_or_messages_delayed", "pin_code_requested_without_rebooting_the_phone", "sudden_airplane_mode"]).     probSymptoms(google_play_cache_error, ["play_store_soesnt_work_properly"]).     probSymptoms(microsd_false_format, ["microsd_card_does_not_work"]).     probSymptoms(damaged_charging_port, ["not_charging"]).     probSymptoms(hacked,             [                 "your_device_s_sending_or_receiving_strange_text_messages" "new_apps_are_installed_on_your_device_and_you_didnt_install_them",                 "websites_appear_somewhat_different_than_before",                 "your_cell-phone_bill_shows_unexpected_charges",                 "your_email_from_the_device_is_getting_blocked_by_spam_filters"             ]).     probSymptoms(hardware_issue, ["randomly_powers_on"]).     probSymptoms(outdated_bootloader, ["wi-fi_signal_is_constantly_cutting_out_with_a_weak_signal"]).
billanova
Posts: 5
Joined: 26 Jul 2022 5:50

Re: Move from Prolog to Visual Prolog

Unread post by billanova »

Thank's a lot dude. Appreciate that
Post Reply