0

我有个问题。几个星期我都无法弄清楚这个问题。例如:

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

查询是:

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

输出 :

% 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$

我应该怎么做才能获得变量 X ?


我从 php 调用。我的PHP代码:

<?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";
}
?>
4

1 回答 1

2

注意查询文件的常用方式是

$ prolog

它允许您输入 swi prolog 解释器:

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).

然后您可以在哪里查询:

?- consult(ples.pl).

(或[ples].)加载文件,然后

?- ancestor(X, tom).

以获得所需的结果。

否则,要从命令行调用它,我建议:

swipl --quiet -s ples.pl -g "forall(ancestor(X, tom), writeln(X)), halt."
于 2012-09-08T15:00:35.503 回答