0

I 'd like to pose a question. I tried to connect php with SWI-Prolog using the exec function and my effort was succeful. I have managed to query prolog via php and I was able to echo Prolog's answer.

What I want to do but can't figure how to accomplish it, is to echo the true/false prolog returns.

Lets assume I have a simple knowledge_base.pl file with these facts and rules:


girl(erin).
boy(john).
likes(erin,reading).
likes(john,reading).
hangs_out_with(erin,X) :- likes(X,reading), boy(X), writeln('Someone s got a new friend!!').

Given the simple knowledge base above one can pose queries and prolog respond.

for example:

?- girl(erin). Prolog based on our knowledge base will respond true.
?- girl(john). Prolog based on our knowledge base will respond false.
?- hangs_out_with(erin,john). Proslog will respond : Someone s got a new friend!! true.

What I need is for PHP to echo the true or false respond. How can I achieve that?

Thanks in advance for you help.

JvdBerg
  • 21,777
  • 8
  • 38
  • 55
Erin
  • 105
  • 1
  • 10
  • I'm confused about your question. Exec is returning, "Someone s got a new friend!! true." and you just want true? – Zeritor Sep 14 '12 at 16:01
  • Hi Zenitor. exec ONLY returns "Someone s got a new friend" when the user queries hangs_out_with(erin,john). i ALSO want the true to be echoed as well. – Erin Sep 14 '12 at 17:22
  • You could try shell_exec, I'm guessing here as I've never used it with prolog, but it should output everything prolog outputs as an array. Could be worth checking if that has any more info. – Zeritor Sep 15 '12 at 10:48
  • @Zeritor I tried shell_exec as you suggested and the array ONLY returns "Someone s got a new friend!!". It doesnt ouput the "true" value I want. I appreciate your effort to help me find an answer. – Erin Sep 15 '12 at 13:12
  • why don't you try to look at the source code of the html page returned? There might be a small chance that prolog does return what you want but the answer contains illegal characters for html thus it is not visible. – dr.doom Sep 16 '12 at 08:43
  • @dr.doom when i use the command prompt to execute a query in prolog it doesn't return the true/false value. If theres a writeln command it gets perfectly executed but NEVER output the true/false prolog gives after each query execution. – Erin Sep 16 '12 at 17:45
  • @Erin, maybe it's just the way SWI Prolog was designed. Can you make Prolog write out "true" or "false" as you need (it's been a while since I used Prolog)? This way the Prolog program would look like it says "true. true." or "false. false." but at least you'd be able to use exec to grab one of them? – Zeritor Sep 17 '12 at 09:50
  • @Zeritor I have already tried that. Although I was happy with the solutions I came up I came to realize that if they are more than one answers and the user wants to input the ";" sign I must come up with a way that Prolog will pause, see if there's an input and then again echo true or false. `girl(X). X=erin ; X=mary` etc. On one hand I do want the true/false value to be displayed but on the other hand I'm wondering if all this "trouble" is even worth it... :( – Erin Sep 17 '12 at 13:52
  • If you want to execute your query automatically and parse its output in PHP, where's that ***user*** coming from???? There's **no user** to press the `;` button. If you allow for that, your script will halt and wait for somebody to press that button. You'd hardly want that as part of your web service, right? If you want all solutions to your predicate, check out *all-solutions predicates* in the SWI doc. – Will Ness Sep 19 '12 at 08:05
  • @Will Ness that's a great idea! I could use a predicate to gather all solutions and then display them to the user. I initially wanted the user to execute queries and if there are more than one answers, i wanted the user to input the ";" as to see next answer as well. :) – Erin Sep 20 '12 at 06:17

0 Answers0