0

I have a problem. I cannot figure out this problem for weeks. For example:

parent(john,paul). 
parent(paul,tom).  
parent(tom,mary).  
ancestor(X,Y) :- parent(X,Y). 
ancestor(X,Y) :- parent(X,Z),
                 ancestor(Z,Y).

query is :

swipl -s /home/alikoyuncu/pl/ples.pl -g "ancestor(X,'tom')" -t halt.

output :

% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,856 bytes
% /home/alikoyuncu/pl/ples.pl compiled 0.01 sec, 119,096 bytes

alikoyuncu@alikoyuncu-EasyNote-TM98:/var/www/nlp$

What should I do to get variable X ?


and i am calling from php. My php code :

<?php

try
{

    $cmd ="swipl --quiet -s /home/alikoyuncu/pl/ples.pl -g \"forall(f(X,gel),writeln(X))\" -t halt.";
    $cmd2="/var/www/nlp/betik.sh";
    exec( $cmd, $output );


if($output==null)
{
    echo "null";
}
else
{
    foreach( $output as $tampon ) { echo "$tampon .nci satir <br>"; };
}

}
catch(Exception $ex)
{
    echo "Error";
}
?>
Kev
  • 118,037
  • 53
  • 300
  • 385
Tractatus
  • 118
  • 1
  • 1
  • 9

1 Answers1

2

Note that the common way of querying the file is

$ prolog

which lets you enter the swi prolog interprer:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.10.4)
Copyright (c) 1990-2011 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

Where you can then query:

?- consult(ples.pl).

(or [ples].)to load the file and then

?- ancestor(X, tom).

to get the desired results.

else, to call this from the command line, I'd recommend:

swipl --quiet -s ples.pl -g "forall(ancestor(X, tom), writeln(X)), halt."
m09
  • 7,490
  • 3
  • 31
  • 58