I have a Prolog program that I connected with php.
I call the Prolog file from php as follows:
$cmd = "swipl -f /path/to/my_file/prolog.pl -g test,halt -t 'halt(1)'"; exec( $cmd, $output); print_r($output);
With the exec() function i can see an array with the output obtained, but the problem is that in the Prolog code i have ‘read()’ function that allows me to insert a value. The problem is that i don’t know how to handle multiple Prolog read functions from php.
Does anyone know a way to solve my problem?
The code of my prolog program is as follows:
start:- write('-----------------------------------------------------------------------'), nl, write(' Welcome'), nl, write('-----------------------------------------------------------------------'), nl, choices.
choices:- read_choices, read(S), ((S == 1; S == one) -> Reply = choice1; ((S == 2; S == two) -> Reply = choice2; ((S == 3; S == three) -> Reply = choice3; ((S == 4; S == four) -> Reply = exit_choice; (Reply = unknown) )))), nl, (Reply == exit_choice -> exit_from_program; (Reply == unknown -> (write('Reply not recognized'), start); (selection(Reply), end_guide(Reply), execute_again('Do you need help?')) )), nl.
read_choices:- write('Make a choice:'), nl, write('1. Choice 1'), nl, write('2. Choice 2'), nl, write('3. Choice 3'), nl, write('4. Exit'), nl, write('Insert choice: ').
execute_again(Text) :- nl, write(Text), nl, read(S), ((S==s ; S == si) -> start; ((S == n ; S == no) -> exit_from_program; (write('Reply not recognized'), execute_again(Text)) )).
end_guide(R):- nl,nl,nl, write(R), write(' ended'), nl.
exit_from_program:- write('Exit, Bye'),nl.
exit_from_program:- write('Closed by the user'),nl.
selection(choice1):- write('choice1 selected').
selection(choice2):- write('choice2 selected').
selection(choice3):- write('choice3 selected').
I would like to find a way to use more prolog read functions in the same program, without querying the knowledge base each time. I’m using swi-prolog